简体   繁体   English

设置标签客户端的值

[英]Setting Value of Label Client Side

I have a web page that has a Folder Picker pop up. 我有一个弹出文件夹选择器的网页。 It allows the user the select a folder on the website, and then track changes to its contents. 它允许用户选择网站上的文件夹,然后跟踪其内容的更改。

I need to pass the value from the pop-up, which is returned to me in JavaScript, and pass that to a server side method. 我需要传递弹出窗口中的值,该弹出窗口在JavaScript中返回给我,并将其传递给服务器端方法。

AJAX is not available for this, as I'm working with SharePoint. 由于我正在使用SharePoint,因此无法使用AJAX。

I get the data I need from a callback in JavaScript, but if I try to set $(control).text(), this doesn't work. 我从JavaScript中的回调中获取了所需的数据,但是如果我尝试设置$(control).text(),则这不起作用。

Can I set the value of a label (rendered as a span) somehow and pass that back onClick? 我可以以某种方式设置标签的值(呈现为跨度)并将其传递回onClick吗?

Current working Code: 目前的工作代码:

$('.tile').on("click", ".LibraryPickerInitiator", function () {
    var hiddenField = $(this).siblings('[type=hidden]');
    var callback = $.proxy(function (s) { this.val(s); }, hiddenField);
    LaunchPickerTreeDialog('CbqPickerSelectListTitle', 'CbqPickerSelectListText', 'websLists', '', '/', '', '', '', '/_layouts/images/smt_icon.gif', '', callback, '', '');
});

Markup: 标记:

<div id="WebSettings" class="WebSettings" runat="server">
    <div class="LibraryPickerInitiator">Pick a Library</div>
    <asp:HiddenField ID="HiddenField1" runat="server" />
    <asp:Label ID="TreePickerLabel" CssClass="PickerPlaceHolder" runat="server" Text="No List Selected"></asp:Label>
    <asp:Button ID="SubmitList" runat="server" Text="Get List Data" onclick="SubmitList_Click" />
</div>

Event: 事件:

protected void SubmitList_Click(object sender, EventArgs e)
{
    string pickerData = HiddenField1.Value;
}

I see no reason you cannot, I would use $.proxy when creating the callback to ensure a proper scope: 我认为没有理由你不能,我会在创建回调时使用$.proxy以确保适当的范围:

var callback = $.proxy(function (s) {
    this.html(s); 
}, sisterLabel);

If you add a hidden input to the markup you could change you client code something like this: 如果向标记添加隐藏输入,则可以更改客户端代码,如下所示:

var sibs = $(this).siblings();

var callback = $.proxy(function (s) {
    this.label.html(s); // set label text
    this.hidden.val(s); // set hidden field val
}, { label: sibs.filter('span'), hidden: sibs.filter(':input:hidden') });

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

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