点击模态框时,按钮没有被触发

mrj*_*_05 5 javascript asp.net jquery modal-dialog

[ Assign a Textbox Value to the modal-box on the same page已被回答]

新问题: 当我点击按钮时,为什么模态框上的按钮没有被触发?我错过了什么吗?

我添加了代码来处理服务器端的click事件:

Protected Sub Save_Button_Click(sender As Object, e As System.EventArgs) Handles Save_Button.Click
    //The code goes here
End Sub
Run Code Online (Sandbox Code Playgroud)

请使用标记的行查看下面的代码.


我在下面的代码中显示了点击LinkBut​​ton后的模态框.而且,我想要做的是如何分配文本框值.

我有一个gridview:

<asp:GridView ID="GV1" runat="server" DataSourceID="DS1" >
  <Columns>
    <asp:BoundField HeaderText="ID" DataField="ID"/>
    <asp:TemplateField ShowHeader="False">
      <ItemTemplate>
        <asp:LinkButton ID="Edit_Linkbutton" runat="server" CausesValidation="False" >
          <asp:Image ID="Edit_Linkbutton_Image" runat="server" ImageUrl="~/edit.png"></asp:Image>
        </asp:LinkButton>
      </ItemTemplate>
    </asp:TemplateField>
  </Columns>
</asp:GridView>
Run Code Online (Sandbox Code Playgroud)

并在同一页面上(这是一个div作为模式框,在Gridview上的Linkbutton点击后显示):

<div id="dialog-form" title="Modal Box">
    <input type="text" id="Textbox1" />

    #--------------------------------------------------------------------#
    #This button didn't get fired while clicked
    <asp:Button ID="Save_Button" runat="server" Text="Save"></asp:Button>
    #--------------------------------------------------------------------#

</div>
Run Code Online (Sandbox Code Playgroud)

然后我通过代码隐藏将一个Javascript函数附加到LinkBut​​ton:

Dim myLinkButton As LinkButton

For i As Integer = 0 To GV1.Rows.Count - 1
  myLinkButton = DirectCast(GV1.Rows(i).Cells(1).FindControl("LinkButton"), LinkButton)
  myLinkButton.Attributes.Add("onclick", "shopModalPopup('" + .Rows(i).Cells(0).Text & "'); return false;")
Next
Run Code Online (Sandbox Code Playgroud)

Rows(i).Cells(0)是Gridview上的第一列,它是" ID".

Javascript代码与Gridview代码位于同一页面上:

<script>
function shopModalPopup(id){
//show the modal-box
    $("#dialog-form").dialog("open");
    // ---> How to assign the 'id' value to the Textbox1 on the modalbox?
} 

$(function () {
    $("#dialog-form").dialog({
        autoOpen: false,
        height: 300,
        width: 350,
        modal: true
    });
});
</script>
Run Code Online (Sandbox Code Playgroud)

上面的代码打开模态框,但没有将值分配给模态框上的Textbox1.

我要问的是如何将Id值分配给Textbox1模态框?我试图搜索任何相关的文章,但他们确实将模态框分开到另一页.但在这种情况下,模态框与点击链接按钮位于同一页面上.我怎样才能做到这一点?非常感谢你.

Luc*_*ofi 1

未经测试但应该可以工作。

我认为你也可以避免使用内联js,只绑定buttonLink的点击事件

#dialog-form { display:none } /* CSS */

<script>  /* JS */
/* Assuming all dialogs share the same default Settings in this grid scenario */
var grid_modal_options = {
        height: 300,
        width: 350,
        modal: true
};
function shopModalPopup(id){
    var DataField = id;
    grid_modal_options.open = function(){
        $('#dialog-form #Textbox1').val( DataField );
        // OR
        // $('#dialog-form').find('textarea').val( DataField );
    };

    $("#dialog-form").dialog(grid_modal_options);
} 
</script>
Run Code Online (Sandbox Code Playgroud)