locked
DynamicControl seemingly 'lost' after postback RRS feed

  • Question

  • User-1712241964 posted

    I am utilizing an image rendering field template(of the NotAClue variety) via UIHint ina DynamicControl in a FormView.      I also have a GridView & DetailsView elsewhere on the same page(neither is 'nested' within the other).   On initial page load, the photo renders beautifully.    When an Item is selected in the GridView and a postback occurs, the DynamicControl seems to go blank(the image disappears).   no errors are thrown, no broken image placeholder is shown...just disappears.  If I remove the UIHint attribute from the DynamicControl, DD just displayes the text that is the file name of the image (ex: "TheFileName.jpeg") and is displayed consistantly throughout postbacks(selecting items in the gridview on the page).   Hope I've described it well enough.   This is a question more so for those more familliar with the NotAClue image template, but any suggestions on what to try would be appreciated.

    -Gary

    Monday, September 12, 2011 10:55 AM

Answers

All replies

  • User-330204900 posted

    Hi Gstater, whic field template is it and where did you get it from as the latest are now on NuGet see Dynamic Data Custom Field Templates<header>

     
    </header>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 13, 2011 5:09 AM
  • User-1712241964 posted

    here is the exact code from the template:

     public partial class ShowImage : System.Web.DynamicData.FieldTemplateUserControl
        {
            protected override void OnDataBinding(EventArgs e)
            {
                base.OnDataBinding(e);
    
                // get attributes
                var uploadAttribute = Column.GetAttributeOrDefault<UploadAttribute>();
                if (uploadAttribute == null)
                    throw new InvalidOperationException("FileUpload must have valid uploadAttribute applied");
    
                var extension = FieldValueString.GetFileExtension();
                var imagePath = String.Format("{0}{1}", VirtualPathUtility.AppendTrailingSlash(uploadAttribute.UploadFolder), FieldValueString);
                var Image1 = new System.Web.UI.WebControls.Image()
                    {
                        ImageUrl = imagePath,
                        AlternateText = FieldValueString,
                        BorderStyle = BorderStyle.None
                    };
    
                // set width
                if (uploadAttribute.Width > 0)
                    Image1.Width = uploadAttribute.Width;
    
                // set height
                if (uploadAttribute.Height > 0)
                    Image1.Height = uploadAttribute.Height;
    
                //var text = new Literal() { Text = "&nbsp;" + FieldValueString.GetFileNameTitle() };
    
                if (uploadAttribute.ShowHyperlink)
                {
                    var hyperlink = new HyperLink()
                    {
                        NavigateUrl = VirtualPathUtility.AppendTrailingSlash(uploadAttribute.UploadFolder) + FieldValueString,
                        Target = "_blank"
                    };
    
                    hyperlink.Controls.Add(Image1);
                    //hyperlink.Controls.Add(text);
    
                    PlaceHolder1.Controls.Add(hyperlink);
                }
                else
                {
                    PlaceHolder1.Controls.Add(Image1);
                    //PlaceHolder1.Controls.Add(text);
                }
            }
    
            public override Control DataControl
            {
                get { return PlaceHolder1; }
            }
        }
    Tuesday, September 13, 2011 7:38 AM
  • User-1712241964 posted

    I grabbed the most recent versions that were available about three weeks ago, vie NuGet of NotAClue.ComponentModel.DataAnnotations.dll, NotAClue.dll, NotAClue.Web.dll, & NotAClue.Web.DynamicData.dll.

    Tuesday, September 13, 2011 7:43 AM
  • User-330204900 posted

    I have found some bugs but not the ones you are seeing, I will try an fix these issues and get an update on NuGet Soon

    Tuesday, September 13, 2011 8:06 AM
  • User-1712241964 posted

    Mr. Stephen,

    NotAClue dlls find themselves added to nearly every project I work on, so...thanks so much for DD adds like this one!

    I did work around the issue by placing both the gridview and problem formview in an UpdatePanel, which, now that I think about it, is probably very appropriate for  what I am doing.    Outside of an UpdatePanel though, the behavior is the same for me regardless of whether the UIHint is utilized in a FormView, DetailsView, etc...

    Tuesday, September 13, 2011 8:57 AM
  • User-330204900 posted

    They should always be in an update pannel I suspoect when outside of an update pannel they are not being refreshed, sot sure why I alway have them inside an update pannel.

    Tuesday, September 13, 2011 8:59 AM
  • User-1712241964 posted

    well...my appologize if I've begun to confuse things...

    looking back at the change I made, and what I wrrote earlier, I worked around the issue by moving the gridview and detailsview that were causing the postback upon row selection into an UpdatePanel, not the FormView that contains the DynamicControl using thr UIHint, thus preventing the page, in it's entirety, from posting back.

    UIHint shown blank after postback for me, whether in an updatepanel or not.

    sorry for the confusion in my earlier post regarding my workaround.

     

    Tuesday, September 13, 2011 12:32 PM
  • User-330204900 posted

    Not a problem I never build a page wihtout my controls in an update pannel. :)

    Tuesday, September 13, 2011 12:35 PM
  • User-1062158585 posted

    follow like below

    http://www.codeproject.com/KB/viewstate/retainingstate.aspx

    Wednesday, September 14, 2011 3:07 PM
  • User-1712241964 posted

    Stephen,

    Just for clarification…. Though I worked around it by putting the other controls on the page in an UpdatePanel to prevent the offending postbacks, would you expect or not expect it to continue to display the image through postbacks?   I may have a need, at some point, to leverage that template inside of an UpdatePanel someday and would like to be prepared to know if any additional mod to the template might be required to have the field display the image as expected beyond the initial page load.

    Konanki,

    Thank you very much for contributing the link.   The info on the page give a good summary of postback behavior, as related to controls.   Please forgive the fact that I am still at a loss though as to how to take any of the code from within that article to apply it in this situation.    What is throwing me is the fact that without the UIHint attribute in the DynamicControl within the FormView’s ItemTemplate, the control persists and displays the appropriate data throughout countless postbacks without the addition of any code to re-generate any of the controls, as described in the article you supplied the link to.   I will dive deeper into figuring out if I need to do some kind of re-generation in the code-behind, specifically for this field template, if Stephen advises that all is working as designed and as expected.   I just very much prefer to keep my implementations of NotAClue code as close to original as possible so that updates are simpler.

    Thanks,
    Gary

     

    Thursday, September 15, 2011 8:49 AM
  • User-330204900 posted

    In my sample from the article all three work fine there are a couple of bugs regarding updating in the sample but the images always show.

    Friday, September 16, 2011 3:51 AM