disable an ascx entirely in my web page

T

TJ

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
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
T

TJ

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
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
J

JerryWEC

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
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
S

Sabs

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top