I want to access the aSubchapter
in the JavaScript file, what should I have to do?(this page is content page)
in .aspx.cs file
protected void page_load()
{
HtmlGenericControl aSubchapter=new HtmlGenericControl("a");
aSubchapter.Attributes.Add("href","somevalue");
aSubchapter.ID="subchapter";
}
in .aspx file
<script type="text/javascript">
var subchap=document.getElementById('<%=subchapter.ClientID%>');
//(The above lines says that subchap is undefined)
</script>
Since you created the control in the code behind you need to add it to the page. It will not be visible until you add it to some control.
Generally, you define a control in .aspx file and add the controls as child from code behind.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.