jQuery将数据从对话框传递到窗口(仅限IE)

时间:2012-08-23 20:10:33

标签: jquery asp.net jquery-ui internet-explorer

当用户在gridview中选择一行时,我正在开发一个系统,该系统将数据从jquery-ui对话框(asp.net更新面板,搜索db并填充gridview)传递到'main'页面。 / p>

一些代码:

Master 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'UserControl:

<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填充的。

1 个答案:

答案 0 :(得分: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;
}