Which control performed PostBack?

J

John Smith

I have put this code inside my Page_Load event:

Response.Write(Page.Request.Params.Get("__EVENTTARGET"))

but it doesn't write to response anything when I click on the button inside
DataGrid (my asp:Button is located inside my template column togrther with
my asp:TextBox). It works fine for DropDownList, which is also inside
template column inside DataGrid.
 
M

mnichols

Hi,

I am not sure if there is any one way to do this for all situations but
here are two ideas:

One is to use ASP.NET events for each PostBack possibility:

<asp:Button ID="Button1" runat="server" Text="Button1"
OnClick="Button1_Click" />
<input id="Button2" runat="server" onserverclick="Button2_ServerClick"
type="button" value="button" />

and then capture events :

protected void Button1_Click(object sender, EventArgs e)
{
Button1Clicked=true;
}
protected void Button2_Click(object sender, EventArgs e)
{
y = 2;
}

Another option is just pure html. If you have three submit buttons:

<input type="submit" name="action" value="Preview">
<input type="submit" name="action" value="Post">
<input type="submit" name="action" value="Cancel">

Request["Preview"]!=null if clicked
Request["Post"]!=null if clicked
Request["Cancel"]!=null if clicked


Maybe someone else will have a better idea.

mnichols
 
B

bruce barker \(sqlwork.com\)

thats because asp:buttons don't use the hidden field "__EVENTTARGET". you
need to check the Page.Form collection for each button on your page and see
its in there. it its there, its the one clicked on.

-- bruce (sqlwork.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,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top