什么时候添加了ctl00前缀? [英] When is the ctl00 prefix added?

查看:377
本文介绍了什么时候添加了ctl00前缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的asp.net页面,带有一个asp.net链接按钮和asp.net内容标签,它指向一个带有asp.net内容占位符和表单标签的简单asp.net母版页。以下是这两项内容的代码:

Site.Master:

 <%@ Master Language =C#AutoEventWireup =trueCodeBehind =Site.master.csInherits =WebApplication1.SiteMaster%> 

< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< title>< / title>
< / head>
< body>
< form runat =server>
< asp:ContentPlaceHolder ID =MainContentrunat =server/>
< / form>
< / body>
< / html>

Default.aspx:

 <%@ Page Title =Home PageLanguage =C#MasterPageFile =〜/ Site.masterAutoEventWireup =true
CodeBehind =Default.aspx.cs Inherits =WebApplication1._Default%>

< asp:Content ID =BodyContentrunat =serverContentPlaceHolderID =MainContent>
< asp:LinkBut​​ton ID =LinkBut​​ton1runat =server> LinkBut​​ton< / asp:LinkBut​​ton>
< / asp:Content>

由于某些原因,当我们在一台服务器上运行这个简单的Web应用程序时,链接bhutton的id为MainContent_LinkBut​​ton1
,当我们在另一台服务器上运行这个应用程序时,链接按钮得到的id是_ctl0_MainContent_LinkBut​​ton1

Doese某人有一个idia为什么我们得到前缀 ctl0 在特定的服务器和另一台服务器上我们没有得到它?

解决方案

我从 .Net 3.5 迁移到 .Net 4.0



我通过在IIS6的 web.config 中添加以下配置来解决这个问题。对于IIS7,请使用 system.webServer 部分:

 <系统名.web> 
< /system.web>


I have a simple asp.net page with an asp.net link button and asp.net content tag which point to a simple asp.net master page with an asp.net content place holder and a form tag. Here is the code of these two items:

Site.Master:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WebApplication1.SiteMaster" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <form runat="server">
            <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
    </form>
</body>
</html>

Default.aspx:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
</asp:Content>

For some reason when we run this simple web application on one server the id the link bhutton get is MainContent_LinkButton1 and when we run this application on another server the id the link button get is _ctl0_MainContent_LinkButton1

Doese someone have an idia why we get the prefix ctl0 in a specific server and in another server we don't get it?

解决方案

I had the same problem when I migrated from .Net 3.5 to .Net 4.0.

I solved it by adding the following configuration in web.config in IIS6. For IIS7, use the system.webServer section:

<system.web> 
  <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>

这篇关于什么时候添加了ctl00前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆