Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > disable an ascx entirely in my web page

Reply
Thread Tools

disable an ascx entirely in my web page

 
 
TJ
Guest
Posts: n/a
 
      07-26-2006
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


 
Reply With Quote
 
 
 
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      07-27-2006
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.

 
Reply With Quote
 
 
 
 
TJ
Guest
Posts: n/a
 
      07-27-2006
Awesome idea! Here's basically what I'm doing:

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

// 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.
>



 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      07-28-2006
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.

 
Reply With Quote
 
JerryWEC
Guest
Posts: n/a
 
      08-01-2006
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


 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      08-02-2006
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.

 
Reply With Quote
 
Sabs
Guest
Posts: n/a
 
      08-29-2006
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
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
begin to parse a web page not entirely downloaded k0mp Python 7 02-08-2007 11:28 PM
How to make a page entirely in C#, no .aspx? sarah ASP .Net 4 03-17-2005 09:59 PM
Multiple *.ascx files with a single *.ascx.cs in VS.NET 2003 Holger (David) Wagner ASP .Net 2 07-03-2004 09:23 AM
can a dg be added to an ascx? ascx call a ws? Jason Shohet ASP .Net 1 11-10-2003 07:08 PM
[ASCX] Add an ascx in a webcontrol... Quentin ASP .Net 1 07-29-2003 07:37 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57