[Resolved] MessageBox ASP.NET (C#)
Hi all,
I'm using C# to write some ASP.NET page.
Does anyone know that how to MessageBox in aspx page?
I typed this "MessageBox.Show("Test");
and run i got an errr that "The type or namespace name MessageBox could not be found (are you missing a using directive or an assembly reference?)" :confused:
Thanks for advance
Re: MessageBox ASP.NET (VB.net)
hi
this code in vb.net
convert it into c#
Switch to the HTML view of your Web form and add the following immediately after the close of the <body> tag:
<script>
<asp:Literal id="ltlAlert" runat="server"
EnableViewState="False">
</asp:Literal>
</script>
Switch back to Design view and save your Web form. This has set up your Literal server control manually—due to the surrounding <script> tags; we couldn't do this using the designer.
Enter the code window behind your Web form and add the following underneath the Public Class and Inherits lines, which allows us to manipulate this control in code:
Protected WithEvents ltlAlert _
As System.Web.UI.WebControls.Literal
Add the following code snippet behind your Web form. This takes a string and incorporates it into a JavaScript 'alert' command, which is then placed on the Web page as pure HTML:
Private Sub Say(ByVal Message As String)
' Format string properly
Message = Message.Replace("'", "\'")
Message = Message.Replace(Convert.ToChar(10), "\n")
Message = Message.Replace(Convert.ToChar(13), "")
' Display as JavaScript alert
ltlAlert.Text = "alert('" & Message & "')"
End Sub
Whenever you want to display an in-your-face message, simply call this Say function in your code—as the following snippet demonstrates:
Say("Sorry, your password is invalid! " & _
Microsoft.VisualBasic.vbNewLine & _
"Please try again, or click the Signup button to _
register now.")
:wave:
if work send me reply at
[email protected]
Re: MessageBox ASP.NET (C#)