简体   繁体   English

将客户端ID从gridview内传递给javascript函数

[英]pass client id from within the gridview to javascript function

I have a gridview that get binds dynamically. 我有一个动态获取绑定一个gridview。 i have a linkbutton attached with every row that opens a modal popup window which I need to show some text which is in a hidden field in gridview. 我每行都附带一个链接按钮,用于打开模式弹出窗口,我需要显示网格视图中隐藏字段中的一些文本。

I need to call a javascript function that sets the value of the label in the popup panel with the text of the hidden field. 我需要调用一个javascript函数,该函数使用隐藏字段的文本在弹出面板中设置标签的值。 The problem is that the value is always blank when the popup is displayed. 问题是显示弹出窗口时,该值始终为空白。

Java script code is - Java脚本代码是-

  function SetNotesonModal(note)
   {
        //debugger;
        var notes = document.getElementById(note.id).innerHTML;
        document.getElementById('ctl00_ContentPlaceHolder1_popupLblNote').value = notes;
   }

Code for calling the function is - 调用该函数的代码是-

lnkViewNotes.Attributes.Add("OnClick", "return SetNotesonModal(" + e.Row.FindControl("lblNote").ClientID + ");");

The controls in gridview are as - gridview中的控件为-

<ItemTemplate>
     <asp:Label ID="lblNote" runat="server" Text='<%# Bind("notes") %>'></asp:Label>
     <asp:LinkButton ID="lnkViewNotes" runat="server">View</asp:LinkButton>
     <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="lnkViewNotes" PopupControlID="Panel2" CancelControlID="popupBtnClose">
     </asp:ModalPopupExtender>
</ItemTemplate>

And the panel for popup is - 弹出面板是-

<asp:Panel ID="Panel2" runat="server" ScrollBars="Auto" align="center" Style="display: none"
    CssClass="modalPopup">
    <table class="border" style="text-align: left; height: 100%" width="100%">
        <tr align="left" style="background-color: #5D7B9D; color: White">
            <th>
                Notes
            </th>
        </tr>
        <tr>
            <td>
                <asp:Label ID="popupLblNote" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="popupBtnClose" runat="server" Text="Close" />
            </td>
        </tr>
    </table>
</asp:Panel>

The javascript function is being called perfectly and its is also setting value of the label in popup panel correctly but not sure why the popup comes blank every time. javascript函数被完美调用,并且它还在弹出面板中正确设置了标签的值,但不确定每次弹出时为何空白。

Any kind of help is welcome. 欢迎任何帮助。

Thanks 谢谢

For every linkbutton or button that should not trigger post back You should try adding: 对于每个不应触发回发的链接按钮或按钮,您应尝试添加:

OnClientClick="return false;"

Also take a look at postback with jquery 还可以看一下jquery的回发

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

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