__doPostBack and arguments

G

Guest

Hi,

I am using the following code in the page class:

this.Button1.Attributes["onclick"] = this.Page.GetPostBackClientEvent(this,
"MyButton1");

When the Page_Load fires, the arguments ("e" variable) are always empty and
the sender is always the form itself. I need to figure out which control
caused the postback to occur, because I have some relate process.

Any help is appreciated. Thanks.
Mike
 
G

Guest

The page load event will always fire, even for a post back.

The most common way i've seen it done is this

in page_load

you just put

if(!page.ispostback)
{
do stuff you want to happen only the first time the page loads
}

then put your code in the code behind the button or whatever
 
J

Jason Kester

Mike said:
this.Button1.Attributes["onclick"] = this.Page.GetPostBackClientEvent(this,
"MyButton1");

When the Page_Load fires, the arguments ("e" variable) are always empty and
the sender is always the form itself. I need to figure out which control
caused the postback to occur, because I have some relate process.

I take it you have multiple buttons pointed at the same handler? If
sender & eventargs are failing you, you could skip the middle man and
inspect the __EVENTTARGET & __EVENTARGUMENT values directly.

Request["__EVENTTARGET"] should get you the ID that the button was
rendered to the page with.


Jason
http://www.expatsoftware.com/
 
G

Guest

Phantastic! I skipped the middle man and it works as you said :)

I also found an alternative solution with a hidden field. Set the value of
the hidden field and then read it on the server side. But I like better your
solution.

Thanks.
Mike



Jason Kester said:
Mike said:
this.Button1.Attributes["onclick"] = this.Page.GetPostBackClientEvent(this,
"MyButton1");

When the Page_Load fires, the arguments ("e" variable) are always empty and
the sender is always the form itself. I need to figure out which control
caused the postback to occur, because I have some relate process.

I take it you have multiple buttons pointed at the same handler? If
sender & eventargs are failing you, you could skip the middle man and
inspect the __EVENTTARGET & __EVENTARGUMENT values directly.

Request["__EVENTTARGET"] should get you the ID that the button was
rendered to the page with.


Jason
http://www.expatsoftware.com/
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top