On a button click i am calling a server side function in which i am calling a Javascript function like
Page.ClientScript.RegisterStartupScript(
this.GetType(),
"scriptsKey",
"<script type=\"text/JavaScript\" language=\"javascript\">test();</script>");
But Javascript function is not calling.
You can call the function from code behind like this :
MyForm.aspx.cs
protected void MyButton_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "myScript", "AnotherFunction();", true);
}
MyForm.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>My Page</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function Test() {
alert("hi");
$("#ButtonRow").show();
}
function AnotherFunction()
{
alert("This is another function");
}
</script>
</head>
<body>
<form id="form2" runat="server">
<table>
<tr><td>
<asp:RadioButtonList ID="SearchCategory" runat="server" onchange="Test()" RepeatDirection="Horizontal" BorderStyle="Solid">
<asp:ListItem>Merchant</asp:ListItem>
<asp:ListItem>Store</asp:ListItem>
<asp:ListItem>Terminal</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr id="ButtonRow"style="display:none">
<td>
<asp:Button ID="MyButton" runat="server" Text="Click Here" OnClick="MyButton_Click" />
</td>
</tr>
</table>
</form>
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "scr", "javascript:test();", true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With