ASP.net 2.0 Create a master page trouble

Source: Internet
Author: User
Tags abstract cdata

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.