Default submit button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt Howeson

    #1

    Default submit button

    I am sure this question has been asked many times, however I am yet to find
    a satisfactory solution to the problem. I have a number of user controls
    within an asp.net page, a login box, a search box, and contact form. I wish
    to be able to ensure that when the user presses enter in the appropriate
    textbox control, the correct form is validated and submitted.

    I have tried a number of methods to achieve this goal, the main one being
    setting the __EVENTTARGET hidden form field value to the id of the button I
    wish to be "clicked" when the enter key is pressed. I do this by adding an
    onkeypress attribute to each of the textboxes within the usercontrol. This
    doesn't appear to be working however, and one button is always "clicked"
    rather than the others.

    I wondered if anyone may have some advice on how to handle this approach
    where there are several user controls which would each have been a form in
    their own right in old style asp. Also I'd be interested in how people
    would handle the validation of such a scenario, I am inclined to just write
    my own validation routines for the scenario, rather than rely on the inbuilt
    validation, which doesn't appear to work well for this.

    I have also found it necessary to check each of the validators individually
    within the user control to check if the data submitted IsValid, if I try to
    call Page.IsValid then it will validate all of the validation controls
    within the page, not just within the user control. Am I missing something
    here or is there anyway to validate only the controls within the current
    user control.

    This would seem to be a fairly common situation, however I am finding it
    very difficult to easily achieve the results I am looking for using ASP.Net.
    Any thoughts appreciated....



  • S. Justin Gengo

    #2
    Re: Default submit button

    Matt,

    Here's how I'm taking care of it:

    TextBox.Attribu tes.Add("onkeyd own", "javascript:if( (event.which &&
    event.which == 13) || (event.keyCode && event.keyCode ==
    13)){document.F orm1." & Button.ClientID & ".click();retur n false;}else
    return true;")


    --
    S. Justin Gengo, MCP
    Web Developer / Programmer

    Free Code Library At:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "Matt Howeson" <howeson@hotmai l.com> wrote in message
    news:iMjRa.4988 4$xd5.2763033@s tones.force9.ne t...[color=blue]
    > I am sure this question has been asked many times, however I am yet to[/color]
    find[color=blue]
    > a satisfactory solution to the problem. I have a number of user controls
    > within an asp.net page, a login box, a search box, and contact form. I[/color]
    wish[color=blue]
    > to be able to ensure that when the user presses enter in the appropriate
    > textbox control, the correct form is validated and submitted.
    >
    > I have tried a number of methods to achieve this goal, the main one being
    > setting the __EVENTTARGET hidden form field value to the id of the button[/color]
    I[color=blue]
    > wish to be "clicked" when the enter key is pressed. I do this by adding[/color]
    an[color=blue]
    > onkeypress attribute to each of the textboxes within the usercontrol.[/color]
    This[color=blue]
    > doesn't appear to be working however, and one button is always "clicked"
    > rather than the others.
    >
    > I wondered if anyone may have some advice on how to handle this approach
    > where there are several user controls which would each have been a form in
    > their own right in old style asp. Also I'd be interested in how people
    > would handle the validation of such a scenario, I am inclined to just[/color]
    write[color=blue]
    > my own validation routines for the scenario, rather than rely on the[/color]
    inbuilt[color=blue]
    > validation, which doesn't appear to work well for this.
    >
    > I have also found it necessary to check each of the validators[/color]
    individually[color=blue]
    > within the user control to check if the data submitted IsValid, if I try[/color]
    to[color=blue]
    > call Page.IsValid then it will validate all of the validation controls
    > within the page, not just within the user control. Am I missing something
    > here or is there anyway to validate only the controls within the current
    > user control.
    >
    > This would seem to be a fairly common situation, however I am finding it
    > very difficult to easily achieve the results I am looking for using[/color]
    ASP.Net.[color=blue]
    > Any thoughts appreciated....
    >
    >
    >[/color]


    Comment

    Working...