message box

  • Thread starter Thread starter Ankit Aneja
  • Start date Start date
A

Ankit Aneja

Hi i want to show or fire a message box from
code behind my.cs file of asp.net web application
how can i do that i am using framework 1.1
 
public static void MsgBox(string strMessage, string UniqueScriptName)
{
StringBuilder s;
System.Web.UI.Page p;
try
{
if (HttpContext.Current == null) return;
s = new StringBuilder("<script type=\"text/javascript\">" + nl +
"<!--" + nl);
s.Append("alert('" + strMessage.Replace("\"", "\\\"") + "');" + nl +
"// --></script>");
p = (System.Web.UI.Page) HttpContext.Current.Handler;
if (!(p.ClientScript.IsStartupScriptRegistered("MsgBox")))
p.ClientScript.RegisterStartupScript(p.GetType(), UniqueScriptName,
s.ToString(), true);
}
catch (Exception ex)
{
HandleError(ex);
}
}

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
Do a script callback and point to a javascript function that does:

<script type=text/javascript language=javascript>
function MessageBx()
{

Alert("Message to display);
}
</script>

You cannot use a messag box normally because asp is server side....it
will try to display the box on the server. Javascript is the easiest
way to accomplish this. It is client side and will display the box
with the "Alert()" method.
 
Response.Write("<script language=jscript>alert('" + "hello" +
"')</script>");

solved
 
Ah sorry. I created a static variable with a short name to substitute for
having to write Environment.NewLine with each new line:

private static string nl = Environment.NewLine;

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.
 
Hi Ankit,

Glad that you're got it working.

BTW, for registering client-side script, we're recommended to use the
Page.ClientScript.XXXX methods instead of Response.Write to do the work.
The page's encapsulated methods can help ensure the startup script or
script block be registered and output at the appropriate place.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top