Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
Hi,

Usercontrol have a button with id=hdnBtn as below,

<pre lang="asp">
&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Header.ascx.cs" Inherits="M2iSTS2.UserControl.Header" %&gt;

&lt;link href="/Styles/styles.css" rel="stylesheet" type="text/css" /&gt;
&lt;script language="javascript" type="text/javascript" src="../Script/Map.js"&gt;&lt;/script&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

     &lt;input type="button" value="Button1" id="hdnBtn" runat="server" onserverclick="assignValue"/&gt;
 &lt;div id="header" class="header"&gt;
    &lt;h1 class="h1"&gt;TrackU: Student and Vehicle Tracking System&lt;/h1&gt;
        &lt;p class="p"&gt;&lt;a class="a" href="/Account/login.aspx"  önclick='setSession()'&gt;Logout&lt;/a&gt;&lt;/p&gt;
  &lt;/div&gt;
  &lt;div&gt;
    &lt;ul class="ul"&gt;
        &lt;li class="li"&gt;&lt;a class="lia" href="/Admin/Fleet.aspx"&gt;Fleet&lt;/a&gt;&lt;/li&gt;
        &lt;li class="li"&gt;&lt;a class="lia" href="/Admin/StudentInfo.aspx"&gt;Student Info&lt;/a&gt;&lt;/li&gt;
        &lt;li class="li"&gt;&lt;a class="lia" href="/Admin/RouteSettings.aspx"&gt;Route Settings&lt;/a&gt;&lt;/li&gt;
        &lt;li class="li"&gt;&lt;a class="lia" href="/Admin/Reports.aspx"&gt;Reports&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;


</pre>

javscript function as below,

<pre lang="javscript">
function setSession() {
    alert(document.getElementById('hdnBtn'));

}
</pre>

but the <pre lang="cs">alert(document.getElementById('hdnBtn'));</pre>

giving the 'null'.why? how to get the id of button in usercontrol?

Thanks
Posted
Comments
ridoy 18-Dec-12 6:51am    
why you post same question twice?!
hasbina 18-Dec-12 7:09am    
how to delete the previous one?

run the code. then right click on your webpage.select viewsoruce, later search and see ur button with id.

document.getElementById('hdnBtn') will gives null if there is no id as 'hdnBtn'.
 
Share this answer
 
v2
Comments
hasbina 18-Dec-12 7:50am    
ya.got it.i found it...
Dear hasbina

try this one

C#

function setSession() {
alert(document.getElementById('<%=hdnBtn.ClientID%>').Tostring());

}

I hope its useful to you..

Thanks and regards

Angappan.S
 
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