2012-12-03 18 views
5

jqueryダイアログをクリック機能で開きます。しかし、私がダイアログを閉じて2回目に開くと、ダイアログ内の内容は変わりません。連続して開いている間にダイアログ内のテキストボックスが空でなければなりません。jqueryダイアログの内容を2回目に開くときに、その内容のみを更新する方法

これは私の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> 

これは私のjsのコードです:

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

      }); 


      $('#id_PrivateSpace').click(function() { 
       $('#thedialog').dialog('open'); 
       return false; 
      }); 

私は、ダイアログの内容だけをリフレッシュするために追加すべきか?

答えて

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; 
}); 

そして、あなたのASPXのためのDropDownListは必ずtrueにAppendDataBoundItemsを設定してください。そして破壊するために緊密に次の関数を追加し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", "")); 
} 
+0

ありがとうございます..しかし、複数行のテキストボックスの内容は同じままです..これについてもこれを達成するには?助けてください – Xavier

+0

私のコードを更新 –

+0

ありがとう..それは動作します:) – Xavier

0
$('#id_PrivateSpace').click(function() { 
    $("#thedialog input[type='text']").val(''); 
    $("#thedialog textarea").html(''); 
    $('#thedialog').dialog('open'); 
    return false; 
}); 
+0

複数のテキストボックスの値が残って..どのようにそれをリフレッシュするには? – Xavier

0

てみてください、

<form id="myform> 
<div id =thedialog> ....... </div> 
</form> 

ダイアログボックスを閉じると、以下の関数を呼び出す

document.getElementById("form1").reset(); 
1

を設定jqueryダイアログの特定のインスタンス:

close: function() 
    { 
     $(this).dialog('close'); 
     $(this).dialog('destroy'); 
     $(this).html(""); 
    }, 

これは、オンザフライでダイアログを作成していたときに同様の問題が発生した場合に使用するコードです。

関連する問題