I am new to ASP.Net and really need to know how can one display an Alert in a webpage. I know that Adobe Flex and the Javascript offer controls to display the Alert but have no idea of this being present in the ASP.Net
So if anyone can provide the control or a technique to display an alert it would really be helpful
JavaScript is JavaScript - all these frameworks do is offer you different ways of putting the alert('message'); on the page. You can either write an alert straight to your page
There are two scenerios, either you want to display message while staying on clientside or you want to display message from server side i.e. after page postback.
In any case, alert() of JScript is the only option to display a meassge box. You can invoke any javascript function from code behind as guided in other replies.
Moreover, Asp.Net do provide a wide range of Validation Controls to validate web form input. There exists a property ' ShowMessageBox ' in ValidationSummary control, that, if set to true, would display an alert box against a wrong input. To see how to use
it, visit
Display Message Box Against Wrong Input.
Another weird approach is to just import System.Windows.Forms namespace and start using MessageBox.Show().
Don't forget to Mark this as an Answer, if it helps
I am new to ASP.Net and really need to know how can one display an Alert in a webpage. I know that Adobe Flex and the Javascript offer controls to display the Alert but have no idea of this being present in the ASP.Net
So if anyone can provide the control or a technique to display an alert it would really be helpful
You could try using this method, maybe it can help you
moonlight007
Member
1 Points
1 Post
ASP.Net Message Box Alert Display
Aug 20, 2009 02:38 PM|LINK
I am new to ASP.Net and really need to know how can one display an Alert in a webpage. I know that Adobe Flex and the Javascript offer controls to display the Alert but have no idea of this being present in the ASP.Net
So if anyone can provide the control or a technique to display an alert it would really be helpful
atconway
All-Star
16846 Points
2756 Posts
Re: ASP.Net Message Box Alert Display
Aug 20, 2009 03:41 PM|LINK
Try the code below:
System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">alert("Hello this is an Alert")</SCRIPT>")Ibro
Participant
1402 Points
455 Posts
Re: ASP.Net Message Box Alert Display
Aug 20, 2009 03:46 PM|LINK
this might help you
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick = "return confirm('Are you sure you want to delete?');"/>Ibro
Spider.net
Member
367 Points
165 Posts
Re: ASP.Net Message Box Alert Display
Aug 20, 2009 03:51 PM|LINK
In ASp.NET web page to display the alert by using java script as you said alert(); method.
For more refer the link below how to use alert in ASP.NET
1) http://weblogs.asp.net/bleroy/archive/2005/12/01/432016.aspx
2) http://www.beansoftware.com/ASP.NET-Tutorials/Message-Box.aspx
3) http://www.dotnetspider.com/forum/ViewForum.aspx?ForumId=32564
4) http://aspnet.4guysfromrolla.com/articles/021104-1.aspx
5) http://www.codeproject.com/KB/webforms/NingLiangSimpleControl.aspx
6) http://stackoverflow.com/questions/651592/how-to-display-an-error-message-box-in-a-web-application-asp-net-c
mendhak
All-Star
17868 Points
2787 Posts
Re: ASP.Net Message Box Alert Display
Aug 20, 2009 05:11 PM|LINK
JavaScript is JavaScript - all these frameworks do is offer you different ways of putting the alert('message'); on the page. You can either write an alert straight to your page
<script type="text/JavaScript">
alert('hello world');
</script>
You can use the ASP.NET codebehind to write it to the page
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
You can also response.write it to the page as shown earlier, you can also write the javascript to a literal on the page.
Bober Song -...
All-Star
34686 Points
2167 Posts
Re: ASP.Net Message Box Alert Display
Aug 25, 2009 09:25 AM|LINK
Hi moonlight007,
From your description, you want to display the messagebox in the page.
You can use the javascript alert or confirm function for this requirement.
Of course, you can display a div for message box by the div tag display property.
By the way, I recommend you use the JQuery plugin for showing the messagebox.
Facebox
http://famspam.com/facebox
http://www.electrictoolbox.com/jquery-facebox-greyed-background/
http://weblogs.asp.net/kyleholder/archive/2008/01/22/jquery-facebox-and-ajax.aspx
Thickbox
http://jquery.com/demo/thickbox/
lightbox
http://www.balupton.com/sandbox/jquery_lightbox_bal/demo/
FancyBox
http://fancy.klade.lv/
Impromptu
http://trentrichardson.com/Impromptu/index.php
Boxy
http://onehackoranother.com/projects/jquery/boxy/index.php#downloading
Let me know whether that answers your question, or if I've missed something.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
malthiru06
Member
20 Points
12 Posts
Re: ASP.Net Message Box Alert Display
Jan 07, 2010 03:44 AM|LINK
Thanks You..i got proper solutions.to display alert box using server side code
string myStringVariable = string.Empty;
myStringVariable = "Welcome";
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
jitendramcu
Contributor
2782 Points
459 Posts
Re: ASP.Net Message Box Alert Display
Jan 07, 2010 04:46 AM|LINK
you can also create custom control for alert and conformation see this link.
http://www.codeproject.com/KB/webforms/NingLiangSimpleControl.aspx
-----------------------------------------------
Jitendra Kr.
http://jitendra-aspnet.blogspot.com/
awaishafeez8...
Member
12 Points
9 Posts
Re: ASP.Net Message Box Alert Display
Jul 09, 2010 11:06 AM|LINK
Hi,
There are two scenerios, either you want to display message while staying on clientside or you want to display message from server side i.e. after page postback.
In any case, alert() of JScript is the only option to display a meassge box. You can invoke any javascript function from code behind as guided in other replies.
Moreover, Asp.Net do provide a wide range of Validation Controls to validate web form input. There exists a property ' ShowMessageBox ' in ValidationSummary control, that, if set to true, would display an alert box against a wrong input. To see how to use it, visit Display Message Box Against Wrong Input.
Another weird approach is to just import System.Windows.Forms namespace and start using MessageBox.Show().
Don't forget to Mark this as an Answer, if it helps
Thank you
alert in asp.net
quangngoc88
Member
3 Points
1 Post
Re: ASP.Net Message Box Alert Display
Aug 23, 2011 08:23 AM|LINK
You could try using this method, maybe it can help you
private void ShowPopUpMsg(string msg) { StringBuilder sb = new StringBuilder(); sb.Append("alert('"); sb.Append(msg.Replace("\n", "\\n").Replace("\r", "").Replace("'", "\\'")); sb.Append("');"); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "showalert", sb.ToString(), true); }