|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Add UserControl on CodeBeheindHi,
I've such a problem. I need to add my UserControl not on design time but on Codebehind, so I prepare: private void Page_Load(object sender, System.EventArgs e) { MyUserControl myUserControl = new MyUserControl(); this.Controls.Add(myUserControls); } But actually that doesn’t work. After requesting my page on a browser, there aren’t shown any controls putted on myUserControl. Also it is thrown an exception of null reference if I tried to modify anything in codebehind of components putted in myUserControl, when he is added in such a way. Any suggestions ? Regards Krzysztof Karnicki are you adding myUserControls or myUserControl?
Show quoteHide quote "Krzysztof Karnicki" wrote: > Hi, > I've such a problem. I need to add my UserControl not on design time but on > Codebehind, so I prepare: > > private void Page_Load(object sender, System.EventArgs e) { > MyUserControl myUserControl = new MyUserControl(); > this.Controls.Add(myUserControls); > } > > But actually that doesn’t work. After requesting my page on a browser, there > aren’t shown any controls putted on myUserControl. Also it is thrown an > exception of null reference if I tried to modify anything in codebehind of > components putted in myUserControl, when he is added in such a way. Any > suggestions ? > > > Regards > Krzysztof Karnicki > Hi,
I'm adding myUserControl, wich is the instance of class inhriting from the System.Web.UI.UserControl. Show quoteHide quote "Jason L Lind" wrote: > are you adding myUserControls or myUserControl? > > "Krzysztof Karnicki" wrote: > > > Hi, > > I've such a problem. I need to add my UserControl not on design time but on > > Codebehind, so I prepare: > > > > private void Page_Load(object sender, System.EventArgs e) { > > MyUserControl myUserControl = new MyUserControl(); > > this.Controls.Add(myUserControls); > > } > > > > But actually that doesn’t work. After requesting my page on a browser, there > > aren’t shown any controls putted on myUserControl. Also it is thrown an > > exception of null reference if I tried to modify anything in codebehind of > > components putted in myUserControl, when he is added in such a way. Any > > suggestions ? > > > > > > Regards > > Krzysztof Karnicki > > On Wed, 13 Jul 2005 02:26:01 -0700, Krzysztof Karnicki
<KrzysztofKarni***@discussions.microsoft.com> wrote: Show quoteHide quote >Hi, Try putting a PlaceHolder control on your form at design time, and>I've such a problem. I need to add my UserControl not on design time but on >Codebehind, so I prepare: > >private void Page_Load(object sender, System.EventArgs e) { > MyUserControl myUserControl = new MyUserControl(); > this.Controls.Add(myUserControls); >} > >But actually that doesn’t work. After requesting my page on a browser, there >aren’t shown any controls putted on myUserControl. Also it is thrown an >exception of null reference if I tried to modify anything in codebehind of >components putted in myUserControl, when he is added in such a way. Any >suggestions ? > > >Regards >Krzysztof Karnicki then Add your control to it, rather than adding it to the page's Controls collection. Hi,
When I try implement Yous sugestion: WebUserControl1 webUserControl = new WebUserControl1(); this.PlaceHolder1.Controls.Add(webUserControl); he same situation occurs. Because webUserControl try to change Text property of Label putted on my control, requesting page throws an null excpetion. Regards, Krzysztof Karnicki Show quoteHide quote "Wilbur Slice" wrote: > On Wed, 13 Jul 2005 02:26:01 -0700, Krzysztof Karnicki > <KrzysztofKarni***@discussions.microsoft.com> wrote: > > >Hi, > >I've such a problem. I need to add my UserControl not on design time but on > >Codebehind, so I prepare: > > > >private void Page_Load(object sender, System.EventArgs e) { > > MyUserControl myUserControl = new MyUserControl(); > > this.Controls.Add(myUserControls); > >} > > > >But actually that doesn’t work. After requesting my page on a browser, there > >aren’t shown any controls putted on myUserControl. Also it is thrown an > >exception of null reference if I tried to modify anything in codebehind of > >components putted in myUserControl, when he is added in such a way. Any > >suggestions ? > > > > > >Regards > >Krzysztof Karnicki > > > Try putting a PlaceHolder control on your form at design time, and > then Add your control to it, rather than adding it to the page's > Controls collection. > > > >
IExtenderProvider
Please Help: ListBox.SelectedItem returns null Can aspnet simulate windows pane separator? Error: Multiple controls with the same ID a dropdown list in the "Properties" window ListItem individual Color Collection with the correct object type on the Collection dialog DropDownList <optgroup> Setting control value in Javascript asp.net 2.0: Webcontrols in Library |
|||||||||||||||||||||||