ASP.NET MESSAGE BOX

ASP.NET MESSAGE BOX

am 20.01.2005 20:37:05 von AdamPC

Hi there,
I have the following code which displays a message box on my asp.net page...
i can call this function from a button click or whatever, but the only
problem is that it turns the whole window white and displays the message,
then once you click OK, then the screen goes back to normal... how do i
change it so that the message box just pops up on top of the window and
doesn't turn it all white..???


Public Sub ASPNET_MsgBox(ByVal Message As String)
Try
System.Web.HttpContext.Current.Response.Write("")

Catch ex As Exception
End Try

End Sub

--
AdamPC@hotmail.com

Re: ASP.NET MESSAGE BOX

am 20.01.2005 22:44:13 von Eliyahu Goldin

That is because you produce the message box before the html body loads.

Put the script on the page and just pass message text from the server like
this:




and in code-behind:

Response.Write ("")

Eliyahu

"ACaunter" wrote in message
news:48B95CDE-54BB-4A7F-9E19-422A271EDC5B@microsoft.com...
> Hi there,
> I have the following code which displays a message box on my asp.net
page...
> i can call this function from a button click or whatever, but the only
> problem is that it turns the whole window white and displays the message,
> then once you click OK, then the screen goes back to normal... how do i
> change it so that the message box just pops up on top of the window and
> doesn't turn it all white..???
>
>
> Public Sub ASPNET_MsgBox(ByVal Message As String)
> Try
> System.Web.HttpContext.Current.Response.Write(" > LANGUAGE=""JavaScript"">" & vbCrLf)
>
> System.Web.HttpContext.Current.Response.Write("alert(""" &
> Message & """)" & vbCrLf)
>
> System.Web.HttpContext.Current.Response.Write("")
>
> Catch ex As Exception
> End Try
>
> End Sub
>
> --
> AdamPC@hotmail.com

Re: ASP.NET MESSAGE BOX

am 20.01.2005 23:41:16 von Steve

This is because your Response.Write line writes out the alert command very
first thing, so it is executed before the rest of the page is interpreted by
the browser.
You can fix this by outputing the alert line last, or by executing in in the
client side OnLoad event of the page.
Here's more info:
http://steveorr.net/articles/ClientSideSuite.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net



"ACaunter" wrote in message
news:48B95CDE-54BB-4A7F-9E19-422A271EDC5B@microsoft.com...
> Hi there,
> I have the following code which displays a message box on my asp.net
> page...
> i can call this function from a button click or whatever, but the only
> problem is that it turns the whole window white and displays the message,
> then once you click OK, then the screen goes back to normal... how do i
> change it so that the message box just pops up on top of the window and
> doesn't turn it all white..???
>
>
> Public Sub ASPNET_MsgBox(ByVal Message As String)
> Try
> System.Web.HttpContext.Current.Response.Write(" > LANGUAGE=""JavaScript"">" & vbCrLf)
>
> System.Web.HttpContext.Current.Response.Write("alert(""" &
> Message & """)" & vbCrLf)
>
> System.Web.HttpContext.Current.Response.Write("")
>
> Catch ex As Exception
> End Try
>
> End Sub
>
> --
> AdamPC@hotmail.com

Re: ASP.NET MESSAGE BOX

am 20.01.2005 23:49:56 von Dave Fancher

http://msdn.microsoft.com/library/default.asp?url=/library/e n-us/cpref/html/frlrfsystemwebuipageclassregisterclientscrip tblocktopic.asp

--
Dave Fancher
http://davefancher.blogspot.com


"ACaunter" wrote in message
news:48B95CDE-54BB-4A7F-9E19-422A271EDC5B@microsoft.com...
> Hi there,
> I have the following code which displays a message box on my asp.net
> page...
> i can call this function from a button click or whatever, but the only
> problem is that it turns the whole window white and displays the message,
> then once you click OK, then the screen goes back to normal... how do i
> change it so that the message box just pops up on top of the window and
> doesn't turn it all white..???
>
>
> Public Sub ASPNET_MsgBox(ByVal Message As String)
> Try
> System.Web.HttpContext.Current.Response.Write(" > LANGUAGE=""JavaScript"">" & vbCrLf)
>
> System.Web.HttpContext.Current.Response.Write("alert(""" &
> Message & """)" & vbCrLf)
>
> System.Web.HttpContext.Current.Response.Write("")
>
> Catch ex As Exception
> End Try
>
> End Sub
>
> --
> AdamPC@hotmail.com

Re: ASP.NET MESSAGE BOX

am 07.03.2005 12:48:36 von Oliver Weichhold

Adam,

After searching for the same problem myself, and seeing these complicated
responses, I found my own MUCH simpler answer: Add a label to the page,
instead of using response.write.

Create a sub like so:
Private Sub ShowAlert(ByVal Message As String)
Dim MyAlertLabel As New Label
MyAlertLabel.Text = ""
Page.Controls.Add(MyAlertLabel)
End Sub

This will display an alert box without blanking the screen. Adding the new
label did not change the appearance of the page, in the testing I did. It
behaves just like a message box in VB, you can add the ShowAlert("xxx")
within your code wherever you need it, (like in an If statement), it does
not need to be tied to a submit button. For example, you can make it pop up
when the user types in an invalid value on your form.
One suggestion: You do have to make sure to use "VbCrLf" as a newline
character (instead of "VbNewLine") when creating your message, or it will
cause an error on the page.

--
Christopher W. Douglas
www (dot) douglasweb (dot) com
chris (at) douglasweb (dot) com

"ACaunter" wrote in message
news:48B95CDE-54BB-4A7F-9E19-422A271EDC5B@microsoft.com...
> Hi there,
> I have the following code which displays a message box on my asp.net
page...
> i can call this function from a button click or whatever, but the only
> problem is that it turns the whole window white and displays the message,
> then once you click OK, then the screen goes back to normal... how do i
> change it so that the message box just pops up on top of the window and
> doesn't turn it all white..???
>
>
> Public Sub ASPNET_MsgBox(ByVal Message As String)
> Try
> System.Web.HttpContext.Current.Response.Write(" > LANGUAGE=""JavaScript"">" & vbCrLf)
>
> System.Web.HttpContext.Current.Response.Write("alert(""" &
> Message & """)" & vbCrLf)
>
> System.Web.HttpContext.Current.Response.Write("")
>
> Catch ex As Exception
> End Try
>
> End Sub
>
> --
> AdamPC@hotmail.com