Correctly validating isPostback

mRbLACK

Freshman
Joined
Aug 27, 2003
Messages
25
Location
south africa
HI there,

In struggling a bit with isPostBack and hoping someone can help,
I'm doing a contact (email us) section on a web site.

You click on a web control (link button) and in its control.click event I insert the buttons, text boxes etc. into a cell on the same page.

One of these new controls is obviously a button, now this also has an control.click event BUT i never actually hit it, heres why i think...when you click the button, the page reloads, the cell contents are then replaced with its ORIGONAL content (because the onload of that cell reloads its content)

SO when it comes into the onload of that cell, I would like to capture, the isPostback, and see which control origonated the postback, how do i do that?
 
just for clarification...

like i said the onload of the cell populates itself with stuff, i replace this with the fields for the email details...these fields are created at run-time so i go something like...

Code:
     Protected WithEvents txtMessage As New System.Web.UI.WebControls.TextBox

replacing the origonal contents of the cell with the new controls, NOW when i post back, those fields are no longer there...which sucks, should i be using viewstate for this? or shouldnt i be doing it like this at all? surely I can catch the click of the Send button and get the field values before the fields are cleared?

Im not sure im making sence... help
 
ok think ive kinda found the solution, when the onload of my cell fires, check for isPostback, if it is then i add the same controls (the new email/contact oneS), even though they have been initialized, and they contain all their values and their events fire off...this makes no sence to me so if anyone can explain thatd be shweet, though it works.

:D

oh and if anyone knows how to get which control fired the postback thatd be very helpfull :D
 
When you dynamically create controls at runtime, they really dont exist on the page, so when you post back, you need to recreate them, otherwise you loose them. To check for which control fired the postback, check the request.form("__EVENTTARGET") form field that is submitted.
 
Thanks I think that is going to help me alot, the only thing though is that when I check that value, If I havent yet added that control its empty? I think I can use it indirectly though so thatnks loads...:D
 
Back
Top