DIV onclick postback - how to identify on the server side?
-
Can anyone help with this? I have an aspx page with 2 divs both marked to run at server.
<div id="div1" runat="server">
this is div 1
</div><div id="div2" runat="server">
this is div 2
</div>In the page load, I dynamically add a clientside onclick postback to the divs like so:
if (!IsPostBack)
{
div1.Attributes.Add("onclick",
Page.ClientScript.GetPostBackClientHyperlink(div1, ""));
div2.Attributes.Add("onclick",
Page.ClientScript.GetPostBackClientHyperlink(div2, ""));
}When I click on the div it postbacks ok, but the question is, how do I identify on the server which div sent the postback? (or have I got the wrong end of the stick)? Cheers
ChrisB
-
Can anyone help with this? I have an aspx page with 2 divs both marked to run at server.
<div id="div1" runat="server">
this is div 1
</div><div id="div2" runat="server">
this is div 2
</div>In the page load, I dynamically add a clientside onclick postback to the divs like so:
if (!IsPostBack)
{
div1.Attributes.Add("onclick",
Page.ClientScript.GetPostBackClientHyperlink(div1, ""));
div2.Attributes.Add("onclick",
Page.ClientScript.GetPostBackClientHyperlink(div2, ""));
}When I click on the div it postbacks ok, but the question is, how do I identify on the server which div sent the postback? (or have I got the wrong end of the stick)? Cheers
ChrisB
Hi Chris: Here is just a suggestion...Before do postback, you store div id into a hidden field...then you can parse this at server side to know which div causes post back... Hope you get the clue... << >>
-
Can anyone help with this? I have an aspx page with 2 divs both marked to run at server.
<div id="div1" runat="server">
this is div 1
</div><div id="div2" runat="server">
this is div 2
</div>In the page load, I dynamically add a clientside onclick postback to the divs like so:
if (!IsPostBack)
{
div1.Attributes.Add("onclick",
Page.ClientScript.GetPostBackClientHyperlink(div1, ""));
div2.Attributes.Add("onclick",
Page.ClientScript.GetPostBackClientHyperlink(div2, ""));
}When I click on the div it postbacks ok, but the question is, how do I identify on the server which div sent the postback? (or have I got the wrong end of the stick)? Cheers
ChrisB
At the server side, you simply check on the
Request.Form["__EVENTTARGET"]
entry to see which object causes the postback, for example if you click the div 1 then the value should be "div1". In addition, you might think about building a custom div control with a custom event, say Click, and you can easily determine which div causing the postback using the sender object of the Click event handler. -
At the server side, you simply check on the
Request.Form["__EVENTTARGET"]
entry to see which object causes the postback, for example if you click the div 1 then the value should be "div1". In addition, you might think about building a custom div control with a custom event, say Click, and you can easily determine which div causing the postback using the sender object of the Click event handler.Perfect, Thanks.
ChrisB