简体   繁体   English

无法读取ASP用户控制参数

[英]Can't read asp user control parameters

I'm driving myself nuts with this particular problem, i really hope someone can help! 对于这个特殊的问题,我真是疯了,我真的希望有人能提供帮助! In the below example i cant get the value of "4" to appear in the rendered page. 在下面的示例中,我无法获取值“ 4”出现在呈现的页面中。 The output from below compiles and executes just fine but all three of the values shown are "0". 下面的输出编译并执行得很好,但是显示的所有三个值均为“ 0”。

Here's a short snippet: 这是一个简短的片段:
(hopefully I'm formatting this correctly) (希望我格式化正确)

(from default.aspx) (来自default.aspx)

<%@ Register Src="Modules/StarRating.ascx" TagName="StarRating" TagPrefix="mytag" %>

(from StarRating.ascx) (来自StarRating.ascx)

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="StarRating.ascx.cs" Inherits="StarRating" %>  
<h1>RATING: <%=OverallRating%></h1>

(from StarRating.ascx.cs) (来自StarRating.ascx.cs)

public partial class StarRating : System.Web.UI.UserControl  
{  
    private int _OverallRating;  
    public string OverallRating  
    {  
        get { return _OverallRating.ToString(); }  
        set { _OverallRating = int.Parse(this.OverallRating); }  
    }

    protected void Page_Load(object sender, EventArgs e)  
    {  
        Response.Write("RATING (from behind code!): " + OverallRating);  
        Response.Write("<BR />RATING (another one): " + _OverallRating);  
    }  
}  

In your OverallRating set accessor, you're parsing the current value of the underlying integer variable instead of the value being passed to the property. 在您的OverallRating集合访问器中,您正在解析基础整数变量的当前值,而不是传递给属性的值。 This should fix it: 这应该解决它:

public string OverallRating  
{  
    get { return _OverallRating.ToString(); }  
    set { _OverallRating = int.Parse(value); }
}

(Presuming that wasn't just a typo) (假设这不仅仅是错字)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM