+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / UserControl Not Persisting PostBack values

UserControl Not Persisting PostBack values

2 posts, 0 answered
  1. Bobby
    Bobby avatar
    56 posts
    Registered:
    11 Feb 2009
    07 Oct 2010
    Link to this post
    Hi,

    I am customizing a RadScheduler to have a custom AdvancedInsertTemplate and AdvancedEditTemplate. The templates have some custom fields called Contact, Brief, and Presentation.

    The Contact is just a text box.

    The Brief and Presentation are fields that are defined in a custom user control. The Brief and Presentation are documents that can be uploaded from the user's computer or selected from a document library, i.e. the same code used to insert a link in a RadEditor Window of a Sitefinity Module. The Brief and Presentation are link buttons that point to the document in the document library. initially, when the advanced templates are loaded, the Brief and Presentation links are empty links, for example:

    <a id="briefLink" href=""></a>
    <a id="presentationLink" href=""></a>

    Everything works as expected until cause a post back by trying to save the new event. Before the post back, all of my fields are filled in and my Brief and Presentation links point to the document that was just uploaded to my document library(or an existing one). So, using javascript and reusing the code that is used to insert links in a RadEditor control of a Module, my links look like the following:

    <a id="briefLink" href="some url pointing to the brief document">Brief Title</a>
    <a id="presentationLink" href="some url pointing to the presentation document">Presentation Title</a>


    When I click the Save button in the advanced forms, and look at the Presentation and Brief Links on the server, the links are empty links like on the initial load.

    Do you have any idea of why this would happen?

    The following is the custom user control markup and code behind. This user control is hosted in the advanced insert and edit forms of the RadScheduler. When the save button is clicked, I call thesetAttachmentIDs() function of the custom user control but the links are empty as explained above. Any ideas?

    Thanks in advance,
    Bobby

    Custom User Control
    <%@ Control Language="C#" ClassName="AgendaItemAttachments" %>
     
     
    <telerik:RadScriptBlock ID="scriptBlock" runat="server">
        <script type="text/javascript">
             //<![CDATA[
     
            var currentLinkId = null;
            var briefLinkId = "<%= briefLink.ClientID %>";
            var presentationLinkId = "<%= presentationLink.ClientID %>";
            function openWin() {
                var oWnd = radopen("<%= ((Telerik.Cms.Web.CmsPageBase)Page).ResolveCmsUrl("~/Sitefinity/UserControls/Dialogs/DocumentEditorDialog.aspx") %>", "RadWindow1");
                return false;
            }
     
            function OnClientClose(oWnd, args) {
                //get the transferred arguments
                if(currentLinkId != null){
                    var arg = args.get_argument();
                    if (arg) {
                        arg.id = currentLinkId;
                        $telerik.$("#hiddenCurrentElement").append(arg);
     
                        var val = $telerik.$("[sfref]");
                        $telerik.$("#" + currentLinkId).attr("href", val.attr("href"));
                        $telerik.$("#" + currentLinkId).text(val.html());
                         
                        $telerik.$("#" + currentLinkId).attr("sfref", val.attr("sfref"));
                        $telerik.$("#" + currentLinkId + "ItemSelector").text("Change");
                    }
                }
            }
            //]]>
        </script>
    </telerik:RadScriptBlock>
     
     
     
    <telerik:RadWindowManager ID="RadWindowManager1" ShowContentDuringLoad="false" VisibleStatusbar="false" Modal="true"
        ReloadOnShow="true" runat="server" Skin="Sunset" EnableShadow="true">
        <Windows>
            <telerik:RadWindow ID="RadWindow1" runat="server" Behaviors="Close" OnClientClose="OnClientClose" Width="700" Height="800"
                NavigateUrl='<%= ((Telerik.Cms.Web.CmsPageBase)Page).ResolveCmsUrl("~/Sitefinity/UserControls/Dialogs/DocumentEditorDialog.aspx") %>'>
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
     
    <ul>
        <li>
            <asp:Label ID="briefLabel" runat="server" Text="Brief" />
            <asp:HyperLink ID="briefLink" runat="server" Target="_blank" />
            <asp:LinkButton ID="briefLinkItemSelector" runat="server" OnClientClick="currentLinkId=briefLinkId;openWin();return false;" Text="Change" />
        </li>
        <li>
            <asp:Label ID="presentationLabel" runat="server" Text="Presentation" />
            <asp:HyperLink ID="presentationLink" runat="server" Target="_blank" />
            <asp:LinkButton ID="presentationLinkItemSelector" runat="server" OnClientClick="currentLinkId=presentationLinkId;openWin();return false;" Text="Change"  />
        </li>
    </ul>
     
    <div id="hiddenCurrentElement" style="display:none"/>

    Custom Control Code Behind
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Cms.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using System.IO;
    using Telerik.Cms.Engine.Streaming;
    using Telerik.Libraries;
    using Telerik.Framework.Web;
    using Telerik.Cms.Engine;
     
    namespace Meetings.WebControls.Admin
    {
        public class AgendaItemAttachments : SimpleControl
        {
            LibraryManager libraryManger = null;
            private const string sfRef = "sfRef";
            Guid briefGuid = Guid.Empty;
            Guid presentationGuid = Guid.Empty;
     
            public override string LayoutTemplatePath
            {
                get
                {
                    return "~/Sitefinity/Admin/ControlTemplates/ResearchAreas/AgendaItemAttachments.ascx";
                }
                set
                {
                    base.LayoutTemplatePath = value;
                }
            }
     
            private LibraryManager LibManager
            {
                get
                {
                    if (libraryManger == null)
                        libraryManger = new LibraryManager();
     
                    return libraryManger;
                }
            }
     
            public IAgendaItem AgendaItem
            {
                get
                {
                    return ViewState["AgendaItem"] == null ? null : (IAgendaItem)ViewState["AgendaItem"];
                }
                set
                {
                    ViewState["AgendaItem"] = value;
                }
            }
     
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
            }
     
            protected override void InitializeControls(System.Web.UI.Control controlContainer)
            {
                base.InitializeControls(controlContainer);
     
                if (AgendaItem != null)
                {
                    if (AgendaItem.BriefContent != null)
                    {
                        BriefLink.NavigateUrl = AgendaItem.BriefContent.Url;
                        BriefLink.Attributes[sfRef] = AgendaItem.BriefContent.ID.ToString();
                        BriefLink.Text = AgendaItem.BriefContent.GetMetaData("name") as string;
                        BriefItemSelectorLink.Text = "Change";
                    }
                    else
                    {
                        BriefItemSelectorLink.Text = "Add";
                    }
     
                    if (AgendaItem.PresentationContent != null)
                    {
                        PresentationLink.NavigateUrl = AgendaItem.PresentationContent.Url;
                        PresentationLink.Attributes[sfRef] = AgendaItem.PresentationContent.ID.ToString();
                        PresentationLink.Text = "Presentation";
                        PresentationItemSelectorLink.Text = "Change";
                    }
                    else
                    {
                        PresentationItemSelectorLink.Text = "Add";
                    }
                }
                else
                {
                    BriefItemSelectorLink.Text = "Add";
                    PresentationItemSelectorLink.Text = "Add";
                }
                 
            }
     
            private HyperLink BriefLink
            {
                get
                {
                    return base.Container.GetControl<HyperLink>("briefLink", true);
                }
            }
     
            private HyperLink PresentationLink
            {
                get
                {
                    return base.Container.GetControl<HyperLink>("presentationLink", true);
                }
            }
     
            private LinkButton BriefItemSelectorLink
            {
                get
                {
                    return base.Container.GetControl<LinkButton>("briefLinkItemSelector", true);
                }
            }
     
            private LinkButton PresentationItemSelectorLink
            {
                get
                {
                    return base.Container.GetControl<LinkButton>("presentationLinkItemSelector", true);
                }
            }
     
            public Guid BriefGuid
            {
                get
                {
                    return briefGuid;
                }
            }
     
            public Guid PresentationGuid
            {
                get
                {
                    return presentationGuid;
                }
            }
     
            public void setAttachmentIDs()
            {
                string presentationSfref = PresentationLink.Attributes[sfRef];
                string briefSfref = BriefLink.Attributes[sfRef];
     
                if (!string.IsNullOrEmpty(presentationSfref))
                {
                    if (presentationSfref.Contains("[" + LibManager.DefaultProvider + "]"))
                    {
                        presentationSfref = presentationSfref.Replace("[" + LibManager.DefaultProvider + "]", string.Empty);
                    }
     
                    presentationGuid = new Guid(presentationSfref);
                }
     
                if (!string.IsNullOrEmpty(briefSfref))
                {
                    if (briefSfref.Contains("[" + LibManager.DefaultProvider + "]"))
                    {
                        briefSfref = briefSfref.Replace("[" + LibManager.DefaultProvider + "]", string.Empty);
                    }
     
                    briefGuid = new Guid(briefSfref);
                }
            }
        }
    }
  2. Bobby
    Bobby avatar
    56 posts
    Registered:
    11 Feb 2009
    08 Oct 2010
    Link to this post
    Hi,

    You can close this post. I had to use a hidden asp.net control to store the information I wanted posted back to the server instead of using a LinkButton server control.

    Thanks,
    Bobby
2 posts, 0 answered