Click here to Skip to main content
16,018,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Usercontrol have a button with id=hdnBtn as below,

ASP
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Header.ascx.cs" Inherits="M2iSTS2.UserControl.Header" %>

<link href="/Styles/styles.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="../Script/Map.js"></script>   

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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


javscript function as below,

javscript
function setSession() {
    alert(document.getElementById('hdnBtn'));

}


but the
C#
alert(document.getElementById('hdnBtn'));


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

Thanks
Posted
Updated 18-Dec-12 0:34am
v2

C#
<input id="hdnBtn" type="button" value="Button1" name="hdnBtn1" runat="server" onserverclick="assignValue" />

use this line instead ofthis

C#
<input type="button" value="Button1" name="hdnBtn1" runat="server" onserverclick="assignValue" />


I think this may help you..
 
Share this answer
 
Comments
hasbina 18-Dec-12 6:35am    
sorry, i forgot to change that thing.by providing id, getting null value
C#
<input type="button" value="Button1" name="hdnBtn1" runat="server" onserverclick="assignValue"/>


Where is the id to this input element

[Code block edited]
 
Share this answer
 
v2
Comments
hasbina 18-Dec-12 6:35am    
sorry, i forgot to change that thing.by providing id, getting null value

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