2010-09-08 74 views
0

如何在RELOADS .aspx页面创建一个Javascript方法,以便在其他现有方法之一中调用。网格不会每次都刷新。我可以整个窗口刷新吗?

<%@ Page Language="VB" Inherits="Core.Web.BaseView(OfLending.Controllers.Workspace.DocumentUploadData)" %> 
    <%@ Import Namespace="Framework.WebControls.Forms" %> 
    <%@ Import Namespace="Framework.WebControls.Grids" %> 

    <script runat="server"> 

    </script> 

    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head runat="server"> 
     <title></title> 
     <script language="javascript" type="text/javascript"> 

      function RefreshGrid(result, data) { 
       if (data.responseText.length > 0) { 
        var obj = eval('(' + data.responseText + ')'); 
        if (obj.Result == false) { 
         Global.alertError(obj.UserMessage, obj.ExceptionID); 
        } 
        else { 
         Global.getComponent('txtDescription').setValue(''); 
         mygrid.refresh(); 
        } 
       } 
      } 

      var uploadWindow 
      var showUploadWindow = function() { 
       if (!uploadWindow) { 
        uploadWindow = new Ext.Window({ 
         title: 'Attach Document' 
         , width: 450 
         , height: 140 
         , closable: true 
         , closeAction: 'hide' 
         , iconCls: '' 
         , layout: 'form' 
         , bodyStyle: 'padding:10px 10px 0px 2px' 
         , labelWidth: 100 
         , labelAlign: 'right' 
         , renderTo: DocumentUploadForm_FormViewPort.getEl() 
         , constrain: true 
         , modal: true 
         , items: [{ 
          xtype: 'textfield' 
          , validationEvent: 'blur' 
          , enableKeyEvents: true 
          , anchor: '100%' 
          , fieldLabel: '* Select File' 
          , labelStyle: 'color:red' 
          , el: 'fuDocument' 
          , id: 'fuDocument' 
          , allowBlank: false 
          , blankText: 'File Upload is a required field' 
          , inputType: 'file' 
         }, { 
          xtype: 'textfield' 
          , anchor: '100%' 
          , fieldLabel: 'Description' 
          , id: 'txtDescription' 
          , allowDecimals: false 
          , decimalPrecision: 0 
          , maxLength: 100 
          , maxLengthText: 'Description must be no more than 100 characters in length' 
         }] 
         , buttonAlign: 'center' 
         , fbar: [{ 
          text: 'Save', iconCls: 'icon-button-save', handler: function() { uploadDocument() } 
         }, { 
          text: 'Cancel', iconCls: 'icon-button-cancel', handler: function() { uploadWindow.hide() } 
          }] 
         }) 
        } 
        uploadWindow.show(); 
        mapEnterKey(uploadWindow); 
       } 

      function viewContent() { 
       var docId = mygrid.getSelectedString('DocumentId'); 
       window.location = "Edit/" + docId; 
      } 

      function uploadDocument() { 
       uploadWindow.hide(); 
       DocumentUploadForm.doAction('SAVE') 
       mygrid.refresh(); 
      } 

      //this function maps enter key 
      function mapEnterKey(obj) { 
       var keyMap = new Ext.KeyMap(obj.getEl(), { 
        key: Ext.EventObject.ENTER, 
        stopEvent: true, 
        handler: uploadDocument 
       }); 
      } 

     </script> 
    </head> 
    <body> 
     <form id="form1" runat="server"> 

      <div style="display:none"> 
       <asp:FileUpload ID="fuDocument" runat="server" /> 
      </div> 

      <% 
       Using DocumentUploadForm As New WebControls.Forms.Form() 
        With DocumentUploadForm 
         .ID = "DocumentUploadForm" 
         .Framed = False 
         .ItemName = "Document" 
         .Title = "Application Documents" 
         .TitleStyle = Forms.Form.TitleStyleType.TitleBar 
         .IconCls = "icon-blank-16" 
         .OnSubmitCallback = "RefreshGrid" 
         .Toolbar.UseDefaultButtons = False 

         With .CenterRegion 
          Using mygrid As New WebControls.Grids.Grid() 
           With mygrid 
            .ID = "mygrid" 

            .GridItemName = "document" 
            .Title = "Uploaded Documents" 
            .Mode = Grid.GridMode.Tab 
            .OnDoubleClick = "viewContent" 
            .SetEditPage("Workspace/DocumentUpload.mvc", "DocumentId") 

            With .Toolbar 
             .AllowSearch = False 
             .UseDefaultButtons = False 
             With .AddButton("Attach Document", "function(){showUploadWindow();}") 
              .RequiresRowSelection = False 
              .IconClass = "icon-button-create" 
             End With 
             With .AddButton(Grids.Grid.GridToolbar.ButtonType.Edit) 
              .Text = "View Document" 
              .Handler = "viewContent" 
              .IconClass = "icon-button-preview" 
             End With 
             With .AddButton(Grids.Grid.GridToolbar.ButtonType.Delete) 
              .Text = "Delete Document" 
             End With 
             .PushItems() 
             With .AddButton("Close Window", "function(){window.close()}") 
              .RequiresRowSelection = False 
              .IconClass = "icon-button-cancel" 
             End With 
            End With 

            .Columns.AddHidden("DocumentId") 
            .Columns.Add("Name", "Name", Grid.ColumnDataType.String, 200) 
            .Columns.Add("Description", "Description", Grid.ColumnDataType.String, 450) 

            .DataSource = ViewData("Documents") 
            .DataBind() 
            Response.Write(.ToString()) 
           End With 
          End Using 
          .AddControl("mygrid", "Documents", Forms.Control.ControlType.Grid) 
         End With 


        End With 

        Response.Write(DocumentUploadForm.ToString()) 
       End Using 
      %> 

     </form> 
    </body> 
    </html> 
+0

另外,我在mygrid.refresh()之后发出警报;声明,我可以看到警报,但由于某种原因,不是新上传的文件,直到我还是F5。这就像刷新网格没有做任何事情。 – Scott 2010-09-08 14:52:40

回答

0

想通了。将RefreshGrid()更改为此。

function RefreshGrid(result, data) { 
       window.location.reload(); 
       if (data.responseText.length > 0) { 
        var obj = eval('(' + data.responseText + ')'); 
        if (obj.Result == false) { 
         Global.alertError(obj.UserMessage, obj.ExceptionID); 
        } 
        else { 
         Global.getComponent('txtDescription').setValue(''); 
        } 
       } 
      } 
0

应该在GridView(Check Ext Docs)上调用refresh()函数。所以,如果 “mygrid” 是你的GridPanel, 然后调用它是这样的:

mygrid.getView().refresh(); 
+0

获取此错误。 mygrid.getView不是函数 – Scott 2010-09-08 15:40:25

+0

如果“mygrid”是一个GridPanel,那么应该有getView()方法。在控制台中检查mygrid - 是否有任何getView()方法。在GridView API中检查refresh()方法 - http://dev.sencha.com/deploy/dev/docs/?class=Ext.grid.GridView – Swar 2010-09-08 16:19:15

+0

我相信弹出的窗口是ExtJS窗口,但我认为父页面上的网格只是一个常规的ASP.NET网格。 mygrid.refresh()的代码;没有错误,但没有工作。我只想要一种方法来从ExtJS弹出窗口中硬刷新父.aspx页面。 – Scott 2010-09-08 17:41:39