[英]Why when I use RegisterStartupScript or RegisterClientScriptBlock my C# code don't works?
I have one aspx page where I need to validate some fields, I made this validation on C# code, but there wasn't working. 我有一个aspx页面,我需要在其中验证一些字段,我在C#代码上进行了此验证,但是没有用。
So I tried put a simple code only to discover what was the problem, so I realized that didn't matter the code, if I run a ScriptManager.RegisterStartupScript or a ScriptManager.RegisterClientScriptBlock, my C# code doesn't work. 因此,我尝试只放置一个简单的代码来发现问题所在,所以我意识到这无关紧要,如果我运行ScriptManager.RegisterStartupScript或ScriptManager.RegisterClientScriptBlock,则我的C#代码不起作用。
Here is an example: 这是一个例子:
protected void btnBuscar_Click(object sender, EventArgs e){
this.lblValidarEmpresa.Visible = false;
ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "script", "AplicarMascara();", false);
}
The function AplicarMascara() applies a data mask on a text field. 函数AplicarMascara()在文本字段上应用数据掩码。
Do you know how solve this problem? 你知道如何解决这个问题吗? Or any other way to apply this mask without use ScriptManager? 还是任何其他无需使用ScriptManager即可应用此掩码的方法?
Thanks. 谢谢。
乍一看,尝试将最后一个参数(addScriptTags)更改为true。
It looks like you're trying to execute javascript code when the button is pushed and things are getting complicated with the use of the updatepanel. 按下按钮似乎您正在尝试执行javascript代码,而使用updatepanel会使事情变得复杂。 Have you considered triggering "AplicarMascara" using the onclientclick property of btnBuscar? 您是否考虑过使用btnBuscar的onclientclick属性触发“ AplicarMascara”? You didn't post your code for the button definition but here's a sample of what it should look like: 您没有发布用于按钮定义的代码,但是下面是其示例的示例:
<asp:Button id="btnBuscar" OnClientClick="AplicarMascara" runat="server" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.