[英]Alert message box
I have been using label text to show different status in an asp.net website. 我一直在使用标签文本在asp.net网站上显示不同的状态。
eg "Profile Updates", "Invalid Character" etc, however would prefer to have a pop up message box instead. 例如,“配置文件更新”,“无效字符”等,但是更喜欢使用弹出消息框。
This is what I have tried - 这是我试过的 -
string alert = ws.webMethod(TextBox1.Text);
System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert(" + alert + ")</SCRIPT>");
However when this is fired, the screen in IE just seems to get bigger, and no message box is presented. 然而,当这被触发时,IE中的屏幕似乎变得更大,并且没有显示消息框。
How can I achieve this? 我怎样才能做到这一点?
I would not advise doing this, it looks like you are creating a modal dialog on page load, meaning that your page cannot continue processing until a user has clicked OK. 我不建议这样做,看起来你在页面加载时创建了一个模态对话框,这意味着在用户点击OK之前你的页面无法继续处理。
That said, however, your problem is probably a lack of quotes around the alert
ed text: 也就是说,您的问题可能是
alert
文字周围缺少引号:
System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('" + alert + "')</SCRIPT>");
Use ClientScriptManager.RegisterClientScriptBlock instead of Response.Write
使用ClientScriptManager.RegisterClientScriptBlock而不是
Response.Write
string alert = ws.webMethod(TextBox1.Text);
string script = "<SCRIPT LANGUAGE='JavaScript'>alert(" + alert + ")</SCRIPT>"
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptBlockName", script );
我在我的项目中使用过这个,对我来说很好
ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "MessageBox", "alert('message')", true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.