Click here to Skip to main content
16,019,140 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Create alert or confirmation box in ASP.Net.
alert box if some error occurs like if text box is empty or so.

any suggestions, please help.
Posted

A good article on CP, to create a simple ASP.NET server control that functions as Message Box and Confirmation Box
A Simple ASP.NET Server Control: Message Box & Confirmation Box[^]

Another article on CP itself:
Buttons, Message Box, and Confirm Box in ASP.NET 3.5[^]
 
Share this answer
 
v2
Comments
sangel1989 30-Apr-12 7:35am    
It works thank u :)
Member 10361479 8-Nov-13 2:23am    
i want a textbox and lable in alertbox in asp.net. so how it can do?
Prasad_Kulkarni 30-Apr-12 7:37am    
Glad it helps
Thank you for 'Accepting solution'
Prasad_Kulkarni 23-May-12 9:34am    
You're welcome!
Hi,

Its very easy, assumed that you have a textbox and a button and you want to alert the user on the button click if its text is empty,

ASP.NET
<table>
       <tr>
           <td>
               <asp:textbox id="txtTest" runat="server" xmlns:asp="#unknown"></asp:textbox>
           </td>
           <td>
               <asp:button id="btnTest" runat="server" text="Click Me!!!" onclientclick="return ShowAlert();" xmlns:asp="#unknown" />
           </td>
       </tr>
   </table>


now here is the javascript function to get the alert when the textbox is empty.

JavaScript
<script type="text/javascript">
       function ShowAlert() {
           var txt = document.getElementById('txtTest').Value;
           if (txt == '') {
               alert('textbox is empty');
               //or if you want to get a confirm alert Box then
               if (confirm('Do you want ot proceed?')) {
                   alert('proceeding................');
               }
               else {
                   alert('canceled.................');
               }
           }
       }
   </script>
 
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