Hi, I have already googled a bit and couldn't find the answer. I have a user control that contain sql data source and a grid view. I would like to enable enter the parameters to my user control through th aspx page like that: <uc:myControl .........> <parameter...../>
..... </uc:myControl> Is there any way to do this or not? thanks alot
duzi
Member
355 Points
90 Posts
User control
Aug 30, 2011 11:42 AM|LINK
gopalanmani
Star
7826 Points
1320 Posts
Re: User control
Aug 30, 2011 12:24 PM|LINK
Hi,
First create a public property in the user control and public method to access from the .aspx page
I would like to suggest you to check the sample below which describes how to pass values from a page to a WebUserControl by using public properties.
1.Create a WebUserControl(suppose it is named as WebUserControl.ascx)
Code in WebUserControl.ascx:
Code in WebUserControl.ascx.cs:
2.Code in page which contains the WebUserControl:
.aspx file:
.cs file:
and also check the following url,
http://www.java2s.com/Tutorial/ASP.NET/0280__Custom-Controls/Usercontrolwithproperty.htm
Hope it can help you.
Gopalan Mani
My Tech blog
duzi
Member
355 Points
90 Posts
Re: User control
Aug 31, 2011 06:47 AM|LINK
Hi,
First, thank you for your answer, but it didn't answer my question. My question is if I can put inner tags in user control and how to do so.
duzi
Member
355 Points
90 Posts
Re: User control
Aug 31, 2011 08:05 AM|LINK
I have found the answer:
in the user control ascx:
[ParseChildren(true)] [PersistChildren(true)] [ToolboxData("<{0}:TabControl runat=server></TabControl>")] public partial class TabControl : System.Web.UI.UserControl, INamingContainer { #region Properties public string HeaderText { get { return divHead.InnerText; } set { divHead.InnerText = value; } } public string SqlConnectionString { get { return sqlData.ConnectionString; } set { sqlData.ConnectionString = value; } } public string SqlSelectCommand { get { return sqlData.SelectCommand; } set { sqlData.SelectCommand = value; } } [PersistenceMode(PersistenceMode.InnerProperty)] public SqlDataSource MySqlData { get { return sqlData; } set { sqlData = value; } } #endregion #region Events protected void Page_Load(object sender, EventArgs e) { } protected void sqlData_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { } #endregion }<uc:TabControl runat="server" HeaderText="TabControl test" SqlSelectCommand="spTest"> <MySqlData ConnectionString="<%$ConnectionStrings:MyConnection %>"> <SelectParameters> <asp:Parameter Name="IsChecked" DefaultValue="0" /> </SelectParameters> </MySqlData> </uc:TabControl>