MessageBox问题 [英] MessageBox questions

查看:66
本文介绍了MessageBox问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想弄清楚如何在我的网络客户端程序(C#)中显示一个带有

OK按钮的简单消息框。我已经查看了每个

对JScript和MessageBox的引用,这些引用看起来甚至像它在VS帮助和NG中都可以提供帮助。我找到了很多

的例子,人们说它是多么容易,并展示了一些例子,并在帮助中提供了
的例子。但我有两个问题:


1.所有示例都显示HTML中的所有代码,通常涉及

用户操作,例如按钮点击。由于从Web服务调用返回,我需要显示此消息框

。所以

调用消息框的代码必须在代码隐藏中。


2.没有一个例子可以工作!!这是我在很长一段时间内看到的最令人沮丧的事情。每个人似乎都说试试这个有效,

我尝试了,甚至无法接近!首先,当我将一些

脚本粘贴到我的HTML中时,例如:


< script language =" C#" runat =" server">

public void Page_Load(Object sender,EventArgs e){

//形成要在客户端注册的脚本。

String scriptString ="< script language = JavaScript>功能DoClick()

{" ;;

scriptString + =" showMessage2.innerHTML =''< h4>欢迎使用Microsoft

..NET!< / h4>''}" ;;

scriptString + =" function Page_Load(){showMessage1.innerHTML =" ;;

scriptString + ="''< h4> RegisterStartupScript示例< / h4>''}<" ;;

scriptString + =" /" ;;

scriptString + =" script>" ;;


if(!this.IsStartupScriptRegistered(" Startup"))

this.RegisterStartupScript(" Startup", scriptString);

}

< / script>


它会立即转换为如下所示:


& lt; script language =" C#" runat =" server"& gt;

public void Page_Load(Object sender,EventArgs e){

//形成要在客户端注册的脚本。

String scriptString ="& lt; script language = JavaScript& gt;功能

DoClick(){" ;;

scriptString + =" showMessage2.innerHTML =''& lt; h4& gt;欢迎来到

Microsoft .NET!& lt; / h4& gt;''}" ;;

scriptString + =" function Page_Load(){showMessage1.innerHTML =" ;;

scriptString + ="''& lt; h4& gt; RegisterStartupScript

示例& lt; / h4& gt;''}& lt;";

scriptString + =" /" ;;

scriptString + =" script& gt;" ;;


if(! this.IsStartupScriptRegistered(" Startup"))

this.RegisterStartupScript(" Startup",scriptString);

}

& lt ; / script& gt;


请注意所有<和>字符已转换为& lt;并且

& gt;


然后当我手动编辑线条来纠正它们时,示例将不会运行
。通常它会编译运行,有时我会得到一个服务器

错误,但更多时候它似乎只是将代码回显到页面。

上面的例子是最接近的工作。当我添加:


< span id =" showMessage1">< / span>

< br>

< input type =" button"值= QUOT; ClickMe" onclick =" DoClick()">

< br>

< span id =" showMessage2">< / span>


在表格中,它确实放了一个按钮,但当我点击它时,我得到一个

状态行,上面写着页面上的错误。 />

A到Z教程在哪里可以准确地说明如何添加和制作这个脚本在Web客户端应用程序中工作?


即使上面的例子可行,但看起来非常复杂

只是为了竖起一个简单的盒子!验证器摘要可以通过

来完成,包括MessageBox =" true"。没脚本!但是当然这不会对我有用,因为我需要将它与网络服务响应联系起来。


请帮帮忙?


谢谢,Russ

I''ve been trying to figure out how to show a simple messagebox with an
OK button in my web client program (C#). I have looked at every
reference to JScript and MessageBox that seemed even remotely like it
could help, both in the VS help and in this NG. I found lots of
examples of people saying how easy it is and showing examples, and
examples in the help. But I have two problems:

1. All the examples show all the code in HTML, usually involving a
user action such as a button click. I need to show this message box
as a result of a return from a web service call. So the code to
invoke the message box must be in the code-behind.

2. None of the examples work!! This is the most frustrating thing I
have seen in a long time. Everyone seems to say "Try this it works",
and I try it and can''t even get close! First off, when I paste some
script into my HTML, like:

<script language="C#" runat="server">
public void Page_Load(Object sender, EventArgs e) {
// Form the script to be registered at client side.
String scriptString = "<script language=JavaScript> function DoClick()
{";
scriptString += "showMessage2.innerHTML=''<h4>Welcome to Microsoft
..NET!</h4>''}";
scriptString += "function Page_Load(){ showMessage1.innerHTML=";
scriptString += "''<h4>RegisterStartupScript Example</h4>''}<";
scriptString += "/";
scriptString += "script>";

if(!this.IsStartupScriptRegistered("Startup"))
this.RegisterStartupScript("Startup", scriptString);
}
</script>

It is immediately converted to look like this:

&lt;script language="C#" runat="server"&gt;
public void Page_Load(Object sender, EventArgs e) {
// Form the script to be registered at client side.
String scriptString = "&lt;script language=JavaScript&gt; function
DoClick() {";
scriptString += "showMessage2.innerHTML=''&lt;h4&gt;Welcome to
Microsoft .NET!&lt;/h4&gt;''}";
scriptString += "function Page_Load(){ showMessage1.innerHTML=";
scriptString += "''&lt;h4&gt;RegisterStartupScript
Example&lt;/h4&gt;''}&lt;";
scriptString += "/";
scriptString += "script&gt;";

if(!this.IsStartupScriptRegistered("Startup"))
this.RegisterStartupScript("Startup", scriptString);
}
&lt;/script&gt;

Notice that all the < and > characters have been converted to &lt; and
&gt;

Then when I manually edit the lines to correct them, the example will
not run. Usually it will compile and run, sometimes I get a server
error, but more often it seems to simply echo the code to the page.
The example above came the closest to working. When I added:

<span id="showMessage1"></span>
<br>
<input type="button" value="ClickMe" onclick="DoClick()">
<br>
<span id="showMessage2"></span>

in the form, it did put up a button, but when I click it, I get a
status line that says "error on page".

Where is the A to Z tutorial that shows exactly how to add and make
this script work in a web client application?

Even if the above example will work it seems terribly over complicated
just to put up a simple box! The validator summary can do it by just
including MessageBox="true". No script! But of course this will not
work for me since I need to tie it to a web service response.

Please help?

Thanks, Russ

推荐答案

Page.Controls.Add(new LiteralControl("< script> alert(''你的)消息已成功发送

成功。'')< / script>"));

您可以告诉我从工作程序中取出了吗?


-

问候,

Alvin Bruney

[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]

有花絮吗?在此处获取... http://tinyurl.com/27cok

Russ < RU **** @ eticomm.net>在消息中写道

新闻:aj ******************************** @ 4ax.com ...
Page.Controls.Add(new LiteralControl("<script>alert(''Your message was sent
succesfully.'')</script>"));
You can tell i took that from a working program right?

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Russ" <ru****@eticomm.net> wrote in message
news:aj********************************@4ax.com...
我一直试图弄清楚如何在我的Web客户端程序(C#)中显示一个带有
OK按钮的简单消息框。我已经看过每个
对JScript和MessageBox的引用,这些引用在VS帮助和NG中都可能有点像它可能有所帮助。我找到了许多人的例子,说明它是多么容易,并在帮助中显示示例和
示例。但我有两个问题:

1.所有示例都显示HTML中的所有代码,通常涉及用户操作,例如按钮单击。由于从Web服务调用返回,我需要显示此消息框
。因此,调用消息框的代码必须在代码隐藏中。

2.所有示例都不起作用!!这是我很久以来见过的最让人沮丧的事情。每个人似乎都说试试这个有用,
我尝试了,甚至无法接近!首先,当我将一些
脚本粘贴到我的HTML中时,例如:

< script language =" C#" runat =" server">
public void Page_Load(Object sender,EventArgs e){
//形成要在客户端注册的脚本。
String scriptString ="< script language = JavaScript>函数DoClick()
{" ;;
scriptString + =" showMessage2.innerHTML =''< h4>欢迎使用Microsoft
.NET!< / h4>''}" ;;
scriptString + =" function Page_Load(){showMessage1.innerHTML =" ;;
scriptString + ="''< h4> RegisterStartupScript示例< / h4>''}<" ;;
scriptString + =" /" ;;
scriptString + =" script>" ;;

if(!this.IsStartupScriptRegistered(" Startup"))
this.RegisterStartupScript(" Startup",scriptString);
}
< / script>

它会立即转换为如下所示:

& lt; script language =" C#" runat =" server"& gt;
public void Page_Load(Object sender,EventArgs e){
//形成要在客户端注册的脚本。
String scriptString =" & lt; script language = JavaScript& gt;功能
DoClick(){" ;;
scriptString + =" showMessage2.innerHTML =''& lt; h4& gt;欢迎来到
Microsoft .NET!& lt; / h4& gt;''}" ;;
scriptString + =" function Page_Load(){showMessage1.innerHTML =" ;;
scriptString + ="''& lt; h4& gt; RegisterStartupScript
示例& lt; / h4& gt;''}& lt;" ;;
scriptString + =" /" ;;
scriptString + =" script& gt; " ;;

if(!this.IsStartupScriptRegistered(" Startup"))
this.RegisterStartupScript(" Startup",scriptString);
}
& ; lt; / script& gt;

请注意所有<和>字符已转换为& lt;然后当我手动编辑线条来纠正它们时,示例将不会运行
和/或>

通常它会编译运行,有时我会得到一个服务器错误,但更多时候它似乎只是将代码回显到页面。
上面的例子最接近工作。当我添加:

< span id =" showMessage1">< / span>
< br>
< input type =" button"值= QUOT; ClickMe"表格中的onclick =" DoClick()">
< br>
< span id =" showMessage2">< / span>

它确实放了一个按钮,但是当我点击它时,我得到了一个
状态行,上面写着页面上的错误。

A到Z教程的确切位置显示在哪里如何添加和制作这个脚本在Web客户端应用程序中工作?

即使上面的例子工作也似乎非常复杂
只是为了竖起一个简单的盒子!验证器摘要可以通过
包括MessageBox =true来完成。没脚本!但当然这对我不起作用,因为我需要将它与网络服务响应联系起来。

请帮忙吗?

谢谢,Russ
I''ve been trying to figure out how to show a simple messagebox with an
OK button in my web client program (C#). I have looked at every
reference to JScript and MessageBox that seemed even remotely like it
could help, both in the VS help and in this NG. I found lots of
examples of people saying how easy it is and showing examples, and
examples in the help. But I have two problems:

1. All the examples show all the code in HTML, usually involving a
user action such as a button click. I need to show this message box
as a result of a return from a web service call. So the code to
invoke the message box must be in the code-behind.

2. None of the examples work!! This is the most frustrating thing I
have seen in a long time. Everyone seems to say "Try this it works",
and I try it and can''t even get close! First off, when I paste some
script into my HTML, like:

<script language="C#" runat="server">
public void Page_Load(Object sender, EventArgs e) {
// Form the script to be registered at client side.
String scriptString = "<script language=JavaScript> function DoClick()
{";
scriptString += "showMessage2.innerHTML=''<h4>Welcome to Microsoft
.NET!</h4>''}";
scriptString += "function Page_Load(){ showMessage1.innerHTML=";
scriptString += "''<h4>RegisterStartupScript Example</h4>''}<";
scriptString += "/";
scriptString += "script>";

if(!this.IsStartupScriptRegistered("Startup"))
this.RegisterStartupScript("Startup", scriptString);
}
</script>

It is immediately converted to look like this:

&lt;script language="C#" runat="server"&gt;
public void Page_Load(Object sender, EventArgs e) {
// Form the script to be registered at client side.
String scriptString = "&lt;script language=JavaScript&gt; function
DoClick() {";
scriptString += "showMessage2.innerHTML=''&lt;h4&gt;Welcome to
Microsoft .NET!&lt;/h4&gt;''}";
scriptString += "function Page_Load(){ showMessage1.innerHTML=";
scriptString += "''&lt;h4&gt;RegisterStartupScript
Example&lt;/h4&gt;''}&lt;";
scriptString += "/";
scriptString += "script&gt;";

if(!this.IsStartupScriptRegistered("Startup"))
this.RegisterStartupScript("Startup", scriptString);
}
&lt;/script&gt;

Notice that all the < and > characters have been converted to &lt; and
&gt;

Then when I manually edit the lines to correct them, the example will
not run. Usually it will compile and run, sometimes I get a server
error, but more often it seems to simply echo the code to the page.
The example above came the closest to working. When I added:

<span id="showMessage1"></span>
<br>
<input type="button" value="ClickMe" onclick="DoClick()">
<br>
<span id="showMessage2"></span>

in the form, it did put up a button, but when I click it, I get a
status line that says "error on page".

Where is the A to Z tutorial that shows exactly how to add and make
this script work in a web client application?

Even if the above example will work it seems terribly over complicated
just to put up a simple box! The validator summary can do it by just
including MessageBox="true". No script! But of course this will not
work for me since I need to tie it to a web service response.

Please help?

Thanks, Russ



好的,一些事情....


您可以格式化要显示的文本消息框因此丢失了所有HTML中的所有HTML.b
的innerHTML。事实上,你根本不需要innerHTML,

只需用你的消息文本准备一个普通的字符串。你从帮助中得到的例子是
是正确的,但在这个例子中,他们没有制作

消息框,他们在span标签内生成文本。


因为您希望消息框显示在网页中,所以

仅限于
$ b的脚本对象模型提供的消息框$ b目标浏览器。换句话说,.NET与消息框无关,

它只提供了一种方法来调用调用

消息框的函数。


只需制作原始字符串,删除innerHTML内容并在函数中使用

放置此:alert(scriptString)


您的代码隐藏文件包含这个(如果需要,转换为C#):

Public Sub Page_Load(Sender As Object,e As EventArgs)

Dim scriptString As String

scriptString ="< script language =''JavaScript''>功能DoClick()

{"

scriptString + =" alert(''你的消息框的定制消息

在这里显示' ')"

scriptString + ="}< / script>"


If(Not Me.IsStartupScriptRegistered(" Startup"))然后

Me.RegisterStartupScript(Startup,scriptString)

结束如果

结束子

和你的HTML页面包含:


< html>

< head>

< / head>

< body>

< form id =" myForm" runat =" server">

< input type =" button"值= QUOT; ClickMe" onclick =" DoClick()">

< / form>

< / body>

< / html>


" Russ" < RU **** @ eticomm.net>在消息中写道

新闻:aj ******************************** @ 4ax.com ...
Ok, a few things....

You can format the text to be shown in a messagebox so lose all the HTML in
the innerHTML of scriptString. In fact, you don''t need innerHTML at all,
just prepare a normal string with the text of your message. The example you
followed from the help is correct, but in that example, they are not making
messageboxes, they are producing text inside of a span tag.

Because you want the messagebox to be displayed in a web page, you are
limited to the messagebox provided by the Scripting Object Model of the
target browser. In other words, .NET has nothing to do with the messagebox,
it only provides a way for you to invoke the function that calls the
messagebox.

Just make the raw string, remove the innerHTML stuff and in your function
place this: alert(scriptString)

Your code behind file contains this (convert to C# if needed):

Public Sub Page_Load(Sender As Object,e As EventArgs)
Dim scriptString As String
scriptString = "<script language=''JavaScript''> function DoClick()
{"
scriptString += "alert(''YOUR CUSTOM MESSAGE FOR THE MESSAGEBOX TO
SHOW HERE'')"
scriptString += "}</script>"

If(Not Me.IsStartupScriptRegistered("Startup")) Then
Me.RegisterStartupScript("Startup", scriptString)
End If
End Sub
And your HTML page contains this:

<html>
<head>
</head>
<body>
<form id="myForm" runat="server">
<input type="button" value="ClickMe" onclick="DoClick()">
</form>
</body>
</html>

"Russ" <ru****@eticomm.net> wrote in message
news:aj********************************@4ax.com...
我一直试图弄清楚如何在我的Web客户端程序(C#)中显示一个带有
OK按钮的简单消息框。我已经看过每个
对JScript和MessageBox的引用,这些引用在VS帮助和NG中都可能有点像它可能有所帮助。我找到了许多人的例子,说明它是多么容易,并在帮助中显示示例和
示例。但我有两个问题:

1.所有示例都显示HTML中的所有代码,通常涉及用户操作,例如按钮单击。由于从Web服务调用返回,我需要显示此消息框
。因此,调用消息框的代码必须在代码隐藏中。

2.所有示例都不起作用!!这是我很久以来见过的最让人沮丧的事情。每个人似乎都说试试这个有用,
我尝试了,甚至无法接近!首先,当我将一些
脚本粘贴到我的HTML中时,例如:

< script language =" C#" runat =" server">
public void Page_Load(Object sender,EventArgs e){
//形成要在客户端注册的脚本。
String scriptString ="< script language = JavaScript>函数DoClick()
{" ;;
scriptString + =" showMessage2.innerHTML =''< h4>欢迎使用Microsoft
.NET!< / h4>''}" ;;
scriptString + =" function Page_Load(){showMessage1.innerHTML =" ;;
scriptString + ="''< h4> RegisterStartupScript示例< / h4>''}<" ;;
scriptString + =" /" ;;
scriptString + =" script>" ;;

if(!this.IsStartupScriptRegistered(" Startup"))
this.RegisterStartupScript(" Startup",scriptString);
}
< / script>

它会立即转换为如下所示:

& lt; script language =" C#" runat =" server"& gt;
public void Page_Load(Object sender,EventArgs e){
//形成要在客户端注册的脚本。
String scriptString =" & lt; script language = JavaScript& gt;功能
DoClick(){" ;;
scriptString + =" showMessage2.innerHTML =''& lt; h4& gt;欢迎来到
Microsoft .NET!& lt; / h4& gt;''}" ;;
scriptString + =" function Page_Load(){showMessage1.innerHTML =" ;;
scriptString + ="''& lt; h4& gt; RegisterStartupScript
示例& lt; / h4& gt;''}& lt;" ;;
scriptString + =" /" ;;
scriptString + =" script& gt; " ;;

if(!this.IsStartupScriptRegistered(" Startup"))
this.RegisterStartupScript(" Startup",scriptString);
}
& ; lt; / script& gt;

请注意所有<和>字符已转换为& lt;然后当我手动编辑线条来纠正它们时,示例将不会运行
和/或>

通常它会编译运行,有时我会得到一个服务器错误,但更多时候它似乎只是将代码回显到页面。
上面的例子最接近工作。当我添加:

< span id =" showMessage1">< / span>
< br>
< input type =" button"值= QUOT; ClickMe"表格中的onclick =" DoClick()">
< br>
< span id =" showMessage2">< / span>

它确实放了一个按钮,但是当我点击它时,我得到了一个
状态行,上面写着页面上的错误。

A到Z教程的确切位置显示在哪里如何添加和制作这个脚本在Web客户端应用程序中工作?

即使上面的例子工作也似乎非常复杂
只是为了竖起一个简单的盒子!验证器摘要可以通过
包括MessageBox =true来完成。没脚本!但当然这对我不起作用,因为我需要将它与网络服务响应联系起来。

请帮忙吗?

谢谢,Russ
I''ve been trying to figure out how to show a simple messagebox with an
OK button in my web client program (C#). I have looked at every
reference to JScript and MessageBox that seemed even remotely like it
could help, both in the VS help and in this NG. I found lots of
examples of people saying how easy it is and showing examples, and
examples in the help. But I have two problems:

1. All the examples show all the code in HTML, usually involving a
user action such as a button click. I need to show this message box
as a result of a return from a web service call. So the code to
invoke the message box must be in the code-behind.

2. None of the examples work!! This is the most frustrating thing I
have seen in a long time. Everyone seems to say "Try this it works",
and I try it and can''t even get close! First off, when I paste some
script into my HTML, like:

<script language="C#" runat="server">
public void Page_Load(Object sender, EventArgs e) {
// Form the script to be registered at client side.
String scriptString = "<script language=JavaScript> function DoClick()
{";
scriptString += "showMessage2.innerHTML=''<h4>Welcome to Microsoft
.NET!</h4>''}";
scriptString += "function Page_Load(){ showMessage1.innerHTML=";
scriptString += "''<h4>RegisterStartupScript Example</h4>''}<";
scriptString += "/";
scriptString += "script>";

if(!this.IsStartupScriptRegistered("Startup"))
this.RegisterStartupScript("Startup", scriptString);
}
</script>

It is immediately converted to look like this:

&lt;script language="C#" runat="server"&gt;
public void Page_Load(Object sender, EventArgs e) {
// Form the script to be registered at client side.
String scriptString = "&lt;script language=JavaScript&gt; function
DoClick() {";
scriptString += "showMessage2.innerHTML=''&lt;h4&gt;Welcome to
Microsoft .NET!&lt;/h4&gt;''}";
scriptString += "function Page_Load(){ showMessage1.innerHTML=";
scriptString += "''&lt;h4&gt;RegisterStartupScript
Example&lt;/h4&gt;''}&lt;";
scriptString += "/";
scriptString += "script&gt;";

if(!this.IsStartupScriptRegistered("Startup"))
this.RegisterStartupScript("Startup", scriptString);
}
&lt;/script&gt;

Notice that all the < and > characters have been converted to &lt; and
&gt;

Then when I manually edit the lines to correct them, the example will
not run. Usually it will compile and run, sometimes I get a server
error, but more often it seems to simply echo the code to the page.
The example above came the closest to working. When I added:

<span id="showMessage1"></span>
<br>
<input type="button" value="ClickMe" onclick="DoClick()">
<br>
<span id="showMessage2"></span>

in the form, it did put up a button, but when I click it, I get a
status line that says "error on page".

Where is the A to Z tutorial that shows exactly how to add and make
this script work in a web client application?

Even if the above example will work it seems terribly over complicated
just to put up a simple box! The validator summary can do it by just
including MessageBox="true". No script! But of course this will not
work for me since I need to tie it to a web service response.

Please help?

Thanks, Russ



< script language =" C#" runat =" server">

public void Page_Load(Object sender,EventArgs e)

{

RegisterStartupScript(" Startup", string.Format("< {0}> alert(''点击

继续'');< / {0}>"," script"));

}

< / script>


时髦的语法是因为你不能使用"< script>" ;在

aspx页面的文字中(虽然你当然可以在后面的代码中)。

- 布鲁斯(sqlwork.com)

" Russ" < RU **** @ eticomm.net>在消息中写道

新闻:aj ******************************** @ 4ax.com ...
<script language="C#" runat="server">
public void Page_Load(Object sender, EventArgs e)
{
RegisterStartupScript("Startup", string.Format("<{0}>alert(''Click to
continue'');</{0}>","script"));
}
</script>

the funky syntax is because you can not use "<script>" in a literal in an
aspx page (though you can of course in the code behind).
-- bruce (sqlwork.com)

"Russ" <ru****@eticomm.net> wrote in message
news:aj********************************@4ax.com...
我一直试图弄清楚如何在我的Web客户端程序(C#)中显示一个带有
OK按钮的简单消息框。我已经看过每个
对JScript和MessageBox的引用,这些引用在VS帮助和NG中都可能有点像它可能有所帮助。我找到了许多人的例子,说明它是多么容易,并在帮助中显示示例和
示例。但我有两个问题:

1.所有示例都显示HTML中的所有代码,通常涉及用户操作,例如按钮单击。由于从Web服务调用返回,我需要显示此消息框
。因此,调用消息框的代码必须在代码隐藏中。

2.所有示例都不起作用!!这是我很久以来见过的最让人沮丧的事情。每个人似乎都说试试这个有用,
我尝试了,甚至无法接近!首先,当我将一些
脚本粘贴到我的HTML中时,例如:

< script language =" C#" runat =" server">
public void Page_Load(Object sender,EventArgs e){
//形成要在客户端注册的脚本。
String scriptString ="< script language = JavaScript>函数DoClick()
{" ;;
scriptString + =" showMessage2.innerHTML =''< h4>欢迎使用Microsoft
.NET!< / h4>''}" ;;
scriptString + =" function Page_Load(){showMessage1.innerHTML =" ;;
scriptString + ="''< h4> RegisterStartupScript示例< / h4>''}<" ;;
scriptString + =" /" ;;
scriptString + =" script>" ;;

if(!this.IsStartupScriptRegistered(" Startup"))
this.RegisterStartupScript(" Startup",scriptString);
}
< / script>

它会立即转换为如下所示:

& lt; script language =" C#" runat =" server"& gt;
public void Page_Load(Object sender,EventArgs e){
//形成要在客户端注册的脚本。
String scriptString =" & lt; script language = JavaScript& gt;功能
DoClick(){" ;;
scriptString + =" showMessage2.innerHTML =''& lt; h4& gt;欢迎来到
Microsoft .NET!& lt; / h4& gt;''}" ;;
scriptString + =" function Page_Load(){showMessage1.innerHTML =" ;;
scriptString + ="''& lt; h4& gt; RegisterStartupScript
示例& lt; / h4& gt;''}& lt;" ;;
scriptString + =" /" ;;
scriptString + =" script& gt; " ;;

if(!this.IsStartupScriptRegistered(" Startup"))
this.RegisterStartupScript(" Startup",scriptString);
}
& ; lt; / script& gt;

请注意所有<和>字符已转换为& lt;然后当我手动编辑线条来纠正它们时,示例将不会运行
和/或>

通常它会编译运行,有时我会得到一个服务器错误,但更多时候它似乎只是将代码回显到页面。
上面的例子最接近工作。当我添加:

< span id =" showMessage1">< / span>
< br>
< input type =" button"值= QUOT; ClickMe"表格中的onclick =" DoClick()">
< br>
< span id =" showMessage2">< / span>

它确实放了一个按钮,但是当我点击它时,我得到了一个
状态行,上面写着页面上的错误。

A到Z教程的确切位置显示在哪里如何添加和制作这个脚本在Web客户端应用程序中工作?

即使上面的例子工作也似乎非常复杂
只是为了竖起一个简单的盒子!验证器摘要可以通过
包括MessageBox =true来完成。没脚本!但当然这对我不起作用,因为我需要将它与网络服务响应联系起来。

请帮忙吗?

谢谢,Russ
I''ve been trying to figure out how to show a simple messagebox with an
OK button in my web client program (C#). I have looked at every
reference to JScript and MessageBox that seemed even remotely like it
could help, both in the VS help and in this NG. I found lots of
examples of people saying how easy it is and showing examples, and
examples in the help. But I have two problems:

1. All the examples show all the code in HTML, usually involving a
user action such as a button click. I need to show this message box
as a result of a return from a web service call. So the code to
invoke the message box must be in the code-behind.

2. None of the examples work!! This is the most frustrating thing I
have seen in a long time. Everyone seems to say "Try this it works",
and I try it and can''t even get close! First off, when I paste some
script into my HTML, like:

<script language="C#" runat="server">
public void Page_Load(Object sender, EventArgs e) {
// Form the script to be registered at client side.
String scriptString = "<script language=JavaScript> function DoClick()
{";
scriptString += "showMessage2.innerHTML=''<h4>Welcome to Microsoft
.NET!</h4>''}";
scriptString += "function Page_Load(){ showMessage1.innerHTML=";
scriptString += "''<h4>RegisterStartupScript Example</h4>''}<";
scriptString += "/";
scriptString += "script>";

if(!this.IsStartupScriptRegistered("Startup"))
this.RegisterStartupScript("Startup", scriptString);
}
</script>

It is immediately converted to look like this:

&lt;script language="C#" runat="server"&gt;
public void Page_Load(Object sender, EventArgs e) {
// Form the script to be registered at client side.
String scriptString = "&lt;script language=JavaScript&gt; function
DoClick() {";
scriptString += "showMessage2.innerHTML=''&lt;h4&gt;Welcome to
Microsoft .NET!&lt;/h4&gt;''}";
scriptString += "function Page_Load(){ showMessage1.innerHTML=";
scriptString += "''&lt;h4&gt;RegisterStartupScript
Example&lt;/h4&gt;''}&lt;";
scriptString += "/";
scriptString += "script&gt;";

if(!this.IsStartupScriptRegistered("Startup"))
this.RegisterStartupScript("Startup", scriptString);
}
&lt;/script&gt;

Notice that all the < and > characters have been converted to &lt; and
&gt;

Then when I manually edit the lines to correct them, the example will
not run. Usually it will compile and run, sometimes I get a server
error, but more often it seems to simply echo the code to the page.
The example above came the closest to working. When I added:

<span id="showMessage1"></span>
<br>
<input type="button" value="ClickMe" onclick="DoClick()">
<br>
<span id="showMessage2"></span>

in the form, it did put up a button, but when I click it, I get a
status line that says "error on page".

Where is the A to Z tutorial that shows exactly how to add and make
this script work in a web client application?

Even if the above example will work it seems terribly over complicated
just to put up a simple box! The validator summary can do it by just
including MessageBox="true". No script! But of course this will not
work for me since I need to tie it to a web service response.

Please help?

Thanks, Russ



这篇关于MessageBox问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆