|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
disable an ascx entirely in my web pageI 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 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 (waw***@online.microsoft.com, 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. 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 Show quoteHide quote "Walter Wang [MSFT]" <waw***@online.microsoft.com> wrote in message news:OHX74ZSsGHA.4424@TK2MSFTNGXA01.phx.gbl... > 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 (waw***@online.microsoft.com, 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. > 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 (waw***@online.microsoft.com, 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. 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 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 (waw***@online.microsoft.com, 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,
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 Show quoteHide quote "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 > > >
Stopping Attributes.Add from converting my JavaScript event code to HTML
GridViewRow FindControl failing ATTN MS: GridView improvements GridView ScrollBar Stop Postback in image button Page with User control loads twice. Expandable Section sumbit server form to another page Rename ID in Properties Window Crystal report in VS 2005 Professional |
|||||||||||||||||||||||