I have one web control (called A) and one web page (Called Default).
Is there a way to call a JavaScript function from Default that belongs to A instead of using OnClientClick?
I am using the following in Page_Load of Default.aspx.cs (This is where my JavaScript function is coming from):
a = (A)LoadControl("~/A.ascx");
a.ID = "AgControl";
panel.Controls.Add(a);
In Default.aspx I have the following:
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button1_OnClick"
OnClientClick="JavaScript()" />
DefaultPage.aspx.cs:
protected void Button1_OnClick(object sender, EventArgs e)
{
String a = getValueofA();
If (a == "1")
{
//OnClientClick code goes here
}
else If (a == "2")
{
//No OnClientClick code goes here
}
}
My goal is to remove OnClientClick="JavaScript() and code it only in the first part of the “if statement”.
ScriptManager.RegisterStartupScript
Example: