Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
<script type="text/javascript">
    var Email = document.getElementById('<%=txtemailid.ClientID %>').value;
    function empty()
    {
    if(Email=="")
    {
    alert("Your email address seems incorrect. Please try again.");
       return false;
    }
    }
 </script>
 
<asp:Button ID="submit" runat="server" Text="Submit" OnClientClick="return empty();" onclick="submit_Click" />
 
[Edit]Code block added[/Edit]
Posted 27-Oct-12 1:29am
Edited 27-Oct-12 2:07am
ProgramFOX120.7K
v2
Comments
OriginalGriff at 27-Oct-12 7:42am
   
So what is happening that shouldn't, or isn't happening that should?
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Umapathi K at 27-Oct-12 7:54am
   
nothing happend. jus form getting load thats it
DaveAuld at 27-Oct-12 8:09am
   
What Griff means is, what are you expecting to happen, what are you trying to do that makes you think something is not working! Expand on the details please.
Umapathi K at 27-Oct-12 8:12am
   
when user hits submit button with out enter anything in the 'txtemailid' textbox alerts should throw
Sandeep Mewara at 27-Oct-12 11:39am
   
So you say, you are not getting the 'alert' message?
Member 8015059 at 29-Oct-12 1:15am
   
Have u tried solution 2 , as it is working fine.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Read the following on how to use the getElementById function :http://www.tizag.com/javascriptT/javascript-getelementbyid.php[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi Umapathi K,
 
just copy and paste the below code and it will work.
<script type="text/javascript">
   
    function empty()
    {
 var Email = document.getElementById('<%=txtemailid.ClientID %>').value;
    if(Email=="")
    {
    alert("Your email address seems incorrect. Please try again.");
       return false;
    }
    }
 </script>
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 363
1 Sergey Alexandrovich Kryukov 286
2 RyanDev 75
3 nv3 60
4 PhilLenoir 60
0 Sergey Alexandrovich Kryukov 6,691
1 OriginalGriff 6,119
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 28 Oct 2012
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