可视Web部件中的自定义属性值始终读取为Null [英] Custom property value in visual web part reading as Null all times

查看:76
本文介绍了可视Web部件中的自定义属性值始终读取为Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为可视化Web部件创建了自定义属性,如下所示.但是,当尝试从用户控制代码中读取字符串时,该字符串始终显示为空.

I created custom property for visual web part as below. But while trying to read the string in user control code behind its always showing null.

Webpart.cs:

  [类别(扩展设置"),
      个性化(PersonalizationScope.Shared),
       WebBrowsable(true),
       WebDisplayName(测试字符串"),
       WebDescription(请输入值")]
      公共字符串_string
       {
          得到;
          设置;
       }
    从用户控制代码后面读取值,如下所示:

 [Category("Extended Settings"),
        Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Test string"),
        WebDescription("Please Enter a value")]
        public string _string
        {
            get;
            set;
        }
      Reading value from user control code behind as below:

   WebpartUserControl.ascx.cs:

   WebpartUserControl.ascx.cs:

this ..WebPart !=

if(this.WebPart != null&& this.WebPart._string != null&& this.WebPart._string.Length > 0)

               {

                {

              lblTest.Text =

                    lblTest.Text =

this.WebPart._string;

               }

                }

感谢&此致克里希纳

Thanks & Regards, Krishna

推荐答案

您必须设置属性值

公共字符串stringValue =默认值";

public string stringValue = "default value";

[类别(扩展设置"),
;   Personalizable(PersonalizationScope.Shared),
;   WebBrowsable(true),
;   WebDisplayName(测试字符串"),
;   WebDescription(请输入值"))
;  公共字符串_string
;   {
;     得到{return stringValue;}
;     设置{stringValue =(value == string.Empty)? stringValue:值; }

[Category("Extended Settings"),
        Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Test string"),
        WebDescription("Please Enter a value")]
        public string _string
        {
            get {return stringValue;}
            set { stringValue = (value == string.Empty) ? stringValue : value;}

    }


这篇关于可视Web部件中的自定义属性值始终读取为Null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆