Click here to Skip to main content
12,403,391 members (73,256 online)
Rate this:
 
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
Updated 27-Oct-12 2:07am
v2
Comments
OriginalGriff 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 27-Oct-12 7:54am
   
nothing happend. jus form getting load thats it
DaveAuld 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 27-Oct-12 8:12am
   
when user hits submit button with out enter anything in the 'txtemailid' textbox alerts should throw
Sandeep Mewara 27-Oct-12 11:39am
   
So you say, you are not getting the 'alert' message?
Member 8015059 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 28 Oct 2012
Copyright © CodeProject, 1999-2016
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