How to set a button from a user control the default button on an aspx page

Discussion in 'ASP .Net' started by AlecL, Feb 12, 2007.

  1. AlecL

    AlecL Guest

    Hi All,

    I have added a user control onto an aspx page and want to make the
    submit button of that user control the default button when the panel
    in which the user control is located is visible. I have used the
    code:
    Page.RegisterHiddenField("__EVENTTARGET", "Login.btnSubmit")
    in the Page Load event but this does not make the submit button
    default(enter) button. Any ideas on how can I do this. I have also
    tried using just the name of the button instead of Login.btnSubmit
    which is the nameofcontrol.nameofbutton convention but to no avail.

    HELP! Please.

    Al
     
    AlecL, Feb 12, 2007
    #1
    1. Advertising

  2. If you wish to go this route, set default in the user control or expose the
    user control up the stack so you can set the value. To expose up the stack,
    set the button to protected instead of private, so you can see it at page
    level. This is the proper OO method of setting up user controls (which most
    examples DO NOT do).

    NOTE: To pass back values properly, unless all work is done in the control,
    you will have to raise an event (delegate) and handle on the page level. The
    best way to do this is make the user control a complete object with
    properties for the different controls.

    NOTE (also): If you are using this particular piece on more than one form,
    compiling into a server control is often the best option.

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA
    http://gregorybeamer.spaces.live.com

    ********************************************
    Think outside the box!
    ********************************************
    "AlecL" <> wrote in message
    news:...
    > Hi All,
    >
    > I have added a user control onto an aspx page and want to make the
    > submit button of that user control the default button when the panel
    > in which the user control is located is visible. I have used the
    > code:
    > Page.RegisterHiddenField("__EVENTTARGET", "Login.btnSubmit")
    > in the Page Load event but this does not make the submit button
    > default(enter) button. Any ideas on how can I do this. I have also
    > tried using just the name of the button instead of Login.btnSubmit
    > which is the nameofcontrol.nameofbutton convention but to no avail.
    >
    > HELP! Please.
    >
    > Al
    >
     
    Cowboy \(Gregory A. Beamer\), Feb 12, 2007
    #2
    1. Advertising

  3. On Feb 12, 7:53 pm, "AlecL" <> wrote:
    > Hi All,
    >
    > I have added a user control onto an aspx page and want to make the
    > submit button of that user control the default button when the panel
    > in which the user control is located is visible. I have used the
    > code:
    > Page.RegisterHiddenField("__EVENTTARGET", "Login.btnSubmit")
    > in the Page Load event but this does not make the submit button
    > default(enter) button. Any ideas on how can I do this. I have also
    > tried using just the name of the button instead of Login.btnSubmit
    > which is the nameofcontrol.nameofbutton convention but to no avail.
    >
    > HELP! Please.
    >
    > Al


    I think

    Page.RegisterHiddenField("__EVENTTARGET", btnSubmit.UniqueID)

    should work
     
    Alexey Smirnov, Feb 12, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Milsnips
    Replies:
    1
    Views:
    419
    John M Deal
    Dec 2, 2004
  2. Reny J Joseph Thuthikattu
    Replies:
    1
    Views:
    577
    =?Utf-8?B?UHJha2FzaC5ORVQ=?=
    Dec 30, 2004
  3. digitalego
    Replies:
    1
    Views:
    678
    digitalego
    Mar 23, 2005
  4. Gaetan
    Replies:
    3
    Views:
    1,462
    Juan T. Llibre
    Feb 14, 2006
  5. SibAndela
    Replies:
    1
    Views:
    211
    Jeff Cochran
    Sep 26, 2004
Loading...

Share This Page