Re: MessageBox questions
From: Russ (russk2_at_eticomm.net)
Date: 06/04/04
- Next message: Steve Franks: "Sample demonstrating how to create surveys?"
- Previous message: Steven Cheng[MSFT]: "Re: Client side scripting"
- In reply to: Russ: "MessageBox questions"
- Next in thread: Scott M.: "Re: MessageBox questions"
- Reply: Scott M.: "Re: MessageBox questions"
- Reply: Scott M.: "Re: MessageBox questions"
- Reply: Saravana [MVP]: "Re: MessageBox questions"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 03 Jun 2004 22:34:47 -0400
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 <russk2@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:
>
><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
>
- Next message: Steve Franks: "Sample demonstrating how to create surveys?"
- Previous message: Steven Cheng[MSFT]: "Re: Client side scripting"
- In reply to: Russ: "MessageBox questions"
- Next in thread: Scott M.: "Re: MessageBox questions"
- Reply: Scott M.: "Re: MessageBox questions"
- Reply: Scott M.: "Re: MessageBox questions"
- Reply: Saravana [MVP]: "Re: MessageBox questions"
- Messages sorted by: [ date ] [ thread ]