This article will introduce you to ASP.net 2.0 in the creation of the master page caused by the trouble, and analyzed the essence of the problem, we in the actual operation of a lot of attention.
I. Questions raised
Because of the overall layout and design needs, we often create a master page to achieve the unity of the entire site, recently, because of the need for uniformity, the original entire project has been a separate page to apply the master page. But there was a mistake ... Record in my blog, convenient for everyone to refer to.
Second, the abstract model
Because the whole page is too much, I abstract the most essential questions in this page.
The original single page, is to use the button to trigger the JS event, in the text field insert "(_)" function, its implementation code as follows:
The following is a reference fragment:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "Default.aspx.cs" inherits= "_default"%
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<title> Single page abstract model-yjinglee</title>
<script language= "javascript" type= "Text/javascript"
//<! cdata[
Function Insert () {
document.getElementById ("TXT"). Value=document.getelementbyid ("TXT"). Value+ "(__ )";
return;
}
//]]>
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<textarea id= "TXT" runat= "server" name= "TXT" rows= "a" cols= "></TEXTAREA>
<asp:button id= "Btninsert" runat= "text=" server-side Insert (_) "onclientclick=" Insert (); " />
<input id= "BtnInsert2" name= "Insert" Onclick= insert (); "type=" button "value=" Client Insert (_) runat= "Server"/></DIV>
</form>
</body
The above page can be used normally. Later, when you use the template page, the code is as follows:
The following is a reference fragment:
<%@ Page language= "C #" masterpagefile= "~/masterpage.master" autoeventwireup= "true" codefile= "Default2.aspx.cs" inherits= "DEFAULT2" title= "use master Page abstract model-yjinglee"%>
<asp:content id= "Content1" contentplaceholderid= "ContentPlaceHolder1" runat= "Server" >
<script language= "javascript" type= "Text/javascript" >
<! cdata[
function Insert () {
document.getElementById ("TXT"). Value=document.getelementbyid ("TXT"). value+ "(__)";
Return
}
]]>
</script>
<div>
<textarea id= "TXT" runat= "server" name= "TXT" rows= "ten" cols= "></textarea>"
<asp:button id= "Btninsert" runat= "text=" server-side Insert (_) " onclientclick=" Insert (); " />
<input id= "BtnInsert2" name= insert "onclick=" Insert (); "type=" button "value=" Client Insert (_) runat= "Server"/></ Div>
</asp:Content>
"Microsoft JScript run-time Error: ' document.getElementById (...) ' is empty or not an object" when you press the button when it is turned on. What is the reason for that? Well, how do you apply a master page to this strange question? For a long time, and friends to discuss, and finally found the answer ...