Click here to Skip to main content
15,921,905 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
Hi,

I want to show date in a label ...But it's not showing in label

The Code is

XML
<script type="text/javascript">
 
  function Getdate()
  {
var dt = new Date();
document.getElementById('Label1').value=dt;
  }
    </script>


and html code is

XML
<asp:Label ID="Label1" runat="server"></asp:Label>/>

<input id="Submit2" type="submit" value="Show Date" onclick="Getdate()" />
Posted

To display in Browser u have to use innerHTML property instead of value.


If U r not using master page u can do like

MIDL
document.getElementById('Label1').innerHTML=dt;


If ur using master page u can do like


C++
document.getElementById('<% =Label1.ClientID %>').innerHTML=dt;
 
Share this answer
 
Label1 is a server control so it should be
document.getElementById('<% =Label1.ClientID %>').value=dt;


EDIT
---------------------
Read Control.ClientID Property[^]
 
Share this answer
 
v3
Comments
Manfred Rudolf Bihy 23-May-11 10:05am    
Correct! My 5+
(Hi Raja! :))
thatraja 23-May-11 10:25am    
Hi Manfred, how are you? Also I couldn't see you very well in Q/A(Actually I was busy in my office so couldn't spend more time in Q/A). Yesterday I have seen Espen after long time. BTW where is Jens? He is almost inactive for 2 weeks.
sat_100m 23-May-11 10:44am    
what's the clientID ?
thatraja 23-May-11 11:01am    
Check my updated answer
Sergey Alexandrovich Kryukov 23-May-11 11:20am    
Correct, a 5. (I guess the date "dt" is found by OP.)
--SA

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