Aspx页给Ascx页传值
<uc1:WebPageAds id="WebPageAds1" adsType="要传的值" runat="server"></uc1:WebPageAds>
代码:

public class WebPageAds : System.Web.UI.UserControl
{
private string _adsType;

private void Page_Load(object sender, System.EventArgs e){
// 在此处放置用户代码以初始化页面
switch(_adsType){
case("leftMenu"):
Response.Write("<iframe scrolling='no' frameborder='0' width='160' height='350' src='http://202.107.245.55:6888/advcode/advring/160350a.htm?u=10761'></iframe>");
break;
case("photoView"):
Response.Write("图片浏览");
break;
}
}

Web 窗体设计器生成的代码

public string setWebAds {
set{
_adsType = value;
}
}
}


您的属性定义错误,应当为:
public string adsType{
set{
_adsType = value;
}
}
代码:

public class WebPageAds : System.Web.UI.UserControl
{
private string _adsType; 
private void Page_Load(object sender, System.EventArgs e){
// 在此处放置用户代码以初始化页面
switch(_adsType){
case("leftMenu"):
Response.Write("<iframe scrolling='no' frameborder='0' width='160' height='350' src='http://202.107.245.55:6888/advcode/advring/160350a.htm?u=10761'></iframe>");
break;
case("photoView"):
Response.Write("图片浏览");
break;
}
} 
Web 窗体设计器生成的代码 
public string setWebAds {
set{
_adsType = value;
}
}
} 

您的属性定义错误,应当为:
public string adsType{
set{
_adsType = value;
}
}



浙公网安备 33010602011771号