2012-02-27 87 views
1

的内容下面是我希望能够找到控制ID为“exampleID”,并使用C#写的东西进去我的Default.aspx编辑ASP.NET控件

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> 
    <h2> 
     WELCOME  
    </h2> 
    <p id="exampleId"> 
     I want to edit here 
    </p> 

</asp:Content> 

的内容。

+2

将它变成一个'runat =“服务器”'控件。 – Oded 2012-02-27 13:25:31

+0

使用asp.net提供的控件之一怎么样?像''可以通过exampleId.Text =“Hello,World!”来访问;' – aweis 2012-02-27 13:28:14

+0

请不要在标题中包含C#标签,将其标记为C#谢谢! – 2012-02-27 13:52:42

回答

4

runat =“server”在标签中缺失以从后面的代码访问它。

HTML

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> 
    <h2> 
     WELCOME  
    </h2> 
    <p id="exampleId" runat = "server"> 
     I want to edit here 
    </p> 

</asp:Content> 

C#代码

exampleId.InnerText = "Your text"; 
1

你几个选择这里:

  1. 添加RUNAT =“服务器”
  2. 添加asp.net服务器端控件“文本”内部p

    <p> 
        <asp:Literal ID="exampleId" runat="server" /> 
    </p> 
    

    不要使用标签为,因为这将额外SPAN渲染,你不要不想要。

希望它有帮助。