I have an LinkButton control which I need to add a c# method to. Currently when I use parse control and add the control to the page it changes the call to javascript and I get undefined. I figure a way around this would be to define a javascript function that would call the c# method from the code behind, but I cannot figure out how to do this.
Specfically when a linkbutton is clicked I need javascript to pass the ID of the linkbutton to a C# method.
I have tried this:
foreach (Control Control in myctrl.Controls)
{
if (Control is LinkButton)
{
LinkButton lb = (LinkButton)Control;
lb.Click += LinkButton_Click;
}
Panel1.Controls.Add(myctrl);
}
public void LinkButton_Click(Object sender, EventArgs e)
{
BREAKPOINTHERE> Console.Write(e.ToString());
}
It never fires when clicked. here is the code generated:
<a id="dnn_ctr954_ViewPromotions_LinkButton2" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("dnn$ctr954$ViewPromotions$LinkButton2", "", true, "", "", false, true))">Get your Free 2</a>
now if I put this in my aspx page, it works fine:
<asp:LinkButton ID="test" OnClick="LinkButton_Click" runat="server">mybutton</asp:LinkButton>
I get this and it works fine:
<a id="dnn_ctr954_ViewPromotions_test" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("dnn$ctr954$ViewPromotions$test", "", true, "", "", false, true))">mybutton</a>