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. Problem with userControl

Problem with userControl

Scheduled Pinned Locked Moved ASP.NET
questionhelp
4 Posts 2 Posters 1 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.
  • A Offline
    A Offline
    AnhTin
    wrote on last edited by
    #1

    hi all I am developing a web application. And I have problem with event in UserControl. i have userControl is search.ascx With usercontrol search.ascx have three Control is : two DropDownList (ddlCategory and ddlProduct) and Button(search). in Function Page_Load of search.ascx have function "LoadCategory load all category" for ("ddlCategory"). When user choose category it will Load All Product of category ("ddlProduct") with event ddlCategory_SelectedIndexChanged(). after that user choose product(“ddlProduct”) and finally click button "search". note: ddlCategory is postback = "true" and event ddlCategory_SelectedIndexChanged() ddlProduct is postback = "false" and event SelectedIndexChanged = “” I have a page Default.aspx and in Page_Load UserControl ucl = new UserControl(); divControlLeft.Controls.Clear(); ucl = (UserControl)LoadControl("search.ascx "); divControlLeft.Controls.Add(ucl); but have problem: so it don't get SelectedValue "ddlProduct".and into usercontrol it run to Load_page() function then to ddlCategory_SelectedIndexChanged() finally btlSearch_ServerClick(). "i dont understand why it run to ddlCategory_SelectedIndexChanged() ?????" when i click button search . And the ddlCategory and ddlProduct dont store value when i click search button ??? How can I get value in ddlProduct and don’t run event ddlCategory_SelectedIndexChanged() in search.ascx UserControl ???? Could u show me ??? If i drag usercontrol to “desgin” default.aspx page it run ok !!! it dont run to ddlCategory_SelectedIndexChanged() function when i click to search button and it get value ddlProduct is successful.

    C 1 Reply Last reply
    0
    • A AnhTin

      hi all I am developing a web application. And I have problem with event in UserControl. i have userControl is search.ascx With usercontrol search.ascx have three Control is : two DropDownList (ddlCategory and ddlProduct) and Button(search). in Function Page_Load of search.ascx have function "LoadCategory load all category" for ("ddlCategory"). When user choose category it will Load All Product of category ("ddlProduct") with event ddlCategory_SelectedIndexChanged(). after that user choose product(“ddlProduct”) and finally click button "search". note: ddlCategory is postback = "true" and event ddlCategory_SelectedIndexChanged() ddlProduct is postback = "false" and event SelectedIndexChanged = “” I have a page Default.aspx and in Page_Load UserControl ucl = new UserControl(); divControlLeft.Controls.Clear(); ucl = (UserControl)LoadControl("search.ascx "); divControlLeft.Controls.Add(ucl); but have problem: so it don't get SelectedValue "ddlProduct".and into usercontrol it run to Load_page() function then to ddlCategory_SelectedIndexChanged() finally btlSearch_ServerClick(). "i dont understand why it run to ddlCategory_SelectedIndexChanged() ?????" when i click button search . And the ddlCategory and ddlProduct dont store value when i click search button ??? How can I get value in ddlProduct and don’t run event ddlCategory_SelectedIndexChanged() in search.ascx UserControl ???? Could u show me ??? If i drag usercontrol to “desgin” default.aspx page it run ok !!! it dont run to ddlCategory_SelectedIndexChanged() function when i click to search button and it get value ddlProduct is successful.

      C Offline
      C Offline
      Chetan Ranpariya
      wrote on last edited by
      #2

      Hi, Here u r creating an instance of ur usercontrol in page_load of default.aspx page so it will be created everytime your aspx is loaded. Process of creation of new instance of usercontrol causes page_load of usercontrol to execute hence your ddlcategory will load data again in itself hence it wont preserve its value and so ddlproduct doesnt. The better way it to drang and drop your usercontrol in page then use it. of the second way is use if(!ispostback) block arount your code in page_load. I am not sure the second way will work perfectly but the first option will 100% work. I hope this will help you.

      Thanks and Regards, Chetan Ranpariya

      A 1 Reply Last reply
      0
      • C Chetan Ranpariya

        Hi, Here u r creating an instance of ur usercontrol in page_load of default.aspx page so it will be created everytime your aspx is loaded. Process of creation of new instance of usercontrol causes page_load of usercontrol to execute hence your ddlcategory will load data again in itself hence it wont preserve its value and so ddlproduct doesnt. The better way it to drang and drop your usercontrol in page then use it. of the second way is use if(!ispostback) block arount your code in page_load. I am not sure the second way will work perfectly but the first option will 100% work. I hope this will help you.

        Thanks and Regards, Chetan Ranpariya

        A Offline
        A Offline
        AnhTin
        wrote on last edited by
        #3

        hi Chetan Ranpariya Thank reply to me But i have three usercontrol and search is one of three usercontrol therefore i have to use dynamic usercontrol with code behind So when i use if(!ispostback) with usercontrol search isn't feasible Because When u choose every usercontrol if u user if(!ispostback) it dont run the function on page_load() ex: function loadallcategory on the usercontrol search.ascx Could u show me any way solve this problem.

        C 1 Reply Last reply
        0
        • A AnhTin

          hi Chetan Ranpariya Thank reply to me But i have three usercontrol and search is one of three usercontrol therefore i have to use dynamic usercontrol with code behind So when i use if(!ispostback) with usercontrol search isn't feasible Because When u choose every usercontrol if u user if(!ispostback) it dont run the function on page_load() ex: function loadallcategory on the usercontrol search.ascx Could u show me any way solve this problem.

          C Offline
          C Offline
          Chetan Ranpariya
          wrote on last edited by
          #4

          Hi, Why dont u put 3 usercontrols on different panel controls and make them visible/invisible as per your search criteria? I hope this will help you.

          Thanks and Regards, Chetan Ranpariya

          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