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

Forums / General Discussions / Passing parameters between two UserControls

Passing parameters between two UserControls

13 posts, 1 answered
  1. Millaneli
    Millaneli avatar
    20 posts
    Registered:
    08 Nov 2010
    11 Dec 2010
    Link to this post
    Hi,

    I use two UserControls in my website, is that possible to pass parameters to a UserControl to another. If yes, how can I do?


    Thanks.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Dec 2010
    Link to this post
    Hello Millaneli,

    You can use QueryString, Cookies and Session( Session will be supported with the R, because currently we are having some issues with the session state).

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Millaneli
    Millaneli avatar
    20 posts
    Registered:
    08 Nov 2010
    12 Dec 2010
    Link to this post
    Hi Ivan,

    Thanks for response.


    This is my first experience with Sitefinity, how I use the querystring with Sitefinity 4.0 RC? and especially if I create pages with Sitefinity how I can modify them with Visual Studio 2010?

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Dec 2010
    Link to this post
    Hello Millaneli,

    Sitefinity's pages are dynamically created and there are not physical files that you can modify. Your logic should be done in custom or/and user controls. QueryString keys and Cookies could be set through a control instances on a page.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Millaneli
    Millaneli avatar
    20 posts
    Registered:
    08 Nov 2010
    13 Dec 2010
    Link to this post
    Hi Ivan,

    Please, can you give me examples because I can not really understand how?

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Dec 2010
    Link to this post
    Hello Millaneli,

    Example:

    Custom control 1 -  process request.

    protected override void InitializeControls(System.Web.UI.Control controlContainer)
    {
        base.InitializeControls(controlContainer);
        this.buttonControl.Click += new EventHandler(buttonControl_Click);
        this.buttonControl2.Click += new EventHandler(buttonControl2_Click);
    }
     
     
    void buttonControl_Click(object sender, EventArgs e)
    {
      
        this.Page.Response.Redirect(this.Page.Request.Url.PathAndQuery + "?something=1");
    }
     
    void buttonControl2_Click(object sender, EventArgs e)
    {
      
        this.Page.Response.Redirect(this.Page.Request.Url.PathAndQuery + "?something=2");
     
    }


    Custom control 2 - displays the data:

    protected override void InitializeControls(System.Web.UI.Control controlContainer)
       {
           base.InitializeControls(controlContainer);
     
           if (this.Page != null &&  this.Page.Request.QueryString["something"] != null)
           {
               int number = Int32.Parse(this.Page.Request.QueryString["something"]);
               switch (number)
               {
                   case 1:
                       this.labelControl.Text = "My something 1";
                       break;
                   case 2:
                       this.labelControl.Text = "My something 2";
                       break;
               }
           }
     
       }


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  7. Edward
    Edward avatar
    9 posts
    Registered:
    12 Oct 2012
    21 Sep 2011
    Link to this post
    I am confused.  If the page doesn't exist (which I know it is a 'virtual' file) how can I link to the new page?

    For example, I have a page called Job Postings that hosts a user control that has a GridView list of job postings.  I have a template field with a LinkButton that acts as a 'Select" command.  When this LinkButton is clicked, I would like to be transferred to another page which is called Applicants and it hosts a user control that has a Gridview List of applicants.

    protected void JobPostingsLinkButton_Click (object sender, EventArgs e) 
        {
            String jobID = (String) GridView1.SelectedRow.Cells[0].Text.ToString();
            Response.Redirect("Applicants.aspx?JobID=" + jobID);
        }

    The click event works fine, but when I run the page that hosts this control, I get the following error when trying to pass the JobID to my Applicant page:

    Message: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
    Line: 5
    Char: 62099
    Code: 0

    I did not post the URL for security reasons.

    I do not see how I could possibly use what you posted, because your code knows nothing about my destination page:
    void buttonControl_Click(object sender, EventArgs e) 
        
        this.Page.Response.Redirect(this.Page.Request.Url.PathAndQuery + "?something=1"); 

    Page.Request.Url.PathAndQuery??  I know when I use hyperlinks within Sitefinity it shows a GUID for the page to which I am linking.  I can't figure out how to imitate this functionality from code.
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Sep 2011
    Link to this post
    Hello Edward,

    You can always get the QueryString using HttpRequest.QueryString.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  9. Edward
    Edward avatar
    9 posts
    Registered:
    12 Oct 2012
    21 Sep 2011
    Link to this post
    I don't think you understand.  The error I am getting relates to the destination page.  It does not exist in the file system, as it is a virtual file.  Getting the querystring value once I have arrived at the destination page is not an issue.  It is the Response.Redirect that is causing the problem.

    Response.Redirect("Applicants.aspx?JobID=" + jobID);

    Specifically, how do I redirect my "JobPostings" page to "Applicants".  I tried grabbing the GUID of the page (by setting up a link in a Generic Content control) and replacing "Applicants.aspx" above with the GUID, but that failed as well.
  10. Edward
    Edward avatar
    9 posts
    Registered:
    12 Oct 2012
    21 Sep 2011
    Link to this post
    Would this work?

    // create a new instance of CmsManager
    Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager();
      
    // let's get the page by passing one of it's additional url's
    Telerik.Cms.IPage myPage = cmsManager.GetPageByAdditionalUrl("Applicants.aspx");
      
    // we can cast myPage as ICmsPage and write out its default url and see that it's different
    // from the additional url
    Response.Redirect(myPage + "?JobID=" + JobID)

    I got this from the developer's manual.
  11. Edward
    Edward avatar
    9 posts
    Registered:
    12 Oct 2012
    21 Sep 2011
    Link to this post
    Well, I have it working....  Somewhat.

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
       {
           // get the JobID of the selected row
           GridViewRow row = GridView1.SelectedRow;
           String jobID = (String)row.Cells[0].Text;
           // create a new instance of CmsManager 
           Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager();
           // let's get the page by passing one of it's additional url's 
           Telerik.Cms.ICmsPage myPage = (Telerik.Cms.ICmsPage) cmsManager.GetPageByAdditionalUrl("~/Admin/HRDashboard/Applicants.aspx");
           Response.Redirect(myPage + "?JobID=" + jobID);
       }

    However, this is the URL I get redirected to: "~/Admin/?JobID=1" It doesn't seem to be able to get anything beyond the root.

    What am I doing wrong?
  12. Edward
    Edward avatar
    9 posts
    Registered:
    12 Oct 2012
    21 Sep 2011
    Link to this post
    For anyone that cares to know, I finally did it.  This is the code that worked:

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // get the JobID of the selected row
            GridViewRow row = GridView1.SelectedRow;
            String jobID = (String)row.Cells[0].Text;
      
            // create a new instance of CmsManager 
            Telerik.Cms.CmsManager cmsManager = new Telerik.Cms.CmsManager();
            
            // let's get a reference to the current page.
     
     
       
            Telerik.Cms.Web.CmsSiteMapNode currentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.CurrentNode;
            Telerik.Cms.ICmsPage currentPage = currentNode.GetCmsPage();
            Guid currentPageId = currentPage.ID;
             
            // let's find the page through it's parent (the current page).  
            Telerik.Cms.IPage applicants = cmsManager.GetChildPageByName(currentPageId, "Applicants");

            // let's redirect the page using it's static URL. 
     
            Response.Redirect((((Telerik.Cms.ICmsPage)applicants).StaticUrl) + "?JobID=" + jobID);
        }

    Hope that this helps anyone that has the same problem in the future.
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Sep 2011
    Link to this post
    Hello Edward,

    This part is not necessary

    Telerik.Cms.Web.CmsSiteMapNode currentNode = (Telerik.Cms.Web.CmsSiteMapNode)SiteMap.CurrentNode;
            Telerik.Cms.ICmsPage currentPage = currentNode.GetCmsPage();
            Guid currentPageId = currentPage.ID;


    since you can get the ID of the current page from the context.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
13 posts, 1 answered