Passing parameters between two UserControls
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?
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
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?
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
Hi Ivan,
Please, can you give me examples because I can not really understand how?
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"
);
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
;
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);
void
buttonControl_Click(
object
sender, EventArgs e)
this
.Page.Response.Redirect(
this
.Page.Request.Url.PathAndQuery +
"?something=1"
);
Hello Edward,
You can always get the QueryString using HttpRequest.QueryString.
All the best,
Ivan Dimitrov
the Telerik team
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);
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)
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);
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);
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;