none
不显示删除回复显示所有回复显示星级回复显示得分回复 为啥preInit取不到s的值啊?明明已经通过构造穿了呀 RRS feed

  • 问题

  • <%@ 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">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
      <title>无标题页</title>
    </head>
    <body>
      <form id="form1" runat="server">
      <div>
      <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /><br />
      <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
      <asp:TextBox ID="txtName" runat="server" ></asp:TextBox>
      <asp:TextBox ID="txtPwd" runat="server"></asp:TextBox>
      <asp:TextBox ID="txts" runat="server"></asp:TextBox>
      <br />
      <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
      </div>
      </form>
      <%=formStr %>

    </body>
    </html>


    using System;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Text;

    public partial class _Default : System.Web.UI.Page 
    {
      protected string formStr;

      protected void Page_PreInit(object sender, EventArgs e)
      {
      if (Request.Form["s"] != null)
      {
      Page.Theme = Request.Form["s"].ToString();
      }
      }

      protected void Page_Load(object sender, EventArgs e)
      {
       

      }
      protected void Button1_Click(object sender, EventArgs e)
      {
      StringBuilder sb = new StringBuilder();
    sb.Append("<form id='tempForm' name='tempForm' action='Default.aspx' method='post' target='_blank' >");
       

      sb.Append("<input type='hidden' name='userName' value='" + txtName.Text.ToString() + "'>");
      sb.Append("<input type='hidden' name='userPwd' value='" + txtPwd.Text.ToString() + "'>");
      sb.Append("<input type='hidden' name='s' value='" + txts.Text.ToString() + "'>");
      sb.Append("</form><script>document.getElementById('tempForm').submit();</script>");

      formStr = sb.ToString();
      Response.Write(formStr);

      }
      protected void TextBox2_TextChanged(object sender, EventArgs e)
      {

      }
    }

     

    还有就是为啥 Response.Write(formStr); 在页面执行变成html,看源代码看不到tempForm呢?谢谢


    maiyude
    2010年4月4日 14:20

答案

  • PreInit
    完成操作:检查 IsPostBack 属性来确定是不是第一次处理该页;
                          
    创建或重新创建动态控件
                          
    动态设置主控页
                          
    动态设置 Theme 属性
                          
    读取或设置配置文件属性
    注:如果请求是回发请求,则控件的值尚未从视图状态恢复,即:不应该在此 事件中设置控件属性。
    2010年4月6日 4:38