473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

MessageBox questions

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
10 2314
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
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
<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
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
> 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
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
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
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gerry Viator | last post by:
Hi all, Whats going on. Testing messagebox, text isn't showing up. Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code "
11
by: Rich Tasker | last post by:
I have a strange situation. A simple call to MessageBox.Show("XXX", "YYY") does not display the message in the messagebox with a visible font. Based on the content of the messagebox, the box...
3
by: sdeyoreo | last post by:
How do I display the integer in pt.x in a message box? I get a error on parameter 2 of MessageBox call: char str; sprintf(str,"point x is %d",pt.x); MessageBox(NULL,str,NULL,MB_OK);
8
by: Dennis C. Drumm | last post by:
I have ordered the book .NET Framework Solutions, In Search of the Lost Win32 API by John Paul Meuller which I think will help answer some of my questions I have regarding making custom...
2
by: Dennis C. Drumm | last post by:
This is a restatement of an earlier post that evidently wasn't clear. I am building a custom MessageBox dialog that has, among other things, a few new button options (yes to all, no to all, etc.)...
4
by: Tressa | last post by:
I have a messagebox that I only want to pop up only if it is not already being displayed on the screen. My code is still poping up the messagebox even though it is on the screen. What am I doing...
0
by: alex_f_il | last post by:
The class centers MessageBox inside the parent rectangle. Enjoy! using System; using System.Windows.Forms; using System.Text; using System.Drawing; using System.Runtime.InteropServices; ...
4
by: Doug Robertson | last post by:
I hope this is one of those simple questions that for some reason or another, I'm just missing the obvious. Using VB.NET 2003 I want my messagebox to display centered on the parrent form...
8
by: Elliot | last post by:
Is it possible to show a MessageBox(Yes&No button) and assume "No" was clicked if nothing was clicked 10 seconds after the MessageBox begins to appear?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.