[英]How we can call javascript function from code-behind in asp.net?
I have this javascript function : 我有这个javascript函数:
function showLoader() {
document.getElementById("loaderState").style.display = 'inline';
}
And I have a button : 我有一个按钮:
<asp:Button ID="btnSignUp" runat="server" Text="Sign Up" OnClick="btnSignUp_Click" />
I am tryong to call that js function in code behind : 我试图在后面的代码中调用该js函数:
protected void btnSignUp_Click(object sender, EventArgs e)
{
try
{
int i = users.AddNewUser();
if (i != 0)
{
Page.ClientScript.RegisterStartupScript(
GetType(),
"btnSignUp",
"showLoader();",
true);
}
}
catch (Exception exp)
{
throw exp;
}
}
But not worked!!! 但是没有用!!! Why?
为什么?
Thanks. 谢谢。
Use: 采用:
ScriptManager.RegisterStartupScript(
this,
GetType(),
"btnSignUp",
"showLoader();",
true);
See these similar question: 看到这些类似的问题:
ScriptManager.RegisterStartupScript code not working - why? ScriptManager.RegisterStartupScript代码不起作用-为什么?
ClientScript.RegisterStartupScript not working ClientScript.RegisterStartupScript无法正常工作
ScriptManager.RegisterStartUpScript(...) not working ScriptManager.RegisterStartUpScript(...)无法正常工作
Try This 尝试这个
protected void btnSignUp_Click(object sender, EventArgs e)
{
try
{
int i = users.AddNewUser();
if (i != 0)
{
ScriptManager.RegisterStartupScript(this, GetType(), "btnSignUp", "showLoader()", true);
}
}
catch (Exception exp)
{
throw exp;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.