|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Get Value of a control from my Own ControlHello,
i have this code: public class MyControl :System.Web.UI.Control, INamingContainer { protected override void CreateChildControls() { TextBox myTextBox = new TextBox(); myTextBox.ID = "txtMyTextBox"; this.Controls.Add(myTextBox); } } When the page postback how can i do to get the text of myTextBox? Thanks. Handle your control's own Load event or override your OnLoad method. In there,
simply access myTextBox.Text. Oh, this will also require you to move the declaration of mytextBox to be a field of your class. -Brock DevelopMentor http://staff.develop.com/ballen Show quote > Hello, > i have this code: > public class MyControl :System.Web.UI.Control, INamingContainer > { > protected override void CreateChildControls() > { > TextBox myTextBox = new TextBox(); > myTextBox.ID = "txtMyTextBox"; > this.Controls.Add(myTextBox); > } > } > When the page postback how can i do to get the text of myTextBox? > > Thanks. > If I handle the Load event first is raised the Load of the Page and then of
the Control. I want to get value of the TextBox and set tu a property from my control because I want to read the Property of the control when the Page_Load is raised. Thanks Show quote "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message news:388304632483984315595968@msnews.microsoft.com... > Handle your control's own Load event or override your OnLoad method. In there, > simply access myTextBox.Text. Oh, this will also require you to move the > declaration of mytextBox to be a field of your class. > > -Brock > DevelopMentor > http://staff.develop.com/ballen > > > > > Hello, > > i have this code: > > public class MyControl :System.Web.UI.Control, INamingContainer > > { > > protected override void CreateChildControls() > > { > > TextBox myTextBox = new TextBox(); > > myTextBox.ID = "txtMyTextBox"; > > this.Controls.Add(myTextBox); > > } > > } > > When the page postback how can i do to get the text of myTextBox? > > > > Thanks. > > > > > So make a property on your control:
public string Text { get { EnsureChildControls(); return _myText.Text; } set { EnsureChildControls(); _myText.Text = value; } } -Brock DevelopMentor http://staff.develop.com/ballen Show quote > If I handle the Load event first is raised the Load of the Page and > then of the Control. I want to get value of the TextBox and set tu a > property from my control because I want to read the Property of the > control when the Page_Load is raised. > > Thanks > > "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message > news:388304632483984315595968@msnews.microsoft.com... > >> Handle your control's own Load event or override your OnLoad method. >> In >> > there, > >> simply access myTextBox.Text. Oh, this will also require you to move >> the declaration of mytextBox to be a field of your class. >> >> -Brock >> DevelopMentor >> http://staff.develop.com/ballen >>> Hello, >>> i have this code: >>> public class MyControl :System.Web.UI.Control, INamingContainer >>> { >>> protected override void CreateChildControls() >>> { >>> TextBox myTextBox = new TextBox(); >>> myTextBox.ID = "txtMyTextBox"; >>> this.Controls.Add(myTextBox); >>> } >>> } >>> When the page postback how can i do to get the text of myTextBox? >>> Thanks. >>> Thanks, and the last question:
There's no way to get the text of the control when CreateChildControl method is running, because i create another control that depend from the value of myTextBox. Show quote "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message news:389931632484060837028384@msnews.microsoft.com... > So make a property on your control: > > public string Text > { > get > { > EnsureChildControls(); > return _myText.Text; > } > set > { > EnsureChildControls(); > _myText.Text = value; > } > } > > -Brock > DevelopMentor > http://staff.develop.com/ballen > > > > > If I handle the Load event first is raised the Load of the Page and > > then of the Control. I want to get value of the TextBox and set tu a > > property from my control because I want to read the Property of the > > control when the Page_Load is raised. > > > > Thanks > > > > "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message > > news:388304632483984315595968@msnews.microsoft.com... > > > >> Handle your control's own Load event or override your OnLoad method. > >> In > >> > > there, > > > >> simply access myTextBox.Text. Oh, this will also require you to move > >> the declaration of mytextBox to be a field of your class. > >> > >> -Brock > >> DevelopMentor > >> http://staff.develop.com/ballen > >>> Hello, > >>> i have this code: > >>> public class MyControl :System.Web.UI.Control, INamingContainer > >>> { > >>> protected override void CreateChildControls() > >>> { > >>> TextBox myTextBox = new TextBox(); > >>> myTextBox.ID = "txtMyTextBox"; > >>> this.Controls.Add(myTextBox); > >>> } > >>> } > >>> When the page postback how can i do to get the text of myTextBox? > >>> Thanks. > >>> > > > > There's no way to get the text of the control when CreateChildControl I don't quite understand what you're asking. But typically if you need to > method > is running, because i create another control that depend from the > value of > myTextBox. dynamically create controls you need to store some extra state to know/remember how to recreate everything on your page. If you need to dynamically change what's on your page based upon something a user enters, then handle the event for the control that tse user is changing and do your dynamic work there. So if the user changes a DropDownList and that means you add a new control to the form, you should do this in the DropDownList's SelectedIndexChange event. -Brock DevelopMentor http://staff.develop.com/ballen Show quote > Thanks, and the last question: > "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message > news:389931632484060837028384@msnews.microsoft.com... > >> So make a property on your control: >> >> public string Text >> { >> get >> { >> EnsureChildControls(); >> return _myText.Text; >> } >> set >> { >> EnsureChildControls(); >> _myText.Text = value; >> } >> } >> -Brock >> DevelopMentor >> http://staff.develop.com/ballen >>> If I handle the Load event first is raised the Load of the Page and >>> then of the Control. I want to get value of the TextBox and set tu a >>> property from my control because I want to read the Property of the >>> control when the Page_Load is raised. >>> >>> Thanks >>> >>> "Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message >>> news:388304632483984315595968@msnews.microsoft.com... >>> >>>> Handle your control's own Load event or override your OnLoad >>>> method. In >>>> >>> there, >>> >>>> simply access myTextBox.Text. Oh, this will also require you to >>>> move the declaration of mytextBox to be a field of your class. >>>> >>>> -Brock >>>> DevelopMentor >>>> http://staff.develop.com/ballen >>>>> Hello, >>>>> i have this code: >>>>> public class MyControl :System.Web.UI.Control, INamingContainer >>>>> { >>>>> protected override void CreateChildControls() >>>>> { >>>>> TextBox myTextBox = new TextBox(); >>>>> myTextBox.ID = "txtMyTextBox"; >>>>> this.Controls.Add(myTextBox); >>>>> } >>>>> } >>>>> When the page postback how can i do to get the text of myTextBox? >>>>> Thanks. |
|||||||||||||||||||||||