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

Forums / Developing with Sitefinity / Passing an Internal Link to a User Control

Passing an Internal Link to a User Control

8 posts, 1 answered
  1. RSewell
    RSewell avatar
    54 posts
    Registered:
    25 Apr 2007
    11 Apr 2011
    Link to this post
    I have a user control with a linkbutton that, when clicked, executes some code and then should redirect to a second page.  I do not want to hard-code this link into the user control.  I would rather find a way to pass the target value to the first page through the CMS to tell it which page to redirect to, preferably not in the query string.

    Can this be done?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    11 Apr 2011
    Link to this post
    Hello RSewell,

    You can use cookie/session.

    Greetings,
    Ivan Dimitrov
    the Telerik team

  3. RSewell
    RSewell avatar
    54 posts
    Registered:
    25 Apr 2007
    11 Apr 2011
    Link to this post
    How do I put this value in the cookie/session from the CMS?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    11 Apr 2011
    Link to this post
    Hi RSewell,

    You can get the first page using the API and pass the value to a cookie that you will read when the button is clicked.You can get the current page by using UrlHelper.CmsPageKey.

    Greetings,
    Ivan Dimitrov
    the Telerik team

  5. RSewell
    RSewell avatar
    54 posts
    Registered:
    25 Apr 2007
    11 Apr 2011
    Link to this post
    Thanks for the quick responses, Ivan.

    I don't understand.

    The first page needs to discover the name of the second page so that it can redirect to it.  The name of that second page is defined in the CMS.  I'd like the CMS to pass the name of that page in a value named NextUrl.

    Can I create a property on the user control and set its value through the CMS by editing the control there on the page(s) that contain it?  If I edit the page now with this user control, it shows the public properties and apparently lets me set them. I assume those values are stored in the database, and there is a way to retrieve that value at run-time.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    12 Apr 2011
    Link to this post
    Hi RSewell,

    Can I create a property on the user control and set its value through the CMS by editing the control there on the page(s) that contain it?

    Yes you can, but you said that you didn't want to hardocode the property, so if you want to change it through the UI this will work. If you want to get it dynamically you should use another approach.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Answered
  7. RSewell
    RSewell avatar
    54 posts
    Registered:
    25 Apr 2007
    12 Apr 2011
    Link to this post

    No, that's exactly what I wanted, Ivan.  Thanks.

    The property itself is to be hard-coded, not it's value.

    This may be obvious to most Sitefinity users, but for some reason it wasn't obvious to me until just now.  For anyone else who might benefit, this is what I did:

    In the user control's code-behind, define each property that you want to be able to assign the value from the CMS/UI, like this:

    private string myProperty;
      
    public string MyProperty {
        get {
            return this.myProperty;
        }
        set {
            this.myProperty = value;
        }
    }

    When you drop the user control on a page in the CMS, click its Edit button, and you'll see and be able to change the value of MyProperty.  In my case, this is a hyperlink to another page defined in Sitefinity CMS but which will not appear on any navigation menu.
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    13 Apr 2011
    Link to this post
    Hi RSewell,

    Yes our control designer expose all public properties ( basic types - string, int, boolean etc)

    Regards,
    Ivan Dimitrov
    the Telerik team

Register for webinar
8 posts, 1 answered