adding user controls to webform
-
Is it possible to add user controls to a webform by extending the URL. for example. The datalist menu has a url of http://localhost/touchofglass/Glass.aspx?SubCatID=1990&selection=2 I want to add user controls to this page displaying product information. possibly using a placeholder and a .ascx file??? but the url would be http://localhost/touchofglass/Glass.aspx?SubCatID=1990&selection=2&ProductID=120&selection=40 The product info has been added to the url. This way the original datalist menu stays on the page together with new user controls Is this known as a postback method? Thanks in advance!
-
Is it possible to add user controls to a webform by extending the URL. for example. The datalist menu has a url of http://localhost/touchofglass/Glass.aspx?SubCatID=1990&selection=2 I want to add user controls to this page displaying product information. possibly using a placeholder and a .ascx file??? but the url would be http://localhost/touchofglass/Glass.aspx?SubCatID=1990&selection=2&ProductID=120&selection=40 The product info has been added to the url. This way the original datalist menu stays on the page together with new user controls Is this known as a postback method? Thanks in advance!
Hi there. You could already have your
UserControl
declared in aPanel
withVisible
=false
, then upon page load testRequest.QueryString["ProductID"]
to determine its passed in value. If a legitimate ProductID is passed in, you could set thePanel.Visible
to true and populate theUserControl
as necessary. Or, instead of declaring yourUserControl
, you could also put aPlaceHolder
control on your page where theUserControl
would be created, then create it in code with theLoadControl
method. Something like this:void Page_Init(object sender, EventArgs e)
{
if (Request.QueryString["ProductID"] != "")
{
MyUserControl u = (MyUserControl) LoadControl("myUserControl.ascx");
myPlaceHolder.Controls.Add(u);
// ... populate the MyUserControl object with data ...
}
} -
Hi there. You could already have your
UserControl
declared in aPanel
withVisible
=false
, then upon page load testRequest.QueryString["ProductID"]
to determine its passed in value. If a legitimate ProductID is passed in, you could set thePanel.Visible
to true and populate theUserControl
as necessary. Or, instead of declaring yourUserControl
, you could also put aPlaceHolder
control on your page where theUserControl
would be created, then create it in code with theLoadControl
method. Something like this:void Page_Init(object sender, EventArgs e)
{
if (Request.QueryString["ProductID"] != "")
{
MyUserControl u = (MyUserControl) LoadControl("myUserControl.ascx");
myPlaceHolder.Controls.Add(u);
// ... populate the MyUserControl object with data ...
}
}Thanks for your quick response! I'm gonna use a placeholder and then load in the web controls with data from product database. My next question would be; My datalist is using Imagebuttons but as their is no NavigateURL property on an Imagebutton would I be able to do a postback using this? I think I use a Hyperlink Control, is this correct? and from the Navigate URL property i could use request.querystring to load the correct data into web controls? sorry to be a pain! Thanks Jetset
-
Thanks for your quick response! I'm gonna use a placeholder and then load in the web controls with data from product database. My next question would be; My datalist is using Imagebuttons but as their is no NavigateURL property on an Imagebutton would I be able to do a postback using this? I think I use a Hyperlink Control, is this correct? and from the Navigate URL property i could use request.querystring to load the correct data into web controls? sorry to be a pain! Thanks Jetset
Hi there. So I'm getting that your user would click the image link in the datalist, which would open a new page that would load the UserControl and display the details, yes? I think the approach you're talking about here would work for that. You might also consider looking into the DataList.ItemCommand[^] event.
ItemCommand
fires when a button has been clicked in the DataList. You could code an event handler for theItemCommand
, determine which item has been clicked using theDataListCommandEventArgs
object passed to the handler, and show & populate an otherwise hiddenUserControl
already declared on the DataList's page (rather than link to a second page). Just another approach. -
Hi there. So I'm getting that your user would click the image link in the datalist, which would open a new page that would load the UserControl and display the details, yes? I think the approach you're talking about here would work for that. You might also consider looking into the DataList.ItemCommand[^] event.
ItemCommand
fires when a button has been clicked in the DataList. You could code an event handler for theItemCommand
, determine which item has been clicked using theDataListCommandEventArgs
object passed to the handler, and show & populate an otherwise hiddenUserControl
already declared on the DataList's page (rather than link to a second page). Just another approach.