By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,053 Members | 922 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,053 IT Pros & Developers. It's quick & easy.

MessageBox questions

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
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...
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

Nov 18 '05 #2

P: n/a
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...
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

Nov 18 '05 #3

P: n/a
<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...
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

Nov 18 '05 #4

P: n/a
Thanks to Alvin, Scott & Bruce for the help. Alvin, of course your
line worked right away, but then I wanted more. Namely I wanted to be
able to change the text that was displayed dynamically. It took me a
while to figure this out but eventually I came up with a function:

private void MsgBox (String msg)
{
String s = "<script>alert('" + msg + "')</script>";
LiteralControl lc = new LiteralControl (s);
Page.Controls.Add (lc);
}

I will extend it to handle confirm and prompt boxes, and to return the
values. What I cannot figure out is: Why the heck aren't functions
like this in the library, instead of making people deal with the
script? I suppose it is not big deal to anyone who has been using
jscript for a while, but to someone like me who's only experience with
script was from AWK about a hundred years ago - whew!

Thanks again, Russ
On Thu, 03 Jun 2004 17:07:39 -0400, Russ <ru****@eticomm.net> wrote:
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


Nov 18 '05 #5

P: n/a
> What I cannot figure out is: Why the heck aren't functions
like this in the library, instead of making people deal with the
script? I suppose it is not big deal to anyone who has been using
jscript for a while, but to someone like me who's only experience with
script was from AWK about a hundred years ago - whew!


Because what you are attempting to do is a browser based solution, not a
..NET solution. .NET simply gives you a way to tap into the browser's
functionality.

You can't produce messageboxes in a web page from the server-side code of
..NET. Think about it a second, when the .NET code is processing, it is
processing on a web server. Since a messagebox requires user input and the
user can't interact with the code that runs on the server, it's left up to
the browser to provide the GUI.
Nov 18 '05 #6

P: n/a
By the way, you probably want to rename your function to something other
than MsgBox since that is a function in the VBScript (and also in VB.NET)
language and could conflict with the interpretation of your function.
"Russ" <ru****@eticomm.net> wrote in message
news:v6********************************@4ax.com...
Thanks to Alvin, Scott & Bruce for the help. Alvin, of course your
line worked right away, but then I wanted more. Namely I wanted to be
able to change the text that was displayed dynamically. It took me a
while to figure this out but eventually I came up with a function:

private void MsgBox (String msg)
{
String s = "<script>alert('" + msg + "')</script>";
LiteralControl lc = new LiteralControl (s);
Page.Controls.Add (lc);
}

I will extend it to handle confirm and prompt boxes, and to return the
values. What I cannot figure out is: Why the heck aren't functions
like this in the library, instead of making people deal with the
script? I suppose it is not big deal to anyone who has been using
jscript for a while, but to someone like me who's only experience with
script was from AWK about a hundred years ago - whew!

Thanks again, Russ
On Thu, 03 Jun 2004 17:07:39 -0400, Russ <ru****@eticomm.net> wrote:
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

Nov 18 '05 #7

P: n/a
Check out this control,
http://www.microsoft.com/india/msdn/articles/119.aspx

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com

"Russ" <ru****@eticomm.net> wrote in message
news:v6********************************@4ax.com...
Thanks to Alvin, Scott & Bruce for the help. Alvin, of course your
line worked right away, but then I wanted more. Namely I wanted to be
able to change the text that was displayed dynamically. It took me a
while to figure this out but eventually I came up with a function:

private void MsgBox (String msg)
{
String s = "<script>alert('" + msg + "')</script>";
LiteralControl lc = new LiteralControl (s);
Page.Controls.Add (lc);
}

I will extend it to handle confirm and prompt boxes, and to return the
values. What I cannot figure out is: Why the heck aren't functions
like this in the library, instead of making people deal with the
script? I suppose it is not big deal to anyone who has been using
jscript for a while, but to someone like me who's only experience with
script was from AWK about a hundred years ago - whew!

Thanks again, Russ
On Thu, 03 Jun 2004 17:07:39 -0400, Russ <ru****@eticomm.net> wrote:
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

Nov 18 '05 #8

P: n/a
Hi Scott. I understand about where the code is executed, but still,
this solution is a function that is executed at the server, in the web
client code. Just because the script is not executed until the page
has been sent to the browser does not mean that it is not a valid
client function.

So, what would have been wrong with the library designers saying "Here
are a few functions that you can use to produce certain actions at the
browser, if executed by the client code"?

Anyway it does what I want so I am happy now. Part of my problem was
that I did not know that script could be inserted by the code - I
thought it all had to be done in the HTML part of the client. Thanks
again to all for the help and explanations.

Regards, Russ
On Thu, 3 Jun 2004 23:07:26 -0400, "Scott M." <s-***@nospam.nospam>
wrote:
What I cannot figure out is: Why the heck aren't functions
like this in the library, instead of making people deal with the
script? I suppose it is not big deal to anyone who has been using
jscript for a while, but to someone like me who's only experience with
script was from AWK about a hundred years ago - whew!


Because what you are attempting to do is a browser based solution, not a
.NET solution. .NET simply gives you a way to tap into the browser's
functionality.

You can't produce messageboxes in a web page from the server-side code of
.NET. Think about it a second, when the .NET code is processing, it is
processing on a web server. Since a messagebox requires user input and the
user can't interact with the code that runs on the server, it's left up to
the browser to provide the GUI.


Nov 18 '05 #9

P: n/a
In addition, you can inject script into a page using
Response.Write("<script>....
RegisterStartupScript and RegisterClientScript. Each variation gives a bit
of control on exactly where in the html resulting page the script is
injected.

--
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:jd********************************@4ax.com...
Hi Scott. I understand about where the code is executed, but still,
this solution is a function that is executed at the server, in the web
client code. Just because the script is not executed until the page
has been sent to the browser does not mean that it is not a valid
client function.

So, what would have been wrong with the library designers saying "Here
are a few functions that you can use to produce certain actions at the
browser, if executed by the client code"?

Anyway it does what I want so I am happy now. Part of my problem was
that I did not know that script could be inserted by the code - I
thought it all had to be done in the HTML part of the client. Thanks
again to all for the help and explanations.

Regards, Russ
On Thu, 3 Jun 2004 23:07:26 -0400, "Scott M." <s-***@nospam.nospam>
wrote:
What I cannot figure out is: Why the heck aren't functions
like this in the library, instead of making people deal with the
script? I suppose it is not big deal to anyone who has been using
jscript for a while, but to someone like me who's only experience with
script was from AWK about a hundred years ago - whew!


Because what you are attempting to do is a browser based solution, not a
.NET solution. .NET simply gives you a way to tap into the browser's
functionality.

You can't produce messageboxes in a web page from the server-side code of
.NET. Think about it a second, when the .NET code is processing, it is
processing on a web server. Since a messagebox requires user input and
the
user can't interact with the code that runs on the server, it's left up to
the browser to provide the GUI.

Nov 18 '05 #10

P: n/a

"Russ" <ru****@eticomm.net> wrote in message
news:jd********************************@4ax.com...
Hi Scott. I understand about where the code is executed, but still,
this solution is a function that is executed at the server, in the web
client code.
Well, that's not quite true Russ. The function is not executed on the
server. All that happens on the server is that the function is delivered
(as it - not the executed results of the function, just the function's code)
to the client along with an event handler for that function.
Just because the script is not executed until the page
has been sent to the browser does not mean that it is not a valid
client function.
I'm not sure what you mean here. Of course it is a valid client function if
it runs on the client.
So, what would have been wrong with the library designers saying "Here
are a few functions that you can use to produce certain actions at the
browser, if executed by the client code"?
They did do just that, they gave us RegisterStartupScript and
control.attributes.add for adding other client event handlers.

Anyway it does what I want so I am happy now. Part of my problem was
that I did not know that script could be inserted by the code - I
thought it all had to be done in the HTML part of the client. Thanks
again to all for the help and explanations.

Glad it's working.
Nov 18 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.