如何在 ASPTokenInput 上预填充一些标签

发布于 2025-01-07 17:30:06 字数 201 浏览 1 评论 0原文

您好,我正在使用 ASPTokenInput 库,从下面的 url 中找到 https://github.com/harindaka/ASPTokenInput/wiki 任何人都可以帮助我如何在页面加载和部分回发时预填充一些令牌控件

Hi I am using ASPTokenInput library find from below url
https://github.com/harindaka/ASPTokenInput/wiki
Can any one please help me how can I pre populate some token control on page load and on partial postback

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

老街孤人 2025-01-14 17:30:06

必须对代码进行一些调整,看起来这个功能没有在原始代码中得到充分测试。我尝试将项目添加到“项目”中,它们会在页面加载时显示,但如果我添加新项目,它们会立即消失,因为它们没有存储在隐藏字段中。

代码修改后,您可以执行以下操作,其中 tiTest2 是 ASPTokenInput 控件(抱歉,没有 tiTest2.Items.Add 支持):

            List<ASPTokenInput.Item> items = new List<ASPTokenInput.Item>();
            items.Add(new ASPTokenInputLib.ASPTokenInput.Item() { id = "United States", name = "United States" });
            items.Add(new ASPTokenInputLib.ASPTokenInput.Item() { id = "Brazil", name = "Brazil" });


            tiTest2.Items = items;

您需要按如下方式更改代码:

   //Change the Items property to the following
   public List<Item> Items
    {
        get
        {
            this.EnsureChildControls();
            if (String.IsNullOrEmpty(_hfPersist.Value)) return new List<Item>();

            else return (List<Item>)new JavaScriptSerializer().Deserialize<IList<Item>>(_hfPersist.Value);
        }
        set
        {
            this.EnsureChildControls();
            _hfPersist.Value = new JavaScriptSerializer().Serialize(value); 
        }
    }

  //Empty out "OnLoad", so it looks like this.  The functionality it was providing we don't need anymore
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

    }

Had to tweak the code a bit, it looks like this feature wasn't fully tested in the original code. I tried just adding items to "Items" and they showed up on page load, but would disappear immediately if I added a new item because they were not being stored in the hidden field.

After the code modifications you can do the following, where tiTest2 is an ASPTokenInput control (sorry, no tiTest2.Items.Add support):

            List<ASPTokenInput.Item> items = new List<ASPTokenInput.Item>();
            items.Add(new ASPTokenInputLib.ASPTokenInput.Item() { id = "United States", name = "United States" });
            items.Add(new ASPTokenInputLib.ASPTokenInput.Item() { id = "Brazil", name = "Brazil" });


            tiTest2.Items = items;

You'll need to change the code as follows:

   //Change the Items property to the following
   public List<Item> Items
    {
        get
        {
            this.EnsureChildControls();
            if (String.IsNullOrEmpty(_hfPersist.Value)) return new List<Item>();

            else return (List<Item>)new JavaScriptSerializer().Deserialize<IList<Item>>(_hfPersist.Value);
        }
        set
        {
            this.EnsureChildControls();
            _hfPersist.Value = new JavaScriptSerializer().Serialize(value); 
        }
    }

  //Empty out "OnLoad", so it looks like this.  The functionality it was providing we don't need anymore
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文