determine html control causing postback

J

John A Grandy

For an .aspx page that uses no server-side controls -- instead it generates
all of its html and writes it to the page in the overriden render event.
How to write logic for the Page_Load() event which determines which control
triggerred the postback ?

Assume that all html controls rendered are given a name and id property ,
but also assume that the set of controls rendered is dynamically selected.


I found a post that addresses some aspects of this topic ... has anyone
tried this technique ?

As I mentioned, the __EVENTTARGET hidden form field should contain the
name of the control that caused the postback event, unless the control
is a Button. If the control is a Button, a field named with the client
ID of the button is set to the value (text) of the button.

For example, let's say your DropDownList is named ddlName, and the
button is btnSubmit:

<code>
//C#
private void Page_Load(object sender, System.EventArgs e)

// Test for ddlName
if (Request.Form["__EVENTTARGET"] == "ddlName") {
....
} else if (Request.Form[btnSubmit.ClientID] != null) {
....
}
</code>

Note that if btnSubmit is NOT clicked, Request.Form[btnSumbit.ClientID]
== null. For VB, change the [ ] to ( ).
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top