向用户控件中传递参数的问题
一个用户控件页:indexNav.ascx
其indexNav.ascx.cs部分代码如下:
public string adClassID = "";protected void Page_Load(object sender, EventArgs e){ if (!Page.IsPostBack) { Response.Write(adClassID + "--"); }}
<%@ Register TagPrefix="jav" TagName="indexNav" src="userControl/indexNav.ascx" %>.....<jav:indexNav id="UC_indexNav8" adClassID="<%#class_forumid1%>" runat="server"></jav:indexNav>
public string class_forumid1 = "0";protected void Page_Load(object sender, EventArgs e){ if (!Page.IsPostBack) { class_forumid1="10"; }}
<%@ Register TagPrefix="jav" TagName="indexNav" src="userControl/indexNav.ascx" %>.....<jav:indexNav id="UC_indexNav8" adClassID="<%#class_forumid1%>" runat="server"></jav:indexNav>
[解决办法]
上面第一段C#改为
if (!Page.IsPostBack) { class_forumid1="10"; UC_indexNav8.DataBind();//这样结果就显示adClassID="10" }