开发者

Get property Null Reference Exception

开发者 https://www.devze.com 2023-01-23 16:11 出处:网络
I am sending CurrentPage value 1, but it gives a null reference exception in set. lblCurrentPage is a label control. CurrentPage is one variable.

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

精彩评论

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