locked
Controls in updatepanel dissapears after postback with VS2013 but not in VS2012 with same framework RRS feed

  • Question

  • User-893491232 posted

    We have made a custom asp.net web user control that we use for opening dialogs. It was written in Visual Studio 2012 with .NET Framework 4.0. Now that we have upgraded our computers with Visual Studio 2013 (still using .NET 4.0), it does not work anymore.

    Added controls into the UpdatePanel disappear when a postback occur in the updatepanel. It consists of a panel with hidden textbox and button, a content panel and Itemplate. We simplified an example control just to make a quick test.

    When the hidden button is clicked, the hidden textbox and button disappear along with the content panel. It does not render into the UI anymore. The control is working with VS2012 and .NET 4.0 but not with VS2013 and .NET 4.0. Tried to change to .NET 4.5 and .NET 4.5.1 but still the same result.

    using System;
    using System.Web.UI;
    
    namespace MyWeb.UI.WebControls
    {
        [PersistChildren(false)]
        [ParseChildren(true)]
        public class MyDialog : Panel
        {
            [PersistenceMode(PersistenceMode.InnerProperty)]
            [TemplateInstance(TemplateInstance.Single)]
            public ITemplate ContentTemplate { get; set; }
    
            protected override void OnInit(EventArgs e)
            {
                UpdatePanel up = new UpdatePanel();
                up.ID = "DialogUpdatePanel1";
                this.Controls.Add(up);
    
                Panel p = new Panel();
                p.ID = "DialogPostBackPanel1";
                //p.Style.Add(HtmlTextWriterStyle.Display, "none");
                p.Style.Add(HtmlTextWriterStyle.Padding, "15px");
                p.Controls.Add(new TextBox());
                p.Controls.Add(new Button());
                up.ContentTemplateContainer.Controls.Add(p);
    
                Panel c = new Panel();
                c.ID = "ContentPanel1";
                c.CssClass = "dialog-content";
                if (this.ContentTemplate != null) this.ContentTemplate.InstantiateIn(c);
                up.ContentTemplateContainer.Controls.Add(c);
    
                base.OnInit(e);
            }
    
            protected override void AddAttributesToRender(HtmlTextWriter writer)
            {
                this.CssClass = (string.IsNullOrEmpty(this.CssClass)) ? "dialog drop-shadow" : string.Format("dialog drop-shadow {0}", this.CssClass);
                base.AddAttributesToRender(writer);
            }
        }
    }
    
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <mm:MyDialog ID="MyDialog1" runat="server" Width="200px" Height="300px">
        <ContentTemplate>
            <asp:TextBox runat="server" />
            <asp:TextBox runat="server" />
            <asp:TextBox runat="server" />
        </ContentTemplate>
    </mm:MyDialog>

    When loading the page the HTML is:

    <div id="ctl00_AppHolder_MyDialog1" class="dialog drop-shadow" style="height:300px;width:200px;">
        <div id="ctl00_AppHolder_DialogUpdatePanel1">
            <div id="ctl00_AppHolder_DialogPostBackPanel1" style="padding:15px;">
                <input name="ctl00$AppHolder$ctl02" type="text" /><input type="submit" name="ctl00$AppHolder$ctl03" value="" />
            </div>
            <div id="ctl00_AppHolder_ContentPanel1" class="dialog-content">
                <input name="ctl00$AppHolder$ctl04" type="text" />
                <input name="ctl00$AppHolder$ctl05" type="text" />
                <input name="ctl00$AppHolder$ctl06" type="text" />
            </div>
        </div>
    </div>

    When clicking the button inside the UpdatePanel (with VS2013) the HTML is:

    <div id="ctl00_AppHolder_MyDialog1" class="dialog drop-shadow" style="height:300px;width:200px;">
        <div id="ctl00_AppHolder_DialogUpdatePanel1">
            <input name="ctl00$AppHolder$ctl04" type="text" />
            <input name="ctl00$AppHolder$ctl05" type="text" />
            <input name="ctl00$AppHolder$ctl06" type="text" />
        </div>
    </div>

    Using

    Visual Studio 2012 Version 11.0.61030.00 Update 4

    Visual Studio 2013 Version 12.0.30119.00 Update 1

    Friday, April 11, 2014 3:15 AM

All replies

  • User697462465 posted

    Hi mikaelAFC,

    According to your code, I have not found the open dialog code, so do you have use the javascript plugin or others?

    So, please make more details about the dialog how to work.

    Your custome control only create some controls and add some attributes, but not define the onclick event.

    Best Regards,
    Terry Guo

    Sunday, April 13, 2014 10:42 PM
  • User-893491232 posted

    Hi Terry,

    The javascript code for showing/opening the dialog is not relavent to the error that occurs. The problem is in the server code that I provided. In our code we click the button with simple jquery and the panel has of course css display:none, but you can simulate the error with a click with the mouse.

    The code that I provided is a small portion of our code that demonstrate the error. That is, controls dissapears after the BUTTON is clicked and a updatepanel postback occurs when running on Visual Studio 2013 with .NET Framework 4.0, but not in Visual Studio 2012 with .NET Framework 4.0. What I did was to minimize the amount of code to emulate the error.

    Best regards,

    Mikael

    Monday, April 14, 2014 7:32 AM