aspx 页面与ascx用户控件传值的问题

//****ascx用户控件中,定义一个要接收参数的属性
public partial class front_search : System.Web.UI.UserControl
{
    private int m_nFirstSortID; // 一级分类的ID,用于aspx传值进来
    public int FirstSortID
    {
        get { return m_nFirstSortID; }
        set { m_nFirstSortID = value; }
    }

    private int m_nSecondSortID; // 二级分类的ID
    public int SecondSortID
    {
        get { return m_nSecondSortID; }
        set { m_nSecondSortID = value; }
    }

}

 

// aspx页面,定义ascx的地方

<%@ Register TagPrefix="MySearch" TagName="Search" Src="~/front_search.ascx" %>

<td align="left">
 <MySearch:Search runat="server" ID="Search1" />
</td>

 

// 进行传值

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int nFirstSortID = RequestUtil.GetInt(Request, "first_sort_id", 0);
            int nSecondSortID = RequestUtil.GetInt(Request, "second_sort_id", 0);

            Search1.FirstSortID = nFirstSortID;
            Search1.SecondSortID = nSecondSortID;
        }
    }

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页