Javascript 警报在 asp.net 的更新面板中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20044762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 17:33:44  来源:igfitidea点击:

Javascript alert is not working in Update Panel in asp.net

c#javascriptasp.netupdatepanel

提问by vivek jain

I am working on asp.net web application. I have one UpdatePanel and there is table inside table which has data in some TextBoxes.

我正在研究 asp.net Web 应用程序。我有一个 UpdatePanel,表内有一个表,其中包含一些 TextBox 中的数据。

I have one save button too inside this UpdatePanel So I want to save this data into Database, when I click Save Button.

我在这个 UpdatePanel 中也有一个保存按钮所以我想在我点击保存按钮时将这些数据保存到数据库中。

This is working fine till now.

到目前为止,这一切正常。

But I want to show alert message to User that information saved successfully. I'm using javascript for this purpose, But Javascript is not working. so is this possible to achieve the desired functionality using javascript, if yes then please guide me Or if there is any other alternative method except this please let me know.

但我想向用户显示成功保存信息的警报消息。我为此目的使用 javascript,但 Javascript 不起作用。那么这是否有可能使用 javascript 实现所需的功能,如果是,请指导我,或者如果除此之外还有任何其他替代方法,请告诉我。

Thanks, Vivek

谢谢,维维克

回答by Monika

If you have update panel use ScriptManager.RegisterClientScriptBlockas below

如果您有更新面板,请使用ScriptManager.RegisterClientScriptBlock如下

ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('Member Registered Sucessfully');", true)

Remember that you can't use Response.Write during an asynchronous postback.

请记住,您不能在异步回发期间使用 Response.Write。

It would be good if you have posted your code here.

如果你把你的代码贴在这里就好了。

回答by Gautam Kumar Sahu

Try This Line of Code Its Definitely work with Update panel.

试试这行代码它绝对适用于更新面板。

var message = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize("Bill No. : " + BillNo + " successfully generated.");
            var script = string.Format("alert({0});window.location ='ChhallanPrint.aspx';", message);
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", script, true);

回答by Jobin George

Try this for popup sweetalert in asp vb.net

试试这个在 asp vb.net 中的 popup sweetalert

Dim message As String = " swal('Added!','Country Added Successfully.', 'success')"

ScriptManager.RegisterClientScriptBlock(TryCast(sender, Control), Me.GetType(), "sweetAlert", message, True)

回答by Osman G?khan ER

  string message = " swal('"+gelen[2]+"!','Sepete Eklendi.', 'success')";
  ScriptManager.RegisterClientScriptBlock(this,this.GetType(), "sweetAlert", message, true);