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

Forums / Developing with Sitefinity / SimpleControl with Control Designer not saving properties

SimpleControl with Control Designer not saving properties

5 posts, 0 answered
  1. Pavliks
    Pavliks avatar
    68 posts
    Registered:
    06 Apr 2010
    04 Sep 2009
    Link to this post
    Hi,

    Here's the scenario. I have a control that inherits Telerik.Cms.Web.UI.SimpleControl, with this control I also applied a ControlDesigner both have embedded templates. I can get this all working without too much difficulty and it works well until I do the following.

    I have a pretty big chunk of javascript for the control designer and if the javascript resides in the control designer template it works and all of the properties save for the base control. The problem is the the script needs access to some clientIDs, injecting them with <% %> does not work so I found myself stringing the javascript together on the server side to gain access to the clientIDs from here I register the script with RegisterClientScriptBlock. Compile it add it to my Sitefinity implementation and run it. The javascript again runs as expected with the ClientIDs but now the base control properties won't save when the I'm Done button is clicked.

    Any Ideas?

    Thanks,
    Steve
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    06 Sep 2009
    Link to this post
    Hello S. Webb,

    Do you use ViewState properties? Any result form the debugger? Can you share some code that illustrates this behavior.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Pavliks
    Pavliks avatar
    68 posts
    Registered:
    06 Apr 2010
    08 Sep 2009
    Link to this post
    Hi Ivan,

    I can't share the exact code but I have created a small sample that illustrates the same behaviour. It can be downloaded here www.stevewebb.ca/ClassLibrary1.zip.

    If this is compiled it will work as intended and it will have the TextSample property save it's value.

    If you uncomment the "RegisterScripts()" call in BasicControlDesigner.cs under InitializeControls it will no longer save the value.

    As you can see I'm not really doing anything with the javascript in this sample except pass a ClientID.

    Thanks Ivan,

    Steve
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    14 Sep 2009
    Link to this post
    Hi S. Webb,

    Please modify BasicControlDesigner as below:

       protected override void OnPreRender(EventArgs e) 
            { 
                base.OnPreRender(e); 
                RegisterScripts(); 
            } 
     
     
            protected override void InitializeControls(System.Web.UI.Control viewContainer) 
            { 
                    txtTest.Text = ((BasicControl)DesignedControl).TextSample; 
            } 
     
            private void RegisterScripts() 
            { 
     
                string strScript = "var stxtTestID = '" + txtTest.ClientID + "';"
     
                if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "TestScript")) 
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"TestScript", strScript, true); 
     
            } 
     
            public override void OnSaving()     
            {         
                // Set the underlying control properties to the new values.         
                ((BasicControl) DesignedControl).TextSample = txtTest.Text; 
            } 


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Pavliks
    Pavliks avatar
    68 posts
    Registered:
    06 Apr 2010
    14 Sep 2009
    Link to this post
    Hi Ivan,

    Of course, I should have known that.

    Thanks for you time,
    Steve
Register for webinar
5 posts, 0 answered