2013-04-25 71 views
1

我是新的asp.net與C#,我需要更新Gridview中的一行,但我必須使用來自AJAX的ModalPopupExtender和我的表的一些領域,必須是強制性的,所以,我開始在這種形式下使用這個控件:首先,我在顯示模式中放置一個按鈕「none」,作爲更新面板的觸發器,在gridview中我放置了一個按鈕名稱「Edit」,在後面顯示ModalPopupExtender代碼,但這裏來了我的麻煩,當我把RequiredFieldValidator,ModalPopupExtender不顯示,這是我的代碼請幫助我,還有一件事,我不能使用Javascript。ModalPopupExtender和RequiredFieldValidator在面板上

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="probando.aspx.cs" Inherits="Menus_Compras_probando" %> 
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> 
<style type="text/css"> 
.modalBackground 
{ 
background-color: Gray; 
filter: alpha(opacity=80); 
opacity: 0.8; 
z-index: 10000; 
} 
</style> 
</asp:Content> 

<asp:Content ID="Content2" ContentPlaceHolderID="cphContenidoPrincipal" Runat="Server"> 

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataSourceID="ObjectDataSource1" DataKeyNames="_adqProveedorId"> 
    <Columns> 
     <asp:BoundField DataField="_adqProveedorId" HeaderText="_adqProveedorId" 
      SortExpression="_adqProveedorId" /> 
     <asp:BoundField DataField="_Nombre" HeaderText="_Nombre" 
      SortExpression="_Nombre" /> 
     <asp:BoundField DataField="_Direccion" HeaderText="_Direccion" 
      SortExpression="_Direccion" /> 
     <asp:BoundField DataField="_OtraIdent" HeaderText="_OtraIdent" 
      SortExpression="_OtraIdent" /> 
     <asp:BoundField DataField="_Telefono" HeaderText="_Telefono" 
      SortExpression="_Telefono" /> 
     <asp:BoundField DataField="_Fax" HeaderText="_Fax" SortExpression="_Fax" /> 
     <asp:BoundField DataField="_Email" HeaderText="_Email" 
      SortExpression="_Email" /> 
     <asp:BoundField DataField="_RepresLegal" HeaderText="_RepresLegal" 
      SortExpression="_RepresLegal" /> 
     <asp:BoundField DataField="_NumRUC" HeaderText="_NumRUC" 
      SortExpression="_NumRUC" /> 
     <asp:CheckBoxField DataField="_PersonalPlanta" HeaderText="_PersonalPlanta" 
      SortExpression="_PersonalPlanta" /> 
     <asp:CheckBoxField DataField="_AutorizaTrasladoAF" 
      HeaderText="_AutorizaTrasladoAF" SortExpression="_AutorizaTrasladoAF" /> 
     <asp:BoundField DataField="_Titulo" HeaderText="_Titulo" 
      SortExpression="_Titulo" /> 
     <asp:BoundField DataField="_CodInt" HeaderText="_CodInt" 
      SortExpression="_CodInt" /> 
     <asp:BoundField DataField="_objClasificaProveedorId" 
      HeaderText="_objClasificaProveedorId" 
      SortExpression="_objClasificaProveedorId" /> 
     <asp:BoundField DataField="_objAgrupacionPID" HeaderText="_objAgrupacionPID" 
      SortExpression="_objAgrupacionPID" /> 
     <asp:BoundField DataField="_objTipoDedIRID" HeaderText="_objTipoDedIRID" 
      SortExpression="_objTipoDedIRID" /> 
     <asp:TemplateField> 
      <ItemTemplate> 
       <asp:Button ID="btnEditar" runat="server" onclick="btnEditar_Click" 
        Text="Editar" /> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
    DataObjectTypeName="Sistema.BO.AdqProveedor" DeleteMethod="BorrarProveedor" 
    OldValuesParameterFormatString="original_{0}" 
    SelectMethod="SelectAllProveedores" TypeName="Sistema.BLL.BLLAdqProveedor" 
    UpdateMethod="AddUpdateProveedor"></asp:ObjectDataSource> 

    <br /><br /> 

    <asp:Button ID="btnShowPopup" runat="server" style="display:none" /> 
    <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlpopup" 
CancelControlID="btnCancel" BackgroundCssClass="modalBackground"> 
</asp:ModalPopupExtender> 

<asp:Panel ID="pnlpopup" runat="server" BackColor="White" style="display:none"> 
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
<ContentTemplate> 
      <table> 
       <tr> 
        <td> 
         <asp:Label ID="Label1" runat="server" Text="Nombre:"> </asp:Label> 
        </td> 
        <td style="width: 315px"> 
         <asp:TextBox ID="tbNombre" runat="server" Width="200px"></asp:TextBox> 

        </td> 
        <td> 
         <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
          ControlToValidate="tbNombre" ErrorMessage="Campo Obligatorio"></asp:RequiredFieldValidator> 
        </td> 
        <td> 
         <asp:Label ID="Label2" runat="server" Text="Dirección:"></asp:Label> 
        </td> 
        <td> 
         <asp:TextBox ID="tbDir" runat="server" Width="300px"></asp:TextBox> 
        </td> 
       </tr> 
       <tr> 
        <td> 
         <asp:Label ID="Label3" runat="server" Text="Otra Identificación"></asp:Label> 
        </td> 
        <td style="width: 315px"> 
         <asp:TextBox ID="tbOtraId" runat="server"></asp:TextBox> 
        </td> 
        <td> 
         <asp:Label ID="Label4" runat="server" Text="Teléfono"></asp:Label> 
        </td> 
        <td> 
         <asp:TextBox ID="tbTel" runat="server"></asp:TextBox> 
        </td> 
       </tr> 
       <tr> 
        <td> 
         <asp:Label ID="Label5" runat="server" Text="Fax:"></asp:Label> 
        </td> 
        <td style="width: 315px"> 
         <asp:TextBox ID="tbFax" runat="server"></asp:TextBox> 
        </td> 
        <td> 
         <asp:Label ID="Label6" runat="server" Text="Email"></asp:Label> 
        </td> 
        <td> 
         <asp:TextBox ID="tbMail" runat="server"></asp:TextBox> 
        </td> 
       </tr> 
       <tr> 
        <td> 
         <asp:Label ID="Label7" runat="server" Text="Representación Legal:"></asp:Label> 
        </td> 
        <td style="width: 315px"> 
         <asp:TextBox ID="tbRepLegal" runat="server"></asp:TextBox> 
        </td> 
        <td> 
         <asp:Label ID="Label8" runat="server" Text="Número RUC:"></asp:Label> 
        </td> 
        <td> 
         <asp:TextBox ID="tbRuc" runat="server"></asp:TextBox> 
        </td> 
       </tr> 
       <tr> 
        <td> 
         <asp:Label ID="Label9" runat="server" Text="Personal Planta:"></asp:Label> 
        </td> 
        <td style="width: 315px"> 
         <asp:CheckBox ID="cbPersonalPlanta" runat="server" /> 
        </td> 
        <td> 
         <asp:Label ID="Label12" runat="server" Text="Clasificación:"></asp:Label> 
        </td> 

       </tr> 
       <tr> 
        <td> 
         <asp:Label ID="Label11" runat="server" Text="Título:"></asp:Label> 
        </td> 
        <td style="width: 315px"> 
         <asp:TextBox ID="tbTitulo" runat="server"></asp:TextBox> 
        </td> 
        <td> 
         <asp:Label ID="Label14" runat="server" Text="Tipo deducción IR:"></asp:Label> 
        </td> 

       </tr> 
       <tr> 
        <td colspan="4" style="height: 23px"> 
         <asp:Label ID="lblIdProv" runat="server" Visible="False"></asp:Label> 
         <asp:Label ID="lblIdClas" runat="server" Visible="False"></asp:Label> 
         <asp:Label ID="lblAgrId" runat="server" Visible="False"></asp:Label> 
         <asp:Label ID="lblDedId" runat="server" Visible="False"></asp:Label> 
        </td> 
       </tr> 
       <tr> 
        <td colspan="4"> 
         <asp:Label ID="lblInfo" runat="server"></asp:Label> 
         <asp:Image ID="Image1" runat="server" Height="16px" Width="16px" /> 
        </td> 
       </tr> 
       <tr> 
        <td> 
         &nbsp;</td> 
        <td style="width: 315px"> 
         &nbsp;</td> 
        <td> 
         &nbsp;</td> 

       </tr> 
      </table> 


    <asp:Label ID="lblRes" runat="server" Text=""></asp:Label> 
    <asp:Button ID="btnAct" runat="server" CommandName="Update" Text="Update" onclick="btnAct_Click" /> 
    <asp:Button ID="btnCancel" runat="server" Text="Cancel" /> 
</ContentTemplate> 
</asp:UpdatePanel> 

,這是我的背後

protected void btnEditar_Click(object sender, EventArgs e) 
{ 
    Button btndetails = sender as Button; 
    GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer; 
    tbNombre.Text = gvrow.Cells[1].Text; 
    this.ModalPopupExtender1.Show(); 
} 

回答

0

try代碼把整個代碼更新面板

+0

也GridView的? – 2013-04-25 01:59:46

+0

你好,我找到了一個解決方案,我不知道它是否是最優化的,但它適用於我,我不得不把所有顯示在ModalPopupExtender上的控件放在同一個驗證組內並且效果不錯:) – 2013-04-25 02:27:31

0

這一次我指出了正確的方向內今天如此認爲我會發佈一個實際的代碼解決方案。如上文的評論中提到的,關鍵是要一個的ValidationGroup標記添加到所有的RequiredFieldValidator控件,您可以控制在應用驗證這種方式 -

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default2.aspx.vb" Inherits="ModalPopupExtenderExample.Default2" %> 
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %> 

    <!DOCTYPE html> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head runat="server"><title>Test</title> 

    <style type="text/css"> 
    body{background-color: grey; font-family: Arial, Helvetica, sans-serif;} 
    .popup{background-color: white; padding:10px; border-radius:5px;} 
    </style> 

    </head> 

    <body> 
     <form id="form1" runat="server"> 
      <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 
      <asp:Label ID="LabelAddNewContact" runat="server" Text="Add new contact"></asp:Label> 
      <asp:Button ID="ButtonAddNewContact" runat="server" Text="Add" /> 

      <asp:Panel ID="ModalPanelAddNewContact" runat="server" Width="500px" CssClass="popup"> 

       <div> 
        <asp:Label ID="LabelFirstName" runat="server" Text="First Name"></asp:Label><span class="requiredSpan"> *</span> 
        <asp:TextBox ID="TextBoxFirstName" runat="server"></asp:TextBox> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidatorFirstName" ValidationGroup="AddNewContact" runat="server" ControlToValidate="TextBoxFirstName" Display="Dynamic" EnableClientScript="true" ErrorMessage="Required"></asp:RequiredFieldValidator> 
       </div> 
       <div> 
        <asp:Label ID="LabelEmail" runat="server" Text="Email"></asp:Label><span class="requiredSpan"> *</span> 
        <asp:TextBox ID="TextBoxEmail" runat="server"></asp:TextBox> 
        <asp:RequiredFieldValidator ID="RequiredFieldValidatorEmail" runat="server" ValidationGroup="AddNewContact" ControlToValidate="TextBoxEmail" Display="Dynamic" EnableClientScript="true" ErrorMessage="Required"></asp:RequiredFieldValidator>    
       </div> 

       <asp:Button ID="ButtonModalPanelAddNewClose" runat="server" Text="Cancel" /> 
       <asp:Button ID="ButtonModalPanelSaveNewContact" runat="server" Text="Save this contact" ValidationGroup="AddNewContact" /> 
       <asp:Button ID="ButtonAddBrandNewContact" runat="server" Text="Add" style="display:none"/> 
      </asp:Panel> 

      <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtenderAddNewContact" runat="server" TargetControlID="ButtonAddBrandNewContact" 
       PopupControlID="ModalPanelAddNewContact" CancelControlID="ButtonModalPanelAddNewClose" BehaviorID="1" /> 
     </form> 
    </body> 
    </html> 
相關問題