服务器呈现控制为HTML代码隐藏不起作用

时间:2018-03-19 09:14:26

标签: c# asp.net

我正在将ASP.NET服务器端按钮呈现为HTML,除了函数后面的代码不起作用外,它工作正常:

Button LoadStudents = new Button();
                LoadStudents.ID = "cl" + i.ToString();
                LoadStudents.CssClass = "btn btn-info";
                LoadStudents.Text = "Student List";
                LoadStudents.Attributes.Add("ClassroomID", StringCipher.Base64Encode(o.ClassroomID.ToString()));
                LoadStudents.Click += LoadStudents_Click;
                var LoadStudentsHTML = new BaseHTML().RenderControlToHtml(LoadStudents);

                sb.AppendLine("<tr>");
                sb.AppendLine("<td>");
                sb.AppendLine(o.ClassroomName);
                sb.AppendLine("</td>");
                sb.AppendLine("<td>");
                sb.AppendLine(o.ClassroomDecription);
                sb.AppendLine("</td>");
                sb.AppendLine("<td>");
                sb.AppendLine("");
                sb.AppendLine("</td>");
                sb.AppendLine("<td>");
                //sb.AppendLine("<input type=\"button\" class=\btn btn-info\" value=\"Student list\">");
                sb.AppendLine(LoadStudentsHTML);
                sb.AppendLine("</td>");
                sb.AppendLine("</tr>");

功能背后的代码

private void LoadStudents_Click(object sender, EventArgs e)
        {
            Button thisButton = (Button)sender;
            var classroomid = thisButton.Attributes["ClassroomID"].ToString();
        }

RenderControlToHTML方法

        public string RenderControlToHtml(Control ControlToRender)
    {
        StringBuilder sb = new StringBuilder();
        StringWriter stWriter = new StringWriter(sb);
        HtmlTextWriter htmlWriter = new HtmlTextWriter(stWriter);
        ControlToRender.RenderControl(htmlWriter);
        return sb.ToString();
    }

任何指针都是最有用的。

0 个答案:

没有答案