Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. adding user controls to webform

adding user controls to webform

Scheduled Pinned Locked Moved ASP.NET
winformstutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jetset32
    wrote on last edited by
    #1

    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!

    M 1 Reply Last reply
    0
    • J jetset32

      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!

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Hi there. You could already have your UserControl declared in a Panel with Visible = false, then upon page load test Request.QueryString["ProductID"] to determine its passed in value. If a legitimate ProductID is passed in, you could set the Panel.Visible to true and populate the UserControl as necessary. Or, instead of declaring your UserControl, you could also put a PlaceHolder control on your page where the UserControl would be created, then create it in code with the LoadControl 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 ...
      }
      }

      J 1 Reply Last reply
      0
      • M Mike Ellison

        Hi there. You could already have your UserControl declared in a Panel with Visible = false, then upon page load test Request.QueryString["ProductID"] to determine its passed in value. If a legitimate ProductID is passed in, you could set the Panel.Visible to true and populate the UserControl as necessary. Or, instead of declaring your UserControl, you could also put a PlaceHolder control on your page where the UserControl would be created, then create it in code with the LoadControl 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 ...
        }
        }

        J Offline
        J Offline
        jetset32
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • J jetset32

          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

          M Offline
          M Offline
          Mike Ellison
          wrote on last edited by
          #4

          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 the ItemCommand, determine which item has been clicked using the DataListCommandEventArgs object passed to the handler, and show & populate an otherwise hidden UserControl already declared on the DataList's page (rather than link to a second page). Just another approach.

          J 1 Reply Last reply
          0
          • M Mike Ellison

            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 the ItemCommand, determine which item has been clicked using the DataListCommandEventArgs object passed to the handler, and show & populate an otherwise hidden UserControl already declared on the DataList's page (rather than link to a second page). Just another approach.

            J Offline
            J Offline
            jetset32
            wrote on last edited by
            #5

            Im gonna try for your second approach, im just struggling with obtaining the product ID when the user would select a product image..... I'll get their ! Thanks again for your help Jetset

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups