'Button'类型的'Button1'必须放在带有runat = server的表单标签内。即使使用runat =“server”的表单内的按钮

时间:2013-04-17 18:10:55

标签: c# render

我正在获取控件'Button'类型'Button1'必须放在带有runat = server的表单标签内。即使表单内的按钮有runat =“server”。请帮助

 public string RenderControlToHtml(Control ControlToRender)
    {
        if (this.Form.Controls.Contains(ControlToRender))
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            System.IO.StringWriter stWriter = new System.IO.StringWriter(sb);
            System.Web.UI.HtmlTextWriter htmlWriter = new    System.Web.UI.HtmlTextWriter(stWriter);
            ControlToRender.RenderControl(htmlWriter);
            //ControlToRender.RenderControl(htmlWriter);
            return sb.ToString();
        }
        return string.Empty;
      }

添加标记,此控件位于runat =“server”

的表单内
<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
   <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
           <table id="Table1" runat="server">
                <tr>
                    <td>
                        <asp:Label ID="LastNameLabel" runat="server" Text="Last Name" CssClass="MemberInfolabel"></asp:Label>
                    </td>
                    <td>
                        <asp:TextBox ID="LastNameBox" runat="server" ReadOnly="true" BackColor="#EEECE1"></asp:TextBox>
                    </td>
            </tr>
                <tr>
                    <td>
                    <asp:Label ID="FirstNameLabel0" runat="server" Text="First Name" CssClass="MemberInfolabel"></asp:Label>
                    </td>
                    <td>
                    <asp:TextBox ID="FirstNameBox" runat="server" ReadOnly="true" BackColor="#EEECE1"></asp:TextBox>
                    </td>
             </tr>

              <tr>
                <td> <asp:Label ID="DOBLabel" runat="server" Text="DOB" CssClass="MemberInfolabel"></asp:Label></td>
                <td>  <asp:TextBox ID="DOBBox" runat="server" ReadOnly="true" BackColor="#EEECE1"></asp:TextBox></td>
             </tr>
             <tr>
                <td> <asp:Label ID="MEMBIDLabel" runat="server" Text="Beneficiary ID" CssClass="MemberInfolabel"></asp:Label></td>
                <td> <asp:TextBox ID="MEMBIDBox" runat="server" ReadOnly="true" BackColor="#EEECE1"></asp:TextBox> </td>
            </tr>
             <tr>
                <td>
                <asp:Label ID="PCPLabel" runat="server" Text="Aligned Provider" CssClass="MemberInfolabel"></asp:Label>
                </td>
                <td>
                <asp:TextBox ID="PCPBox" runat="server" ReadOnly="true" BackColor="#EEECE1"></asp:TextBox>

                </td>
            </tr>
             <tr>
                <td>
                    <asp:Label ID="HospLabel" runat="server" Text="Hospital" CssClass="MemberInfolabel"></asp:Label>
                </td>
            </tr>
            </table>
    </form>
</body>
</html>

0 个答案:

没有答案