Can't add record to store from partial view

Page 1 of 2 12 LastLast
  1. #1

    Can't add record to store from partial view

    Is it possible to update a store that was loaded through a partial view?

    The partial view below was loaded to a tab. I've got a store of photos attached to a dataview. On that same page I have an image uploader. After uploading the image i want to add that record to the store and refresh the dataview. This would probably be a good image upload example for your website.

    My only problem is that the store is non existant or I can't find it. I know i can't use .net to update it since it's a partialview, but I was hoping to at least be able to use javascript.

    I tried to refresh the tab using javascript, but .net broke on the Page_Load call. So i tried different methods to load the datastore.

    I tried the PageProxy and that didn't work. The storePhoto_Refresh couldn't find the store. It was the same code as the Page_Load method.

    I also tried the http proxy (commented out) but that didn't work either. It was returning the exact same JSON but for some reason the dataview kept showing 0 images. That method returned an AjaxStoreResult. I tried AutoBind, AutoLoad, and a bunch of other things. It doesn't like me :-)

    Basically, does anyone have a good idea how to refresh the store after i upload an image. My obstacle seems to be that i'm loading this from a partialview and trying to update after the page is loaded.


    
    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        
        protected void storePhoto_Refresh(object sender, StoreRefreshDataEventArgs e)
        {
            // tried to use a refresh on the store, but that didn't work either.  it seems you can't do a refresh on a strore in a partialview
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var photos = (Session["GroupMembership"] as GroupMembership).photos;
            if (photos.Count > 0)
            {
                List<object> data = new List<object>(photos.Count);
                foreach (var photo in photos)
                {
                    data.Add(new
                    {
                        name = photo.caption,
                        url = "../../" + photo.path,
                        size = Convert.ToInt32(photo.image_size)
                    });
                }
                this.storePhoto.DataSource = data;
                this.storePhoto.DataBind();
            }
            
        }
    </script>
     <script type="text/javascript">
         var prepareData = function (data) {
             data.shortName = Ext.util.Format.ellipsis(data.name, 15);
             data.sizeString = Ext.util.Format.fileSize(data.size);
             return data;
         };
    
         var selectionChaged = function (dv, nodes) {
             var l = nodes.length;
             var s = l != 1 ? 's' : '';
             ImagePanel.setTitle('Simple DataView (' + l + ' item' + s + ' selected)');
         };
    
                var photoUploadFailureHandler = function (form, action) {
                    Ext.Msg.show({
                        title: "Save Error",
                        msg: action.response.responseText,
                        buttons: Ext.Msg.OK,
                        icon: Ext.Msg.ERROR
                    });
                };
    
                var photoUploadSuccessHandler = function (result, request) {
                    Ext.Msg.show({
                        title: "Complete.",
                        msg: "Image uploaded successfully.",
                        buttons: Ext.Msg.OK
                    });
                    //        // can't access storePhoto
                    //        MyRecordType = Ext.data.Record.create(['name', 'url', 'size']);
                    //        myrec = new MyRecordType({ "name": "101", "name": "Craig", "size": "10000" });
                    //        Ext.getCmp("storePhoto").add(myrec);
                    Ext.getCmp("dvPhotos").refresh();
                };
    
    
    
        </script> 
       
        <ext:Panel ID="plnPhotosBorderLayoutWrapper" runat="server" Layout="fit" Height="400" Border="false">
        <Items>
        <ext:BorderLayout ID="brdlayoutPhotosTab" runat="server">
            <west MarginsSummary="5 5 5 0" collapsible="true" split="true">
                <ext:FormPanel 
                    ID="frmPhotoUpload" 
                    runat="server"
                    Width="225"
                    Frame="true"
                    Closable = "false"
                    Collapsible = "true"
                    Title="Upload Photos"
                    AutoHeight="true"
                    MonitorValid="true"
                    PaddingSummary="10px 10px 0 10px"
                    LabelWidth="50"
                    url="/Group/UploadPhotoExt/"  
                    Method="POST"
                    FileUpload="true">                
                    <Items>
                        <ext:TextField Width="140" ID="PhotoName" runat="server" FieldLabel="Caption" Name="caption" />
                        <ext:FileUploadField 
                        ID="FileName"
                            runat="server" 
                            Width = "140"
                            EmptyText="Select an image"
                            FieldLabel="Photo"
                            ButtonText=""
                            Icon="Attach"
                            />
                    </Items>
                    <Buttons>
                        <ext:Button ID="SaveButton"  runat="server" Text="Save">
                            <Listeners>
                                <Click Handler="#{frmPhotoUpload}.getForm().submit({ waitMsg : 'Uploading photo...',  success : photoUploadSuccessHandler, failure : photoUploadFailureHandler });" />
                            </Listeners>
                        </ext:Button>
                        <ext:Button  runat="server" Text="Reset" ID="ctl40">
                            <Listeners>
                                <Click Handler="#{frmPhotoUpload}.getForm().reset();" />
                            </Listeners>
                        </ext:Button>
                    </Buttons>
                </ext:FormPanel>
                         
            </west>
            <center MarginsSummary="5 5 5 0">
                <ext:Panel ID="plnPhotosCenterLayout" runat="server" Border="false" AutoHeight="true" Layout="fit">
                    <Items>
                        <ext:Panel 
                            runat="server" 
                            ID="plnPhotosImagePanel" 
                            Cls="images-view" 
                            Frame="true" 
                            AutoHeight ="true"
                            Collapsible = "false"
                            Layout = "fit"
                            Title="Group Photos">
                            <Items>
                                <ext:DataView ID="dvPhotos" 
                                    runat="server"
                                    AutoHeight = "true"
                                    MultiSelect="true"
                                    OverClass="x-view-over"
                                    ItemSelector="div.thumb-wrap"
                                    EmptyText="There are no images in this group.">
                                    <Store>
                                    <ext:Store runat="server" ID="storePhoto" AutoLoad="true" >
                                       <%-- <Proxy>
                                            <ext:HttpProxy Method="POST" Url="/Group/GetPhotos/" />
                                           //  this doesn't work - no idea why.. forced to use page_load to bind
                                        </Proxy>--%>
                                        <Reader>
                                            <ext:JsonReader>
                                                <Fields>
                                                    <ext:RecordField Name="name" />
                                                    <ext:RecordField Name="url" />      
                                                    <ext:RecordField Name="size" Type="Int" />
                                                </Fields>
                                            </ext:JsonReader>
                                        </Reader>
                                        <AutoLoadParams>
                                            <ext:Parameter Name="start" Value="0" Mode="Raw" />
                                            <ext:Parameter Name="limit" Value="15" Mode="Raw" />
                                        </AutoLoadParams>
                                    </ext:Store>   
                                    </Store>
                                    <Template ID="Template1" runat="server">
                                        <Html>
    					                    <tpl for=".">
    						                    <div class="thumb-wrap">
    							                    <div class="thumb"><img src="{url}" title="{name}"></div>
    							                    <span class="x-editable">{name}</span>
    						                    </div>
    					                    </tpl>
    					                    <div class="x-clear"></div>        
    				                    </Html>
                                    </Template>                         
                                   <%-- <PrepareData Fn="prepareData" />                
                                    <Listeners>
                                        <SelectionChange Fn="selectionChaged" /> 
                                    </Listeners> --%>                        
                                </ext:DataView>
                            </Items>
                            <BottomBar>
                                <ext:PagingToolbar ID="pgTbPhotoViewer" runat="server" StoreID="storePhoto" PageSize="15" HideRefresh="true" />
                            </BottomBar>
                        </ext:Panel>
                        
                    </Items>
                </ext:Panel>
            </center>
        </ext:BorderLayout>
        </Items>
        </ext:Panel>
  2. #2
    Bumping... Anyone have any ideas?
  3. #3
    ok, i got everything working with the http proxy and i'm just reloading the tab. Not my favorite solution, but it will do for now.
    I fixed the http proxy by adding a few tags to the json reader. I guess it needed some binding help.

    <ext:JsonReader IDProperty="name" Root="data" TotalProperty="total">

    Now the DataView isn't scaling again. I say again because this happened before when i was binding on the page_load function. I finally fixed it by increasing the AutoLoadParams to match the PageSize in the paging toolbar.

    <AutoLoadParams>
          <ext:Parameter Name="start" Value="0" Mode="Raw" />
          <ext:Parameter Name="limit" Value="15" Mode="Raw" />
    </AutoLoadParams>
    But now with the http proxy, the dataview is only rendering 3 images at a time. I can't seem to fix it. On the first page, it only shows 3 of 24 images and there are only 2 pages. I have no idea what is happening to the other images.

    It's not a height issue because the paging says "Displaying 1 - 3 of 24"

    Has anyone seen this before? Why is it not rendering all my images or at least the 15 per page?


    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
        <ext:Panel ID="plnPhotosBorderLayoutWrapper" runat="server" Layout="fit" Height="400" Border="false">
        <Items>
        <ext:BorderLayout ID="brdlayoutPhotosTab" runat="server">
            <west MarginsSummary="5 5 5 0" collapsible="true" split="true">
                <ext:FormPanel 
                    ID="frmPhotoUpload" 
                    runat="server"
                    Width="225"
                    Frame="true"
                    Closable = "false"
                    Collapsible = "true"
                    Title="Upload Photos"
                    AutoHeight="true"
                    MonitorValid="true"
                    PaddingSummary="10px 10px 0 10px"
                    LabelWidth="50"
                    url="/Group/UploadPhotoExt/"  
                    Method="POST"
                    FileUpload="true">                
                    <Items>
                        <ext:TextField Width="140" ID="PhotoName" runat="server" FieldLabel="Caption" Name="caption" />
                        <ext:FileUploadField 
                        ID="FileName"
                            runat="server" 
                            Width = "140"
                            EmptyText="Select an image"
                            FieldLabel="Photo"
                            ButtonText=""
                            Icon="Attach"
                            />
                    </Items>
                    <Buttons>
                        <ext:Button ID="SaveButton"  runat="server" Text="Save">
                            <Listeners>
                                <Click Handler="#{frmPhotoUpload}.getForm().submit({ waitMsg : 'Uploading photo...',  success : photoUploadSuccessHandler, failure : photoUploadFailureHandler });" />
                            </Listeners>
                        </ext:Button>
                        <ext:Button  runat="server" Text="Reset" ID="ctl40">
                            <Listeners>
                                <Click Handler="#{frmPhotoUpload}.getForm().reset();" />
                            </Listeners>
                        </ext:Button>
                    </Buttons>
                </ext:FormPanel>
                         
            </west>
            <center MarginsSummary="5 5 5 0">
                <ext:Panel ID="plnPhotosCenterLayout" runat="server" Border="false" AutoHeight="true" Layout="fit">
                    <Items>
                        <ext:Panel 
                            runat="server" 
                            ID="plnPhotosImagePanel" 
                            Cls="images-view" 
                            Frame="true" 
                             Height="300"
                            Collapsible = "false"
                            Layout = "fit"
                            Title="Group Photos">
                            <Items>
                                <ext:DataView ID="dvPhotos" 
                                    runat="server"
                                    AutoHeight = "true"
                                    MultiSelect="true"
                                    OverClass="x-view-over"
                                    ItemSelector="div.thumb-wrap"
                                    EmptyText="There are no images in this group.">
                                    <Store>
                                    <ext:Store runat="server" ID="storePhoto" AutoLoad="true" >
                                        <Proxy>
                                            <ext:HttpProxy Method="POST" Url="/Group/GetPhotos/" AutoDataBind="true" />  
                                        </Proxy>
                                        <Reader>
                                            <ext:JsonReader IDProperty="name" Root="data" TotalProperty="total">
                                                <Fields>
                                                    <ext:RecordField Name="name" />
                                                    <ext:RecordField Name="url" />      
                                                    <ext:RecordField Name="size" Type="Int" />
                                                </Fields>
                                            </ext:JsonReader>
                                        </Reader>
                                        <AutoLoadParams>
                                            <ext:Parameter Name="start" Value="0" Mode="Raw" />
                                            <ext:Parameter Name="limit" Value="15" Mode="Raw" />
                                        </AutoLoadParams>
                                    </ext:Store>   
                                    </Store>
                                    <Template ID="Template1" runat="server">
                                        <Html>
    					                    <tpl for=".">
    						                    <div class="thumb-wrap">
    							                    <div class="thumb"><img src="{url}" title="{name}"></div>
    							                    <span class="x-editable">{name}</span>
    						                    </div>
    					                    </tpl>
    					                    <div class="x-clear"></div>        
    				                    </Html>
                                    </Template>                         
                                   <%-- <PrepareData Fn="prepareData" />                
                                    <Listeners>
                                        <SelectionChange Fn="selectionChaged" /> 
                                    </Listeners> --%>                      
                                </ext:DataView>
                            </Items>
                            <BottomBar>
                                <ext:PagingToolbar ID="pgTbPhotoViewer" runat="server" StoreID="storePhoto" PageSize="15" HideRefresh="true" />
                            </BottomBar>
                        </ext:Panel>
                        
                    </Items>
                </ext:Panel>
            </center>
        </ext:BorderLayout>
        </Items>
        </ext:Panel>
  4. #4
    Hi,

    1. You cannot have any server side handlers in the partial view because partial view is not recreated on other requests therefore RefershData handler cannot be used

    2. Store cannot be found using Ext.getCmp because it is not component. Please see ExtJS documentation to understand getCmp method
    http://dev.sencha.com/deploy/dev/docs/

    Just use ClientID directly
    storePhoto.add(myrec);
    3.
    But now with the http proxy, the dataview is only rendering 3 images at a time. I can't seem to fix it. On the first page, it only shows 3 of 24 images and there are only 2 pages. I have no idea what is happening to the other images.
    Do you return total count of records? Please see
    https://examples1.ext.net/#/GridPane...rting/Handler/
  5. #5
    yeah, i'm returning the total record count. The paging knows about it, just not the dataview. Here's the JSON i'm returning.

    When i don't use the http proxy and code the bind to the store, everything works great. But i need the httpproxy since i can't reload this tab with the page_load function there.

    {data:[{"name":"test","url":"../../images/photos/bd86d9a8-e0eb-4511-8b72-e49e325e084dLighthouse.jpg","size":584237},{"name":"ets","url":"../../images/photos/a2bc9d92-c51a-4618-8141-ab6d42aa0e23Penguins.jpg","size":684071},{"name":"test","url":"../../images/photos/7b96933f-9d02-4e3e-b00c-deb1360778d3Lighthouse.jpg","size":584237},{"name":"test","url":"../../images/photos/c4e190f5-12da-4530-bf02-d8735823d36fLighthouse.jpg","size":584237},{"name":"test","url":"../../images/photos/fa64d65d-1c37-41a9-a527-6c882d2713ccHydrangeas.jpg","size":711172},{"name":"test","url":"../../images/photos/c09aed9e-577d-429b-a386-ef3fa365f9b0Lighthouse.jpg","size":584237},{"name":"test","url":"../../images/photos/276806a5-fa36-410a-b2bb-88caa4fd3120Penguins.jpg","size":684071},{"name":"test","url":"../../images/photos/5fe24a28-f5d2-481c-ac92-5e48799b8563Lighthouse.jpg","size":584237},{"name":"test","url":"../../images/photos/4f9a8a1d-928e-444b-8eae-8ed8e442feccPenguins.jpg","size":684071},{"name":"test","url":"../../images/photos/89c24a47-7bed-43d7-8369-c47e8f40c56eLighthouse.jpg","size":584237},{"name":"test","url":"../../images/photos/b115dc83-6eee-43d1-a102-3e667296bb7fLighthouse.jpg","size":584237},{"name":"test","url":"../../images/photos/acd29294-89c3-4c0b-a153-2473dd5ccadaLighthouse.jpg","size":584237},{"name":"test","url":"../../images/photos/2d2cec0d-d84c-4e76-add9-137cc71c9fb1Lighthouse.jpg","size":584237},{"name":"test","url":"../../images/photos/ed5d348e-803b-4a9d-960d-289014d765c5Lighthouse.jpg","size":584237},
    {"name":"I love these flowers","url":"../../images/photos/ab9f9dcd-bfda-4232-bda9-ff037879903dHydrangeas.jpg","size":711172},{"name":"test","url":"../../images/photos/c1cb8ee7-2ecb-496b-b14a-a14a1f93d336Penguins.jpg","size":684071},{"name":"test","url":"../../images/photos/3af293bb-dd72-4296-9100-67f66a2c734bLighthouse.jpg","size":584237},{"name":"test","url":"../../images/photos/1e6560f6-4596-48a8-8342-79a4593594e5Lighthouse.jpg","size":584237},{"name":"test","url":"../../images/photos/0a35bb1a-2cde-40e3-a521-4bdc774a908fLighthouse.jpg","size":584237},{"name":"test","url":"../../images/photos/7b0ca9af-c456-4144-904b-bfcf990f7475Lighthouse.jpg","size":584237},{"name":"test","url":"../../images/photos/f320d293-a492-4337-84f5-169ccd695169Penguins.jpg","size":684071},{"name":"test","url":"../../images/photos/293101b8-76c4-4b8c-ae18-af0aa7dcbd72Penguins.jpg","size":684071},{"name":"test","url":"../../images/photos/b9a7fbbc-be9e-4d79-b69b-cc90e5fa9792Penguins.jpg","size":684071},{"name":"test","url":"../../images/photos/3b6dab59-83ef-4649-a527-f287fa3566b3Penguins.jpg","size":684071}], total: 24}
  6. #6
    Also, i tried the access the store in many ways.

    storePhoto.add is null.

    Ext.get("storePhoto") is null as well

    Can this be because it's from a partial view? I can't access any of my javascript in a partial view. I need to move all my javascript methods to the parent asp page. Maybe there is a setting i'm missing or something when i render the partialview to a tab.
  7. #7
    Hi,

    Can you create simple test project (without any assemblies) and post it?
    Last edited by geoffrey.mcgill; Jan 04, 2011 at 9:10 PM.
  8. #8
    ok, so i created a simple test project and it worked (although javascript still isn't available). Maybe you can shed some light on that. Any javascript function in a partialview does not work once the partial view is loaded to a tab.

    The paging was also broken in the simple test project. I read some more forum posts and found a remotepaging option. Although this should be set to false by default, i think it gets enabled when doing an http proxy. So i set that to false and paging started working again.

    But the killer was the IDProperty on the JSON reader. I had this set to Name. Most of the names where the same and that's why only a few images were showing up. There was a duplicate id problem. That also broke the store which is now accessible through javascript after page load :-).

    So with exception for the javascript methods which don't work within the scope of the partialview everything seems to be good.
  9. #9
    I'd prefer not to refresh the entire tab for each upload. I just want to add a record to the store and for it to show up in the dataview.

    I've got that working except it just add it to the bottom and ignores the paging. How do I get this to work with the paging?

     var photoUploadSuccessHandler = function (result, request) {
                   // reloadTab("Photos");
    
                    Ext.net.Notification.show({
                        bringToFront: true,
                        pinEvent: 'click',
                        alignToCfg: {
                            offset: [-200, -200],
                            position: 'br-br',
                            el: Ext.net.getEl('ctl00_MainContent_tpGroupTabs')
                        },
                        html: "<br />Upload completed successfully</br>",
                        title: 'Upload complete'
                    });
                    MyRecordType = Ext.data.Record.create(['id', 'name', 'image', 'thumb', 'size']);
                    myrec = new MyRecordType({ "id":"item1", "name": "101", "image": "good.gif", "thumb":"goodthumb", "size": "10000" });
                    storePhoto.add(myrec);
                    Ext.getCmp("pgTbPhotoViewer").doLoad(); // this doesn't work right - it losing all paging
                    Ext.getCmp("dvPhotos").refresh(); // this just adds the new store object at the bottom and doesn't do paging
                           
                };
  10. #10
    any suggestions on how to do this?
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] Problem rendering partial view
    By T3rryChan in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jul 03, 2012, 9:22 PM
  2. [CLOSED] Partial View Error
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 10, 2012, 10:32 AM
  3. Javascript not work in partial view mvc.ext.net
    By theblackcat_2902 in forum 1.x Help
    Replies: 9
    Last Post: Aug 24, 2011, 10:31 AM
  4. [CLOSED] RegisterOnReadyScript in MVC partial view
    By SandorD in forum 1.x Legacy Premium Help
    Replies: 22
    Last Post: Aug 10, 2011, 4:17 PM
  5. MVC binding store in partial view problems
    By craig2005 in forum 1.x Help
    Replies: 11
    Last Post: Jan 04, 2011, 3:31 AM

Posting Permissions