I need a div element to cause postback to the server. I can use window.location tough but then I think I won't be able to fire any event back on the server. How can I call the asp.net generated dopostback function properly? Thx in advance
A:
The idea is that I place a linkButton, and then I use it from the Div
<form id="form1" runat="server">
<div>
<div runat="server" ID="txtTest" style="cursor:pointer;" >Click the div</div>
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" style="display:none;"></asp:LinkButton>
<br /><asp:Literal runat="server" ID="txtDebug"></asp:Literal>
</div>
</form>
and code behind
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtTest.Attributes.Add("onclick", "__doPostBack('"+LinkButton1.ClientID+"','')");
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
txtDebug.Text = "click on div";
}
Aristos
2010-04-27 18:32:02
I can't use any element inside the div. That is the reason I am after making a postback from the div directly. If I use any element inside the div, then I run into problems using onmouseout (for jQuery animations etc). The element (linkbutton) causes onmouseout .. I use different script that checks all the parent nodes but that makes the whole thing dead slow and the animation fails again :)
Snoop Dogg
2010-04-27 20:51:52
And also you use cursor:pointer for the div, but it will not postback if you don't click the linkbutton. So it is kinda weird making the user think that the whole div is a button when it is NOT.
Snoop Dogg
2010-04-27 20:53:21
@Snoop the linkbutton is outside the div, you can place it anywhere, even on the bottom of the page. Exist only to force the asp.net to create the postback that I use, and then to capture from code behind the commandId
Aristos
2010-04-28 06:59:44
Uhm I'm sorry ...
Snoop Dogg
2010-04-28 09:46:12