如何在第二次打开时仅刷新jquery对话框的内容

Xav*_*ier 5 html javascript asp.net jquery jquery-dialog

我在点击功能中打开一个jquery对话框.但是,如果我关闭对话框并第二次打开它,对话框内的内容保持不变.我需要对话框内的文本框为空,而我连续打开它.

这是我的aspx代码:

<div>
<span id="id_PrivateSpace" style="color: #88b807; margin-left: 839px;
                            margin-top: -12px; cursor: pointer; display: block">Create</span>
</div>


<div id="thedialog" style="display: none; overflow: hidden">
                    <table id="table" style="border-spacing: 7px 7px; margin-left: 5px">
                        <tr>
                            <td>
                                <span class="SubHeading" style="font-size: 10pt;">Private Space Name </span>
                            </td>
                            <td>
                                <asp:TextBox ID="txt_spacename" runat="server" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="SubHeading" style="font-size: 10pt;">Private Space Description </span>
                            </td>
                            <td>
                                <asp:TextBox ID="txt_spacedesc" TextMode="MultiLine" runat="server" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="SubHeading" style="font-size: 10pt;">Users </span>
                            </td>
                            <td>

                                <input type="text" id="txt_users" />
                            </td>
                            <td>
                                <asp:Button ID="btn_addusers" Text="Add" Style="margin-left: 10px;" runat="server" />
                            </td>
                            <td rowspan="5">
                                <table id="users_grid" align="left">
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="SubHeading" style="font-size: 10pt;">DL </span>
                            </td>
                            <td>
                                <asp:TextBox ID="txt_Add_dl" TextMode="MultiLine" runat="server" />
                            </td>
                        </tr>
                    </table>
                    <input type="button" id="Btn_Submit" value="Create" style="margin-left: 335px; margin-top: 35px;"
                        runat="server" />
                </div>
Run Code Online (Sandbox Code Playgroud)

这是我的js代码:

 $("#thedialog").dialog({
                autoOpen: false,
                title: 'Create Private space',
                modal: true,
                position: 'center',
                width: 900

            });


            $('#id_PrivateSpace').click(function() {
                $('#thedialog').dialog('open');
                return false;
            });
Run Code Online (Sandbox Code Playgroud)

我应该添加什么才能刷新对话框的内容?

Akh*_*ran 3

我想你可以尝试:

$('#id_PrivateSpace').click(function() {
    $("#thedialog").find('input:text, textarea').val('').attr('placeholder','Enter some value');
    $("#thedialog").find('select').val('');//you need to have and option like <option value="">Please Select</option> in your select options list
    $('#thedialog').dialog('open');
    return false;
}); 
Run Code Online (Sandbox Code Playgroud)

对于您的 aspx Dropdownlist,请确保将 AppendDataBoundItems 设置为 true;并设置OnDataBinding事件

<asp:DropDownList id="myDdl" runat="server" OnDataBinding="Ddl_Databinding" >
</asp:DropDownList>

And in your code behind, Add:

protected void Ddl_Databinding(object sender, EventArgs e)
{
    DropDownList ddl = (DropDownList)sender;
    ddl.Items.Add(new ListItem("Please Select", ""));
}
Run Code Online (Sandbox Code Playgroud)