开发者

Get property Null Reference Exception

I am sending CurrentPage value 1, but it gives a null reference exception in set.

lblCurrentPage is a label control. CurrentPage is one variable.

public int CurrentPage
{

    get { return int.P开发者_C百科arse(lblCurrentPage.Text); }
    set {
             lblCurrentPage.Text = Convert.ToString(value);
        }
}


You have a massive lack of info for us to go on, but i'll make a suggestion. Check that lblCurrentPage is actually set to a real control, i.e. make sure the label has been instantiated before you try to set its properties.

public int CurrentPage 
{
    get 
    { 
        int temp = 0;
        if (lblCurrentPage != null) 
        {
            int.TryParse(lblCurrentPage.Text, out temp);
        }
        return temp;
    }
    set 
    {
        if (lblCurrentPage != null)
            lblCurrentPage.Text = Convert.ToString(value);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜