disable an ascx entirely in my web page

Discussion in 'ASP .Net Web Controls' started by TJ, Jul 26, 2006.

  1. TJ

    TJ Guest

    I have a page that has an .ascx. I want to use it most of the time, but
    sometimes I don't and just setting it's 'visible' property to false doesn't
    cut it because I want it not to be touched at all (because in certain
    situations if the page tries to render it, it blows up because sometimes I
    don't have all the data required yet to make it work).

    So is there a way to completely disable/stop the rendering of an .ascx on a
    web form (.aspx)?

    Thx in advance,
    - T
    TJ, Jul 26, 2006
    #1
    1. Advertising

  2. Hi,

    Thank you for your post.

    Based on my understanding, your question is how to conditionally
    load/render a UserControl. If I've misunderstood anything, please feel free
    to post here.

    I think you can dynamically load the UserControl into the WebForm rather
    than declaratively use it. You can replace the UserControl with a
    PlaceHolder on the WebForm, and use LoadControl() to load the UserControl
    and add it to the PlaceHolder.

    Hope this helps. Please feel free to post here if anything is unclear.

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Jul 27, 2006
    #2
    1. Advertising

  3. TJ

    TJ Guest

    Awesome idea! Here's basically what I'm doing:

    // Code for Adding the User Control
    PlaceHolder1.Controls.Add(LoadControl("taclient.ascx"));

    // Code for Removing the UserControl
    Control myControl = PlaceHolder1.Controls[0];
    PlaceHolder1.Controls.Remove(myControl);

    Thanks again,

    - TJ


    "Walter Wang [MSFT]" <> wrote in message
    news:...
    > Hi,
    >
    > Thank you for your post.
    >
    > Based on my understanding, your question is how to conditionally
    > load/render a UserControl. If I've misunderstood anything, please feel
    > free
    > to post here.
    >
    > I think you can dynamically load the UserControl into the WebForm rather
    > than declaratively use it. You can replace the UserControl with a
    > PlaceHolder on the WebForm, and use LoadControl() to load the UserControl
    > and add it to the PlaceHolder.
    >
    > Hope this helps. Please feel free to post here if anything is unclear.
    >
    > Regards,
    > Walter Wang (, remove 'online.')
    > Microsoft Online Community Support
    >
    > ==================================================
    > When responding to posts, please "Reply to Group" via your newsreader so
    > that others may learn and benefit from your issue.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
    TJ, Jul 27, 2006
    #3
  4. Hi,

    Appreciate your update and response. I am glad to hear that the problem has
    been fixed. If you have any other questions or concerns, please do not
    hesitate to contact us. It is always our pleasure to be of assistance.

    Have a nice day!

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Jul 28, 2006
    #4
  5. TJ

    JerryWEC Guest

    Is this PlaceHolder a new control in VS2005? Good tip on the LoadControl()
    and Remove() methods!!!

    I used the following method in a UserControl in FlowLayout to hide it while
    not in use. Seting the display attribute to none will remove it from the
    flow and not take up space...

    Private Sub Hide()
    'JLM 21July2006 - Set the containing Panel control's style.Display
    attribute.

    Try 'JLM 21July2006 - Setting display attribute to "none" will not take
    up space in the flow of a FlowLayout web page.

    pnlMsgBox.Attributes("display") = "none"

    Catch ex As Exception

    DisplayError("Error in FlowMsgBox::Hide() Method. - " & ex.Message,
    ex.StackTrace)

    End Try

    End Sub

    'JLM - Set the Style.Display attribute to Block to Show UserControl.

    Private Sub Show()

    'Set the containing Panel control's style.Display attribute.

    Try

    pnlMsgBox.Attributes("display") = "block"

    Catch ex As Exception

    DisplayError("Error in FlowMsgBox::Show() Method. - " & ex.Message,
    ex.StackTrace)

    End Try

    End Sub

    If anyone knows why the pasted code looses it formating (intentation level)
    please let me know. I manually intented this code after pasting it into the
    post.

    Thanks JerryM
    JerryWEC, Aug 1, 2006
    #5
  6. Hi Jerry,

    The PlaceHolder is available in VS2003 too.

    To maintain the code indentation, you may need to instruct your code editor
    to use spaces instead of TAB.

    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Aug 2, 2006
    #6
  7. TJ

    Sabs Guest

    TJ,

    Also, if the UserControl is declaratively (as opposed to programmatically)
    rendered in your ASPX page, you can disable it by enclosing the control in
    these comments: <%-- %--> instead of these: <!-- -->. This will completely
    disable any web server controls (not only UserControls) to prevent it from
    running without removing it from the page (thus breaking references).

    Hope that helps,
    -Sabrina

    "TJ" wrote:

    > I have a page that has an .ascx. I want to use it most of the time, but
    > sometimes I don't and just setting it's 'visible' property to false doesn't
    > cut it because I want it not to be touched at all (because in certain
    > situations if the page tries to render it, it blows up because sometimes I
    > don't have all the data required yet to make it work).
    >
    > So is there a way to completely disable/stop the rendering of an .ascx on a
    > web form (.aspx)?
    >
    > Thx in advance,
    > - T
    >
    >
    >
    Sabs, Aug 29, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom wilson
    Replies:
    2
    Views:
    2,621
    Tom wilson
    Feb 11, 2005
  2. sarah
    Replies:
    4
    Views:
    7,848
    Brock Allen
    Mar 17, 2005
  3. Neil Monk

    Entirely HTML only forums?

    Neil Monk, Feb 20, 2004, in forum: HTML
    Replies:
    12
    Views:
    583
    Chris Morris
    Feb 24, 2004
  4. k0mp
    Replies:
    7
    Views:
    257
  5. TGOS
    Replies:
    4
    Views:
    519
    Old Wolf
    Nov 8, 2004
Loading...

Share This Page