User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 402,070 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,595 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 2085 | Replies: 13 | Solved
Reply
Join Date: Sep 2007
Posts: 73
Reputation: ebabes is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
ebabes's Avatar
ebabes ebabes is offline Offline
Junior Poster in Training

Question What is the equivalent code of MessageBox in ASP.Net?

  #1  
Jan 22nd, 2008
Can anybody help me identify the code in ASP.Net that is equivalent to MessageBox (C#) or Alert (JSCript). I need a message box that will pop up when a certain condition is not fulfilled.

Your response is highly appreciated.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Posts: 1,057
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: What is the equivalent code of MessageBox in ASP.Net?

  #2  
Jan 23rd, 2008
vb.net:
MessageBox.Show("Your Message Here")
C#:
StringBuilder str = new StringBuilder();
str.Append("<script language='javascript'>");
str.Append("alert('Your Message')");
str.Append("</script>");
RegisterStartupService("Msg",str.toString());
Reply With Quote  
Join Date: Sep 2007
Posts: 73
Reputation: ebabes is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
ebabes's Avatar
ebabes ebabes is offline Offline
Junior Poster in Training

Question Re: What is the equivalent code of MessageBox in ASP.Net?

  #3  
Jan 25th, 2008
I tried the given code but I receive a message such as StringBuilder not found. Does it need an assembly or header file? What is it?
Reply With Quote  
Join Date: Jan 2008
Location: istanbul
Posts: 265
Reputation: serkansendur is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 23
serkansendur's Avatar
serkansendur serkansendur is offline Offline
Posting Whiz in Training

Re: What is the equivalent code of MessageBox in ASP.Net?

  #4  
Jan 25th, 2008
compiler cant found stringbuilder class since you didnt register the namespace. you can use the class' fully qualified name or you can use the using statement at the top of your code file like :

System.Text.StringBuilder s = new System.Text.StringBuilder();

or include the using statement above your class definition :

using System.Text;

then you wont get any compiler errors.
Reply With Quote  
Join Date: Jan 2008
Location: istanbul
Posts: 265
Reputation: serkansendur is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 23
serkansendur's Avatar
serkansendur serkansendur is offline Offline
Posting Whiz in Training

Re: What is the equivalent code of MessageBox in ASP.Net?

  #5  
Jan 25th, 2008
the easiest way to show a message box is this :

<asp:button id="foo" runat="server" text="foo" onclientclick="alert('message box is shown now')" />

i can help you with the details if you be more specific on what you want?
Reply With Quote  
Join Date: Jan 2008
Location: India
Posts: 147
Reputation: sbv is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
sbv's Avatar
sbv sbv is online now Online
Junior Poster

Re: What is the equivalent code of MessageBox in ASP.Net?

  #6  
Jan 28th, 2008
hi
as per my knowledge the best way for getting message box in asp.net project is creating a class and put there, following code.


'To display the message
Public Sub msgbox(ByVal msg As String, ByVal mypage As Page)
mypage.RegisterStartupScript("msg", "<script>alert('" & msg & "');</script>")
End Sub

then you can use this using object of this class any where in your project.

try this.

Best Luck.
Reply With Quote  
Join Date: Sep 2007
Posts: 73
Reputation: ebabes is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
ebabes's Avatar
ebabes ebabes is offline Offline
Junior Poster in Training

Question Re: What is the equivalent code of MessageBox in ASP.Net?

  #7  
Feb 10th, 2008
Thanks. I experience some problems again. What if let's say a user had entered an invalid value in a textbox, then a MessageBox should pop up like "Sorry, minors not allowed!". How can I do this?
Reply With Quote  
Join Date: Jan 2008
Location: istanbul
Posts: 265
Reputation: serkansendur is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 23
serkansendur's Avatar
serkansendur serkansendur is offline Offline
Posting Whiz in Training

Re: What is the equivalent code of MessageBox in ASP.Net?

  #8  
Feb 11th, 2008
try this :
<script>
function doValidation()
{
var text = document.getElementById('<%= Textbox1.ClientID %>').value;
var retVal = false;
//forexamle let say you wont allow text longer than 10 characters
if(text.length > 10)
{
alert("the text entered is not valid");
retVal = false;
}
else
{
retVal = true;
}
return retVal;
}
</script>
<asp:button runat="server" id="button1" value="validate" onclientclick="return doValidation()" />
Serkan Şendur
MCAD.NET
Reply With Quote  
Join Date: Sep 2007
Posts: 73
Reputation: ebabes is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
ebabes's Avatar
ebabes ebabes is offline Offline
Junior Poster in Training

Question Re: What is the equivalent code of MessageBox in ASP.Net?

  #9  
Feb 11th, 2008
Thanks buddy! What if my script is C#? And I wish to create class for messagebox, I wish to repeatedly call it in any part of my program?
Reply With Quote  
Join Date: Jan 2008
Location: India
Posts: 147
Reputation: sbv is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
sbv's Avatar
sbv sbv is online now Online
Junior Poster

Re: What is the equivalent code of MessageBox in ASP.Net?

  #10  
Feb 12th, 2008
Originally Posted by ebabes View Post
Thanks buddy! What if my script is C#? And I wish to create class for messagebox, I wish to repeatedly call it in any part of my program?

hi
i already provided you a code for creating a class for Message box in vb code.
you can get auto converted code from vb to c# using this link. try this...

http://labs.developerfusion.co.uk/co...arp-to-vb.aspx

Best Luck..
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 12:58 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC