Generating usercontroll programatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ghayas
    New Member
    • Apr 2010
    • 6

    Generating usercontroll programatically

    I m generating usercontroll programaticlly but it is not visible on the page,
    can any body tell me where i m making mistake

    code written in code behind file is below

    Code:
    Private UCInvoiceDetail As ASP.InvoicingDetail
    UCInvoiceDetail = CType(LoadControl("~/InvoicingDetail.ascx"), ASP.InvoicingDetail)
    UCInvoiceDetail.ID = "UC3"
    UCPlaceHolder.Controls.Add(UCInvoiceDetail)
    thanks in advance
    Last edited by Frinavale; Apr 16 '10, 01:19 PM. Reason: Please post code in [code]...[/code] tags. Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Try moving lines 2 - 4 into the Page Init event.
    For an explanation of why I suggested this please review the article on how to use dynamic controls in asp.net

    -Frinny

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by Ghayas
      no resultt,
      same as previous one,
      code is working fine
      i have checked it the control is being created properly but unable to see it means not visible,

      anyways thanks for your time,
      if u find something then plz let me know
      Hi Ghayas,
      Please respond in thread instead of through PMs so that when we find a solution to the problem other people facing the same problem can see how we solved the problem :)

      This is very strange behaviour.
      Have you tried setting the Visible property of the control to true to make sure it's rendered...on second thought, are you sure it's not being rendered? (check the HTML and see if you can see the control in the page...maybe you have a style setting or something messing this up).

      -Frinny

      Comment

      • Ghayas
        New Member
        • Apr 2010
        • 6

        #4
        sorry i didnt know where to answer so i send u PM
        i don know what was the problem i removed update panel ,
        may b may b infact the actual reason was,i have update panel in which i have a check box and on check event the control creation occur,and i made blander that i didnt put the update panel for place holder

        thankx alot for your time

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Oh.
          I don't think this is going to work.

          I remember a thread a while ago discussing issues with this and I don't think that it was resolved.

          I recommend staying away from dynamically loading the control when using UpdatePanels. Set the control's Visible property to false and when you need it set it to true instead of trying to add it dynamically when needed.

          When a control's Visible property is set in your sever side code (C# or VB.NET) then the control is not rendered on the page....it's omitted...until you set the Visible property to true.

          -Frinny

          Comment

          • Ghayas
            New Member
            • Apr 2010
            • 6

            #6
            actually its clients requirement,
            to use ajax

            Comment

            • Frinavale
              Recognized Expert Expert
              • Oct 2006
              • 9749

              #7
              For now, to get things up and running, don't dynamically add the control to the page. Instead try using the Visible property I was talking about in my last post.

              -Frinny

              Comment

              Working...