Results 1 to 12 of 12

Thread: Events and which button was clicked

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    19

    Events and which button was clicked

    I'm a bit confused about the order of events when posting back to the server.
    I have a registration page which accepts user name, address etc. There's a Register button and a Reset button.
    There are also validation controls that I set on Load when the page loads for the first time, but not on postbacks and the Register button of course posts back and everything runs just fine when it is clicked.
    The problem arises when I hit the reset button in which I clear all the fields, but the event for btnRegister_Click never fires before going through the load event. I understand that the btnRegister_Click is the last to fire of all the events coming from the form to the server, so my question is what is the best way to determine which button was clicked? I can't seem to find an answer to that in the wonderful MSDN documentation.
    Thanks in advance for your insights.

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    so my question is what is the best way to determine which button was clicked?
    I am not sure I understand what you want. You already know the order that the events fire, so what is the question? How to reset the fields? You know which button was clicked in code when the event fires. Post some of your code, that might also help along with more detail of exactly what you need to know.

  3. #3
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    I'm a little confused also. The button click event handler runs after the load event, assuming that the user did indeed invoke the button click.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    19
    Sorry for the confusion.
    Since the only place to pick up the values of controls on a form is in the load event (if I'm not mistaken) that's where I'm calling a procedure that registers the user. In that case I'm checking if it's a postback and running it.
    Clicking the Reset button also fires that function because it's a postback, so the user is registered or I get errors for incomplete fields etc.
    Is there another point in the events of a postback I can pick up the values entered on the form when trying to register so that I can take that out of the load event of the page? Seems like when I need to know what button was clicked then it's too late because the first thing to fire is what's in the load event.
    Thanks again and I hope this clarifies things.

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    You can see all the values on the page in your event handlers when a postback occurs, assuming you are using html server controls or asp.net web server controls.

  6. #6
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Wrap functionality you don't want processed in a
    if(!Page.IsPostBack)
    block. If that isn't working, you should post your code so we can see what you mean. I think maybe you are just coding it the wrong way and not getting your desired results.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    19
    I had a couple of other ideas while reading your replies and thinking about the whole structure of the post-back logic. I'll try to implement and get back if it doesn't work the way I need. I can't show code right now because this is an outside of work thing.
    Thanks again.

  8. #8
    New Member
    Join Date
    Oct 2002
    Location
    Melbourne, Australia
    Posts
    12
    Not strictly an answer to the question here, but I found this in the installed help for VS.NET:
    ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconcontrolexecutionlifecycle.htm "Control Execution Lifecycle"

    It does explain the event order of your page (actually web controls, but the order is the same). The last 2 may be in the wrong order thou.

  9. #9
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    This might sound stupid, but what the difference between html server controls and asp.net web server controls.
    Dont gain the world and lose your soul

  10. #10
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    html server controls are nothing more than standard html control which provides access in server-side code. It's main purpose is to ease the migration to .NET. To convert a standard html element into a html server control, you need to simply add the 'Runat='Server' attribute to the element. Also, the programatic model differs from the standard .NET model, when compared to other classes and web server controls. Web server controls provide a more robust and standard programmatic object model. For instance, when using standard html server controls, you manipulate the element content via the value property for most html elements. Now, when you want to manipulate the content of an asp.net web server control, you use the 'text' property, which is the standard.

    Hope this helps..

  11. #11
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Thanks for the explanation.
    Dont gain the world and lose your soul

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    19

    resolved

    I've got it working just fine. Got the wheels churning a bit more while reading the posts and thinking about it.
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width