Cross Page Posting in .net 2 Beta

  • Thread starter Thread starter jhoge123
  • Start date Start date
J

jhoge123

I would like to do a cross post from one page to another, but I have
two buttons on the main page, and I want the page receiving the post to
determine which button has been clicked:

<body>
<form id="form1" runat="server">
<div>
<asp:Button PostBackUrl="HandlerPage.aspx" ID="Button1"
runat="server" Text="Do This" /><br />
<asp:Button PostBackUrl="HandlerPage.aspx" ID="Button2"
runat="server" Text="Do Something Else" />&nbsp;</div>
</form>
</body>

HandlerPage.aspx can test Page.PreviousPage to see if it is being
called by a cross post, but how do I determine if Button1 or Button2
was clicked?

All I can think of right now are unpalatable options:
1) Clutter up the session object
2) Use a Querystring
3) Look at Request.form and check the ClientID of Button1 as below:

Button Button1 = (Button)PreviousPage.FindControl("Button1");
Button Button2 = (Button)PreviousPage.FindControl("Button2");
if (Request.Form[Button1.ClientID]==Button1.Text){
Response.Write ("Button1 CLicked");
}
else if (Request.Form[Button2.ClientID] == Button2.Text)
{
Response.Write("Button 2 Clicked");
}
}

This latter strategy seems to work, but I can't help thinking that
there must be a cleaner way.
 
You could add a client-side OnClick instruction to each button that sets a
hidden form field with a value. That value can then be tested in the
receiving page.
 
Back
Top