Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将参数从aspx传递给后面的用户控制代码_C#_Asp.net - Fatal编程技术网

C# 将参数从aspx传递给后面的用户控制代码

C# 将参数从aspx传递给后面的用户控制代码,c#,asp.net,C#,Asp.net,我试图将一些文本标签从db传递到中继器内的用户控件,但没有成功。它似乎没有传递我的变量 例如,请参见折扣变量 My Default.cs: public String strDiscount { get; set; } ... strDiscount = getCaptionFromDB("strDiscount"); My Default.aspx: <asp:Repeater ItemType="MyProduct" ID="ProductsGrid" runat="server"&

我试图将一些文本标签从db传递到中继器内的用户控件,但没有成功。它似乎没有传递我的变量

例如,请参见折扣变量

My Default.cs:

public String strDiscount { get; set; }
...
strDiscount = getCaptionFromDB("strDiscount");
My Default.aspx:

<asp:Repeater ItemType="MyProduct" ID="ProductsGrid" runat="server">
    <ItemTemplate>
        <uc1:productRow runat="server" Item="<%#Item%>" strDiscount="<%#strDiscount%>" />
    </ItemTemplate>
</asp:Repeater>
My ProductRow用户控件ascx.cs:

public partial class ProductRow : Product {

}
我的ProductRow用户控件ascx:

...
<%:Item.BonusGetValue%>% <%:strDiscount %>
...
。。。
% 
...
我一定是做错了什么,但我不知道是什么。
提前感谢

不要认为STRDICONT在范围内。您需要将ClassName='MyDefaultPage“属性添加到容器页面声明中。这允许您将其视为类

然后在控件中,您需要在控件代码隐藏中获得对此页面及其属性的引用

    var myDefault = (MyDefaultPage) this.Page();
    string discount = myDefault.strDiscount
    var myDefault = (MyDefaultPage) this.Page();
    string discount = myDefault.strDiscount