Raise Server Event By Div Click [Resolved]

Posted by Sharpcnet under ASP.NET on 12/30/2013 | Points: 10 | Views : 627 | Status : [Member] | Replies : 4
I'm trying to fire the link button's click event on the Div Click, but this is not working. How can this be done. Also tried with asp button. I Just need to raise a server event.
JavaScript: 
function ShowModal()
{
document.getElementById('<%=lnkBtn.ClientID%>').click();
}

ASPX:
<div id="divKey" runat="server" onclick="ShowModal()">
//content..
<asp:linkButton Id="lnkBtn" runat="server" onClick="lnkBtn_Click"></asp:LinkButton>
</div>

C#:
protected void lnkBtn_Click(object sender, EventArgs e)
{
//some code
}





Responses

Posted by: Sharpcnet on: 12/30/2013 [Member] Starter | Points: 25

Up
0
Down

Resolved
Thank you but none of them worked unfortunately.
This one from spvlong did - http://forums.asp.net/t/1090438.aspx.

public partial class Home: System.Web.UI.Page, IPostBackEventHandler
{

protected void Page_Load(object sender, EventArgs e)
{
div1.Attributes["onclick"] = ClientScript.GetPostBackEventReference(this, "div1_Click");
}

protected void div1_Click()
{
// Do something
}

public void RaisePostBackEvent(string eventArgument)
{
if (!string.IsNullOrEmpty(eventArgument))
{
if (eventArgument == "ClickDiv")
{
div1_Click();
}
}
}
}




Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/30/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Please use this inside js function:

__doPostBack("<%= lnkBtn.UniqueID %>", "");

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/30/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Also refer:-
http://stackoverflow.com/questions/7646162/how-to-fire-a-button-click-event-from-javascript-in-asp-net

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 12/30/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Also Please check for page directive having AutoEventWireup attribute

<%@ Master Language="C#" AutoEventWireup="true" %>

Sharpcnet, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response