日期:2014-05-20  浏览次数:20568 次

请教关于用户控件传值到aspx页
网站首页index.aspx右边有个产品搜索功能的用户控件.right.ascx   内有Dropdownlist1和TextBox1.   想实现点搜索后在产品页显示搜索结果.   要用Server.Transfer( "products.aspx ")  

请教各路英雄,应该怎么实现?     get也设了     就是不知道怎么在产品页中取得用户控件中的值.     请帮帮我.   谢谢!!!!!

------解决方案--------------------
汗,还没有搞定?我给你一个例子吧,一共四个文件,你拷贝到VS中编译一下:
my.ascx:
<%@ Control Language= "c# " AutoEventWireup= "false " Codebehind= "my.ascx.cs " Inherits= "test.my " TargetSchema= "http://schemas.microsoft.com/intellisense/ie5 "%>
<asp:TextBox id= "TextBox1 " runat= "server "> a4w </asp:TextBox>

my.ascx.cs:
namespace test
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// my 的摘要说明。
/// </summary>
public class my : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox TextBox1;

public string Retu1{
get{
return this.TextBox1.Text;
}
set{
this.TextBox1.Text = value;
}
}

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面

}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

webform1.aspx:
<%@ Page language= "c# " Codebehind= "WebForm1.aspx.cs " AutoEventWireup= "false " Inherits= "test.WebForm1 " %>
<%@ Register TagName= "abc " TagPrefix= "my " src= "my.ascx " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN " >
<HTML>
<HEAD>
<title> WebForm1 </title>
<meta name= "GENERATOR " Content= "Microsoft Visual Studio .NET 7.1 ">
<meta name= "CODE_LANGUAGE " Content= "C# ">
<meta name= "vs_defaultClientScript " content= "JavaScript ">
<meta name= "vs_targetSchema " content= "http://schemas.microsoft.com/intellisense/ie5 ">
</HEAD>
<body>
<form id= "Form1 " method= "post " runat= "server ">
<my:abc id= "myAscx " runat= "server " /> <FONT face= "宋体 "> <BR>
</FONT>
<asp:Button id= "Button1 " runat= "server " Text= "Button "> </asp:Button>
</form>
</body>
</HTML>

webform1.aspx.cs:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ICSharpCode.SharpZipLib.BZip2;

namespace test
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page