net/C# application, I have a user control containing a button.
I am loading the control in a PlaceHolder on the main page at runtime.
<asp:PlaceHolder ID="PlaceHolder1" runat="server">
</asp:PlaceHolder>
Code Behind:
MyControl CC = (MyControl)LoadControl("Controls/MyControl.ascx");
PlaceHolder1.Controls.Add(CC);
on the main page I have a text box and a link button. I want to do the following:
When the user clicks on the button in the user control, the textbox value is set to ‘5’ and the link button click event is fired using javascript.
I tried the following but it did not work:
IN THE MAIN PAGE:
<asp:TextBox ID="PageBox" runat="server"></asp:TextBox>
<asp:LinkButton ID="LinkButtonPage" runat="server" onclick="LinkButtonPage_Click" Text="Submit"></asp:LinkButton>
IN THE USER CONTROL:
<script type="text/javascript">
function SetPage(a) {
var txtFld = document.getElementById("PageBox");
txtFld.value = a;
document.getElementById('LinkButtonPage').click();
return false;
}
</script>
<input type="button" id="Button1" onclick="SetPage('5');" value="Submit"/>
But when i click on the button nothig happens.
Thank you for any help
I fixed the problem by adding the function directly in the onclick event of the button