C# 对于这一点?当我尝试此方法时,我只得到了方法“RegisterStartupScript”的没有重载,该方法有4个参数如果你想使用网页中的多条消息,你应该对它们进行不同的命名,例如myalert1、myalert2等。如果你的消息包含单引号,它将不起作用,
C# 对于这一点?当我尝试此方法时,我只得到了方法“RegisterStartupScript”的没有重载,该方法有4个参数如果你想使用网页中的多条消息,你应该对它们进行不同的命名,例如myalert1、myalert2等。如果你的消息包含单引号,它将不起作用,,c#,asp.net,web-applications,code-behind,messagebox,C#,Asp.net,Web Applications,Code Behind,Messagebox,对于这一点?当我尝试此方法时,我只得到了方法“RegisterStartupScript”的没有重载,该方法有4个参数如果你想使用网页中的多条消息,你应该对它们进行不同的命名,例如myalert1、myalert2等。如果你的消息包含单引号,它将不起作用,您必须将其替换为其他字符,例如|。不!这将显示服务器上的消息框。Richard是正确的。不要这样做。这将显示服务器上的消息框。我得到“扩展方法必须是静态的”。有什么想法吗?@usefulBee:您忘记在public和void之间添加static
对于这一点?当我尝试此方法时,我只得到了方法“RegisterStartupScript”的
没有重载,该方法有4个参数
如果你想使用网页中的多条消息,你应该对它们进行不同的命名,例如myalert1、myalert2等。如果你的消息包含单引号,它将不起作用,您必须将其替换为其他字符,例如|。不!这将显示服务器上的消息框。Richard是正确的。不要这样做。这将显示服务器上的消息框。我得到“扩展方法必须是静态的”。有什么想法吗?@usefulBee:您忘记在public
和void
之间添加static
。不完全正确。该类创建页面对象的扩展metod。您可以使用页面实例调用它:this.Show(“这里是我的消息”)或将页面作为参数提供:MessageBox.Show(这里是我的消息”)是的,但是当您在自己的页面类中工作时。那么您就不需要使用此语句获取解析器错误消息:无法加载类型“CSASPNETMessageBox.MessageBoxUserControl”。此解决方案似乎非常适合我的问题。。。直到我点击这些链接,发现它们不再工作(感谢微软!)。有人可以在步骤3和4中发布MessageBox.cs和MessageBoxCore.cs的代码吗?或者告诉我代码应该是什么样子?windows.Forms不是ASP.net的一部分。完全不同的游戏+1,它不是问题的正确答案,但将有助于将来在本地服务器上进行调试
MessageBox.Show("Here is my message");
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
System.Windows.forms
MessageBox.Show("Here is my message");
System.Windows.forms
btn_click()
{
System.Windows.Forms.MessageBox.Show("Hello");
}
public static class MessageBox {
public static void Show(this Page Page, String Message) {
Page.ClientScript.RegisterStartupScript(
Page.GetType(),
"MessageBox",
"<script language='javascript'>alert('" + Message + "');</script>"
);
}
}
MessageBox.Show("Here is my message");
<asp:Literal ID="PopupBox" runat="server"></asp:Literal>
string title = "My box title goes here";
string text = "Do you want to Update this record?";
MessageBox messageBox = new MessageBox(text, title, MessageBox.MessageBoxIcons.Question, MessageBox.MessageBoxButtons.YesOrNo, MessageBox.MessageBoxStyle.StyleA);
messageBox.SuccessEvent.Add("YesModClick");
PopupBox.Text = messageBox.Show(this);
[WebMethod]
public static string YesModClick(object sender, EventArgs e)
{
string strToRtn = "";
// The code that you want to execute when the user clicked yes goes here
return strToRtn;
}
<link href="~/Styles/MessageBox.css" rel="stylesheet" type="text/css" />
<div id="result"></div>
<asp:ScriptManager runat="server" ID="scriptManager" EnablePageMethods="True">
</asp:ScriptManager> //<-- Make sure you only have one ScriptManager on your aspx page. Remove the one on your aspx page if you already have one.
<%@ Register src="~/MessageBoxUserControl.ascx" tagname="MessageBoxUserControl" tagprefix="uc1" %>
<uc1:MessageBoxUserControl ID="MessageBoxUserControl1" runat="server" />
<asp:scriptmanager id="ScriptManager1" runat="server" />
{
string sMsg = "My Message";
ScriptManager.RegisterStartupScript(Page, Page.GetType, Guid.NewGuid().ToString(), "alert('" + sMsg + "')", true);
}
using System.Windows.Form;
protected void Button1_Click(object sender, EventArgs e)
{
MessageBox.Show(" Hi....");
}
<script>
var data = '<%= JsData %>';
alert(data);
</script>
public partial class PageName : Page
{
protected string JsData = "your message";
/// <summary>
/// Shows a basic MessageBox on the passed in page
/// </summary>
/// <param name="page">The Page object to show the message on</param>
/// <param name="message">The message to show</param>
/// <returns></returns>
public static ShowMessageBox(Page page, string message)
{
Type cstype = page.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = page.ClientScript;
// Find the first unregistered script number
int ScriptNumber = 0;
bool ScriptRegistered = false;
do
{
ScriptNumber++;
ScriptRegistered = cs.IsStartupScriptRegistered(cstype, "PopupScript" + ScriptNumber);
} while (ScriptRegistered == true);
//Execute the new script number that we found
cs.RegisterStartupScript(cstype, "PopupScript" + ScriptNumber, "alert('" + message + "');", true);
}