Web user control
-
hi, How to access a web user's control method & property that is placed on webform.aspx. Regards, aB
A user control block should be present on the page if using Vis studio Simply select it and use properties window.
-
A user control block should be present on the page if using Vis studio Simply select it and use properties window.
Thanks, but still i'm not able to get it.:wtf: Here is what i have done: I have created a web user control (MYCTR.ascx) with DropDownList filled with names, to deploy it in default.aspx i put: <%@ Register TagPrefix="Mycomp" TagName="ctl" Src="MYCTR.ascx" %> To add the control in default.aspx i put: "MyComp:Ctl id="MYT" runat="server/" Things are working, but i would like access an item in DropDown list, how do i do ? Regards, aB -- modified at 11:55 Sunday 11th December, 2005
-
Thanks, but still i'm not able to get it.:wtf: Here is what i have done: I have created a web user control (MYCTR.ascx) with DropDownList filled with names, to deploy it in default.aspx i put: <%@ Register TagPrefix="Mycomp" TagName="ctl" Src="MYCTR.ascx" %> To add the control in default.aspx i put: "MyComp:Ctl id="MYT" runat="server/" Things are working, but i would like access an item in DropDown list, how do i do ? Regards, aB -- modified at 11:55 Sunday 11th December, 2005
Hmm, I tried adding things to a drop list and its a lot harder than it seems. Most responses tend to be to set the values in the properties box. This doesnt always work and of course you dont have access to the properties. You could try setting them from within the actual ascx page. Otherwise you will need to do something like the following to manually populate the ddl's
DropDownList5.Items.Clear(); ListItem li5 = new ListItem("",""); DropDownList5.Items.Add(li5); foreach (DataRow dr in ds.Tables["times"].Rows) { //Some code to fills rows} That should do the job.
-
Thanks, but still i'm not able to get it.:wtf: Here is what i have done: I have created a web user control (MYCTR.ascx) with DropDownList filled with names, to deploy it in default.aspx i put: <%@ Register TagPrefix="Mycomp" TagName="ctl" Src="MYCTR.ascx" %> To add the control in default.aspx i put: "MyComp:Ctl id="MYT" runat="server/" Things are working, but i would like access an item in DropDown list, how do i do ? Regards, aB -- modified at 11:55 Sunday 11th December, 2005
????? What do you mean? Youre not making much sense. Sorry! Do you mean that no values / text is displayed in the drop down list?
-
????? What do you mean? Youre not making much sense. Sorry! Do you mean that no values / text is displayed in the drop down list?
ok,:doh: 1.MyCtr.ASCX contains a DDlist with 5 items. 2.Default.ASPX contains one MyButton 3.After deploying MyCtr.ASCX in default.ASPX, i want to get "DDlist.SelectedItem.Text" FROM MyButton_click() Thanks aB -- modified at 13:09 Sunday 11th December, 2005
-
ok,:doh: 1.MyCtr.ASCX contains a DDlist with 5 items. 2.Default.ASPX contains one MyButton 3.After deploying MyCtr.ASCX in default.ASPX, i want to get "DDlist.SelectedItem.Text" FROM MyButton_click() Thanks aB -- modified at 13:09 Sunday 11th December, 2005
ok,
string temp = DropDownList3.SelectedItem.Value;
to get data from drop list. Then you need to tellMyButton_click()
to return the value. So something like:return temp;
-
ok,
string temp = DropDownList3.SelectedItem.Value;
to get data from drop list. Then you need to tellMyButton_click()
to return the value. So something like:return temp;
-
hi, i have found another way to do this: #1) By default DDlist in MYCTR.ASCX is "protected" change it "Public" #2) In default.ASPX, load the control using NewCtr=Loadcontrol("MyCTR.ascx") method #3) ... and now i can access Newctr.DDlist.selecteditem.text Actually this is what i was expecting... thanks for you great support Regards aBaste
-
hi, i have found another way to do this: #1) By default DDlist in MYCTR.ASCX is "protected" change it "Public" #2) In default.ASPX, load the control using NewCtr=Loadcontrol("MyCTR.ascx") method #3) ... and now i can access Newctr.DDlist.selecteditem.text Actually this is what i was expecting... thanks for you great support Regards aBaste
Hi, are their any benefits or otherwise to loading the control in this manner compared to the conventional method i described earlier? Just interested.
-
hi, i have found another way to do this: #1) By default DDlist in MYCTR.ASCX is "protected" change it "Public" #2) In default.ASPX, load the control using NewCtr=Loadcontrol("MyCTR.ascx") method #3) ... and now i can access Newctr.DDlist.selecteditem.text Actually this is what i was expecting... thanks for you great support Regards aBaste
why are you using Loadcontrol method? This is not a good sense. Just put the definition for this control like other controls. for ex: ASPX ==== <%@ Register TagPrefix="Mycomp" TagName="ctl" Src="MYCTR.ascx" %> ... "MyComp:Ctl id="MYT" runat="server" /> CodeBehind =========== protected ctl MYT; in the control definition part. Now u can use MYT.DDlist.selecteditem.text Regards R.Arockiapathinathan