R
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:
<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>
Notice that all the < and > characters have been converted to < and
>
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
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:
<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>
Notice that all the < and > characters have been converted to < and
>
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