views:

172

answers:

1

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
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
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
@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
Uhm I'm sorry ...
Snoop Dogg