Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
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
Comments
I.explore.code 16-Oct-12 5:35am    
Use JavaScript for client side validation and alert() JS method to show a message box.
MONU MITTAL 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

alert message validation through Simple Javascript

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


Thanks
 
Share this answer
 
Comments
Manas Bhardwaj 24-Oct-12 4:57am    
+5!
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
 
Share this answer
 
Comments
zaid Qureshi 16-Oct-12 5:24am    
I want to use without Validators.
MT_ 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 16-Oct-12 6:24am    
but how ...can u plz help me with that
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>
 
Share this answer
 
Comments
Manas Bhardwaj 24-Oct-12 4:57am    
+5!
In Asp.net,Just do the following code in Button click Event,,


C#
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);

 }
 
Share this answer
 
v2
C#
if(TextBox.text=="")
{
MessageBox.Show(" please enter value");

}
 
Share this answer
 
Comments
zaid Qureshi 16-Oct-12 5:46am    
its working on Windows based Application but Not on Web Pages
narutoluffy01 18-Oct-12 7:36am    
you have to add namespace System.Window.Forms
add System.Windows.Forms in the namespace


and

C#
if(textBox.text=="")
{
MessageBox.Show(".......");
}
 
Share this answer
 
v2
Comments
zaid Qureshi 16-Oct-12 5:24am    
its not on Windows Its on Web
I.explore.code 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 20-Aug-14 10:49am    
Why add System.Windows.Forms namespace? When it is not a Windows application, it is a Web based application.
I think this is exactly what you need:

A Windows Form like MessageBox for ASP.NET Website[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900