|
-
Mar 6th, 2003, 09:45 AM
#1
Thread Starter
Junior Member
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.
-
Mar 6th, 2003, 10:18 AM
#2
PowerPoster
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.
-
Mar 6th, 2003, 11:32 AM
#3
PowerPoster
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.
-
Mar 6th, 2003, 12:00 PM
#4
Thread Starter
Junior Member
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.
-
Mar 6th, 2003, 01:43 PM
#5
PowerPoster
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.
-
Mar 6th, 2003, 01:47 PM
#6
PowerPoster
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.
-
Mar 6th, 2003, 04:55 PM
#7
Thread Starter
Junior Member
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.
-
Mar 6th, 2003, 04:56 PM
#8
New Member
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.
-
Mar 6th, 2003, 06:24 PM
#9
Frenzied Member
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
-
Mar 6th, 2003, 08:40 PM
#10
PowerPoster
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..
-
Mar 6th, 2003, 09:17 PM
#11
Frenzied Member
Thanks for the explanation.
Dont gain the world and lose your soul
-
Mar 7th, 2003, 11:38 AM
#12
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|