get value of ddl, txtbox, calendar used in user control on main page using findcontrol in asp.net c#? -
i want task in want using findcontrol during use of webusercontrol on web form value of webusercontrol on main page mean, i've created webusercontrol , have used on web form. in webusercontrol.ascx page use textbox, calendar, , dropdownlist. want value(which choose txtbox, ddl etc) should display on main page. mean, want use button on default.aspx page , in variable want store value of txtbox, calendar etc. , using findcontrol want these values on main page. how can plz me code plz i'm new in programing.
this code of ascx page <%@ control language="c#" classname="calendarusercontrol" %> <asp:textbox id="txtdata" runat="server"></asp:textbox> <br /> <asp:calendar id="calendar1" runat="server" backcolor="beige" > </asp:calendar> <br/> <asp:dropdownlist id="ddlthings" runat="server"> <asp:listitem> apple</asp:listitem> <asp:listitem> banana</asp:listitem> <asp:listitem> mango</asp:listitem> <asp:listitem> grapes</asp:listitem> </asp:dropdownlist> default.aspx page <div> <uc1:calendarusercontrol id="calendarusercontrol1" runat="server" /> <br /> <asp:button id="button1" runat="server" onclick="btn_click" text="button" /> <br /> <asp:label id="label1" runat="server" text="label"></asp:label> </div>
define properties in user control, return values of controls want. example
public partial class calendarusercontrol: usercontrol { // code-behind of user control public string data { {return txtdata.text;} } public datetime calendardate { {return calendar1.selecteddate;} } // same approach drop down list ddlthings }
then in aspx page, read values, example in btn_click
event handler
protected void btn_click(object sender, eventargs e) { var textboxvalue = calendarusercontrol1.data; var calendarvalue = calendarusercontrol1.calendardate; //.... }
Comments
Post a Comment