我使用的是VS.NET 2005,C#,我无法在第二个页面上使用第一个页面的控件参数。譬如在第一个页面search1上我定义了一个RadioButtonList1,想将它传递到第二个页面search2上,我是这么写的:search1页面:<html>
  <body>
    <form id="form1" method="post" action="search2.aspx" runat="server">       <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" DataSourceID  ="对机组类型表的绑定" DataValueField="机组类型" Style="position: static" Width="132px" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
        </asp:RadioButtonList>     </form>
  </body>
</html>search2页面的cs代码(在此页面定义了一个label5):public partial class search2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        label5 = string.Format(search1.RadioButtonList1.SelectedValue);
    }
}但是在编译时说是无法找到search1,是不是单纯地用form提交这种方法不可行,请问我该怎么调用它呀?

解决方案 »

  1.   

    try:search2页面的cs代码(在此页面定义了一个label5):public partial class search2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            label5.Text = string.Format(Request["RadioButtonList1"]);
        }
    }
      

  2.   

    第一个页面
    <asp:TextBox ID="TextBox1" runat="server">hi</asp:TextBox>
    <asp:Button ID="Button1" runat="server" PostBackUrl="WelcomeWorld.aspx" Text="Button" />第2个页面 WelcomeWorld.aspx:
    if (Page.PreviousPage != null)
            {
                this.Label1.Text = "hello <br>" + ((TextBox)Page.PreviousPage.FindControl("TextBox1")).Text;
            }
     则读到 第一个页面 的 ID="TextBox1" 的 值
      

  3.   


    a.html<script>
    var a;
    </script>
    <a href="b.html" target="_blank">a</a>
    <div id=test></div>b.html
    <script>
    function setvalue(){
    window.opener.document.a="b"//该值可改为由数据库获得
    window.opener.document.getElementById("test").innerHTML="由数据库获得"
    }
    </script>
    <body>
    <input onclick=setvalue() type=button>
    </body>
      

  4.   

    可以使用asp.net 2.0的跨页提交功能,你的代码修改如下:search1页面:<html>
      <body>
        <form id="form1" method="post" runat="server">       <asp:RadioButtonList ID="RadioButtonList1" runat="server" DataSourceID  ="对机组类型表的绑定" DataValueField="机组类型" Style="position: static" Width="132px" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
            </asp:RadioButtonList>       <asp:button id="button1" runat="server" postbackurl="searc2.aspx" text="submit"/>
         </form>
      </body>
    </html>search2页面的cs代码(在此页面定义了一个label5):public partial class search2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RadioButtonList ctl = this.PreviousPage.FindControl("RadioButtonList1") as RadioButtonList;
            if (ctl != null) label5.Text = ctl.SelectedValue;
        }
    }
      

  5.   

    Web是无状态的,不能像WinForm一样在两个窗体之间共享数据。也可以用URL参数传递或者使用隐藏表单域等。
      

  6.   

    楼主,你用的2005,那它是可以实现跨页面提交的。
    第一个页面
    <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" DataSourceID  ="对机组类型表的绑定" DataValueField="机组类型" Style="position: static" Width="132px" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
    </asp:RadioButtonList>
    <asp:Button ID="Button1" runat="server" PostBackUrl="WelcomeWorld.aspx" Text="Button" />search2页面的cs代码(在此页面定义了一个label5):public partial class search2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            label5.Text = string.Format(Request["RadioButtonList1"]);
        }
    }