Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
Dear All,
 
I am new To programming,
 

I need some help for;
 

How to add message Box or Showing an Alert To the user.
 
example:
 

if the textBox is blank, the Alert message Should come or Some Message Box should come.i.e Please Fill the TextBox.
 

Please Help me For the Same...
Posted 16-Oct-12 0:16am
Comments
Aman.A at 16-Oct-12 5:35am
   
Use JavaScript for client side validation and alert() JS method to show a message box.
MONU MITTAL at 21-Aug-14 0:46am
   
you can also use some validation control.
where there is a property name control to validate.
by this u can alert about blank textbox
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

In Asp.net,Just do the following code in Button click Event,,
 

       if (textbox1.Text !="")
        {
        
                     ScriptManager.RegisterClientScriptBlock(Page,typeof(Page),"ClientScript","alert('hello')",true);
 
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(Page,typeof(Page),"ClientScript","alert('Plz fill  the textbox')",true);
 
        }
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

alert message validation through Simple Javascript
 
 
function validation()
{
if(TextName.text=="")
{
   alert(" please enter Name");
   return false;
}
return true;
}

 
Thanks
  Permalink  
Comments
Manas Bhardwaj at 24-Oct-12 4:57am
   
+5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Most of the time, for such validations of controls, you should be using validators.
 
There are six types of validators to serve various purposes ranging from simple required field to complex custom validations.
 
Please check at links below.
 
http://msdn.microsoft.com/en-us/library/debza5t0(v=vs.100).aspx[^]
 
www.w3schools.com/aspnet/aspnet_refvalidationcontrols.asp[^]
 
After that if you have questions, you are always welcome here to ask specific questions.
 
Thanks
Milind
  Permalink  
Comments
zaid Qureshi at 16-Oct-12 5:24am
   
I want to use without Validators.
Milind Thakkar at 16-Oct-12 5:47am
   
Try using simple javascript alert("Please enter value"); using jquery or javascript to check if the textbox is empty
zaid Qureshi at 16-Oct-12 6:24am
   
but how ...can u plz help me with that
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Try this.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript">
        function fnValidate() {
            if (document.getElementById("TextBox1").value == '') {
                alert('Textbox can not be empty.')
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox>
        <asp:button id="Button1" runat="server" text="Button" onclientclick="fnValidate()" xmlns:asp="#unknown" />
    </div>
    </form>
</body>
</html></html>
  Permalink  
Comments
Manas Bhardwaj at 24-Oct-12 4:57am
   
+5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

if(TextBox.text=="")
{
MessageBox.Show(" please enter value");
 
}
  Permalink  
Comments
zaid Qureshi at 16-Oct-12 5:46am
   
its working on Windows based Application but Not on Web Pages
narutoluffy01 at 18-Oct-12 7:36am
   
you have to add namespace System.Window.Forms
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

add System.Windows.Forms in the namespace
 

and
 
if(textBox.text=="")
{
MessageBox.Show(".......");
}
  Permalink  
v2
Comments
zaid Qureshi at 16-Oct-12 5:24am
   
its not on Windows Its on Web
Aman.A at 16-Oct-12 5:33am
   
This will give this error at runtime: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application. You cannot get the MessageBox to display on the client side like that.
Afzaal Ahmad Zeeshan at 20-Aug-14 10:49am
   
Why add System.Windows.Forms namespace? When it is not a Windows application, it is a Web based application.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

I think this is exactly what you need:
 
A Windows Form like MessageBox for ASP.NET Website[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 20 Aug 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100