简体   繁体   English

为什么当我使用RegisterStartupScript或RegisterClientScriptBlock时,我的C#代码不起作用?

[英]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.

相关问题 在我的C#嗅探器中设置套接字选项时,不知道为什么我收到错误代码10022(无效参数) - Don't know why I'm getting Error Code 10022 (Invalid Argument) when setting socket options in my C# sniffer 当我使用变量时,使用 ExecuteScalar() 选择不起作用,总是返回空,当我不使用变量时它起作用 - C# - Select with a ExecuteScalar() not working when i use a variable, always return empty, when i don't use variable it works - C# 在 asp.net 3.5 中使用 RegisterClientScriptBlock/RegisterStartupScript - Use of RegisterClientScriptBlock/RegisterStartupScript in asp.net 3.5 我不明白为什么此代码有效? - I don't understand why this code works? 我的C#代码生成的命令在C#中不起作用,但是当我将其粘贴到cmd时可以完美地工作 - My command which is being produced by my C# code isn't working in C#, but works perfectly when I paste it to cmd 我正在用 Unity 研究 C# 构造函数和析构函数,但我不知道为什么它会这样工作 - I'm studying the C# constructor and destructor with Unity, but I don't know why it works like this 当运行基本的c#控制台应用程序时,控制台打开空白,我不知道为什么 - When running my basic c# console app, my console opens blank and I don't know why 在 C# 中使用轨迹栏更改表单中的不透明度不起作用,为什么? - Changing opacity in form with trackbar in C# don't works, why? 为什么我的代码不更改 c# 中的 head 值,或者我必须使用指针之类的东西? - why my code doesn't change the head value in c# or i have to use somethings like pointers? RegisterStartupScript和RegisterClientScriptBlock之间的区别? - Difference between RegisterStartupScript and RegisterClientScriptBlock?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM