2012-08-23 30 views
0

我正在研究將數據從jquery-ui對話框(asp.net更新面板,搜索db和填充gridview)傳遞到「主」頁面的系統當用戶在gridview中選擇一條線時。jQuery將數據從對話框傳遞到窗口(僅限IE)

一些代碼:

主JSS:

 $(document).ready(function() { 
      $('#PesquisaPessoas').dialog({ 
       autoOpen: false, 
       draggable: false, 
       modal: true, 
       title: "Busca de pessoas na Base de Dados", 
       closeOnEscape: true, 
       width: 650, 
       height: 350, 
       open: function (type, data) { 
        $(this).parent().appendTo("form"); 
       } 
      }); 
     }); 
     function showDialog(id) { 
      $("#" + id).dialog("open"); 
     } 
     function closeDialog(id) { 
      $("#" + id).dialog("close"); 
     } 
     var idCodigo, idNome; 
     function armazenaIds(cod, nome) { 
      //stores controls' IDs 
      idCodigo = cod; 
      idNome = nome; 
     } 
     function preencheTextBoxes(botao) { 
      //gets fields 0 and 1 (Person's ID and name) from the selected line 
      var codigo = botao.parent().siblings()[0].textContent; 
      var nome = botao.parent().siblings()[1].textContent; 
      $("#"+idCodigo).val(codigo); 
      $("#"+idNome).val(nome); 
      $("#CodigoPessoaHiddenField").val(codigo); 
     } 

'主' 頁面:

<asp:FormView ID="ContratoFormView" ... et cetera ...> 
    ... 
    <InsertItemTemplate> 
     Contratante: 
     <asp:TextBox ID="PSS_COD_PESSOATextBox" runat="server" 
      Width="50px" 
      ReadOnly="True" /> 

     <asp:TextBox ID="PSS_NOMETextBox" runat="server" ReadOnly="True"></asp:TextBox> 
     <%-- when user clicks the search button, a js function stores the ids of the two textboxes above --%> 
     <input id="PesquisarButton" type="button" 
      style="border-style: none; background-image: url('Icons/Search24.png'); background-repeat: no-repeat; background-color: #FFFFFF; width: 24px; height: 24px;" 
      onclick="showDialog('PesquisaPessoas'); armazenaIds($(this).prev('input').prev('input').attr('id'),$(this).prev('input').attr('id'))" alt="Pesquisar" /> 
     <asp:HiddenField ID="CodigoPessoaHiddenField" runat="server" 
      ClientIDMode="Static" Value='<%# Bind("PSS_COD_PESSOA") %>' /> 
     <br /> 
     <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
      CommandName="Insert" Text="Cadastrar" /> 
     &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
      CausesValidation="False" CommandName="Cancel" Text="Cancelar" /> 
    </InsertItemTemplate> 
    ... 
</asp:FormView> 

<div id="PesquisaPessoas"> 
    <uc1:PesquisaPessoas ID="PesquisaPessoas1" runat="server" /> 
</div> 

'PesquisaPessoas' 用戶控件:

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
    <ContentTemplate> 
     <h3>Escolha um dos campos para realizar a busca</h3> 
     <div align="center"> 
     <asp:RadioButtonList ID="RadioButtonList1" runat="server" 
      RepeatDirection="Horizontal"> 
      <asp:ListItem Selected="True">Nome</asp:ListItem> 
      <asp:ListItem>CPF</asp:ListItem> 
      <asp:ListItem>Data Nascimento</asp:ListItem> 
     </asp:RadioButtonList> 
     <br /> 

      <asp:TextBox ID="BuscaTextBox" runat="server" AutoPostBack="True" 
       ontextchanged="BuscaTextBox_TextChanged" Width="250px"></asp:TextBox> 
      <asp:ImageButton ID="ImageButton1" runat="server" Height="16px" 
       ImageUrl="~/Icons/Search24.png" onclick="ImageButton1_Click" 
       Width="16px" /> 
     </div> 
     <br /> 
     <asp:GridView ID="BuscaPessoaGridView" runat="server" 
      AutoGenerateColumns="False" DataSourceID="PessoaDataSource" 
      Visible="False" HorizontalAlign="Center" CssClass="SemBordas" > 
      <Columns> 
       <asp:BoundField DataField="PSS_COD_PESSOA" HeaderText="Código" 
        SortExpression="PSS_COD_PESSOA" /> 
       <asp:BoundField DataField="PSS_NOME" HeaderText="Nome" 
        SortExpression="PSS_NOME" /> 
       <asp:BoundField DataField="PSS_NUM_CPF" HeaderText="CPF" 
        SortExpression="PSS_NUM_CPF" /> 
       <asp:BoundField DataField="PSS_DT_NASCIMENTO" DataFormatString="{0:dd/MM/yyyy}" 
        HeaderText="Data Nasc." SortExpression="PSS_DT_NASCIMENTO" /> 
       <asp:BoundField DataField="PSS_SEXO" HeaderText="Sexo" 
        SortExpression="PSS_SEXO" /> 
       <asp:BoundField DataField="PSS_NOME_MAE" HeaderText="Nome Mãe" 
        SortExpression="PSS_NOME_MAE" /> 
       <asp:TemplateField HeaderText="Escolher" ShowHeader="False"> 
        <ItemTemplate> 
         <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandName="Select" 
          ImageUrl="~/Icons/Checkmark.png" Text="OK" 
          onclientclick="closeDialog('PesquisaPessoas'); preencheTextBoxes($(this)); return false;" /> 
        </ItemTemplate> 
        <ControlStyle Height="24px" Width="24px" /> 
        <ItemStyle HorizontalAlign="Center" /> 
       </asp:TemplateField> 
      </Columns> 
      <EmptyDataTemplate> 
       Nenhuma pessoa encontrada. Verifique se os dados foram digitados corretamente. 
      </EmptyDataTemplate> 
     </asp:GridView> 
     <asp:ObjectDataSource ID="PessoaDataSource" runat="server" 
      SelectMethod="BuscaPessoaPorNome" TypeName="UniVendas.Controle.Fachada.Fachada"> 
      <SelectParameters> 
       <asp:FormParameter FormField="BuscaTextBox" Name="nome" Type="String" /> 
      </SelectParameters> 
     </asp:ObjectDataSource> 
    </ContentTemplate> 
    <Triggers> 
     <asp:AsyncPostBackTrigger ControlID="ImageButton1" EventName="Click" /> 
    </Triggers> 
</asp:UpdatePanel> 

ScriptManager的是其他地方的頁。此代碼適用於Firefox和Chrome(均爲最新版本)。

在IE中,'main'中的文本框沒有被JS填充。

+0

你有沒有注意到通過IE拋出的任何JavaScript錯誤? (在開發人員工具中,單擊控制檯選項卡;輸出任何錯誤) – roland

+0

沒有錯誤。並使用控制檯,我可以正確地檢索變量idCodigo和idNome的值。 –

回答

0

與JS控制檯「玩」,我發現IE獲取文本使用innerText而不是textContent

所以,我創建了一個解決方法,以獲得正確的價值觀:

//if user uses IE: 
if(navigator.userAgent.search("MSIE") != -1){ 
    codigo = botao.parent().siblings()[0].innerText; 
    nome = botao.parent().siblings()[1].innerText; 
}else{ 

    codigo = botao.parent().siblings()[0].textContent; 
    nome = botao.parent().siblings()[1].textContent; 
} 
相關問題