Click here to Skip to main content
16,004,833 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
actually i'm developing template using asp.net and c#. i have one panel which contain 2 fieldset in my usercontrol page. i wand to access these 2 fieldset from the code behind of the main.aspx page, which means when the user click on the link1 at the main.aspx page the panel will be refresh and shows the fielset1 and when the user click on the link2, the panel will be refresh and panel shows the fieldset2. for the partial refreshing of the page i'm using the updatepanel. could you please guide me how to get ride of this problem.
appreciate your consideration.
Posted

Register the user control in default.aspx as:

XML
<%@ Register TagPrefix="so" TagName="UserControl" Src="~/myUserControl.ascx" %>


Instance of the user control is created as:

XML
<so:UserControl ID="UserControl1" runat="server" Title="Control 1" OnRemoving="UserControl1_Removing" />


In code behind, handle the user control evnt as:
C#
protected void UserControl1_Removing(object sender, EventArgs e)
{
    myUserControl ctrl = (myUserControl)sender;
    ctrl.Visible = false;
}
 
Share this answer
 
Comments
Far sh 13-Dec-11 4:04am    
thanks for the reply, but could you please show me how to build the property for the fieldset in ascx.cs page and in the aspx.cs page change the visibility of the fieldset to false or true. because i could do it for the panel:

Control panelControl31 = WebUserControl31.FindControl("Panel1");
Panel pControl1 = (Panel)panelControl31;
pControl1.Visible = false;

but i couldn't do it for the fieldset inside the panel.
really appreciate.
i have fixed the problem.
i have put one HiddenField variable at my usercontrol page:
<asp:hiddenfield id="hid_choosingField" value="" runat="server" xmlns:asp="#unknown" />

then i have accessed and changed it from aspx.cs page:
Control hidField = WebUserControl31.FindControl("hid_choosingField");
    HiddenField ucHidField = (HiddenField)hidField;
    ucHidField.Value = "1";


then i have put a if condition at the ascx page to check what is the HiddenField value and base on the value i show the related fieldset:
<% if (hid_choosingField.Value == "1")
   { 
%>
    <fieldset id="uc3Fieldset1" style=" height:350px;">
    <legend>New Module Details</legend>

        <asp:label id="Label2" runat="server" forecolor="blue" text="This is User Control 3 Panel 1 Fieldset 1" />
    </fieldset>

   }
   else if (hid_choosingField.Value == "2")
   { 

    <fieldset style=" height:350px;">
    <legend>New Module Details</legend>

        <asp:label id="Label1" runat="server" forecolor="blue" text="This is User Control 3 Panel 1 Fieldset 2" />
</fieldset>


i hope it would be helpful. thanks
 
Share this answer
 
v2
you can try this. if you have question or problem ask me.

foreach (Control c in UpdatePanel1.Controls)
        {
            if (c.GetType().Name.ToLower() == "uc_ascx")//YOUR USER CONTROL NAME:for exacmple:uc_ascx
            {
                UserControl uc = (UserControl)c;
               
                TextBox txtbox1 = (TextBox)uc.FindControl("Textbox1");//you must CAST type of destination control. for example textbox or button, label , hyper link
                Label label = (Label)uc.FindControl("Labl1");
                Button button = (Button)uc.FindControl("button1");
                // done your job
                string value1 = txtbox1.Text;
                string value2 = label.Text;
                string value3 = button.Text;
            }
        }


in user control put some control like textbox or label
then when you added this user control on Main.aspx in the code behind of Main.aspx, add this function at event(for example: button click event )
then you can get all of the property of control that you like, but you must use of your control instead of :

TextBox txtbox1 = (TextBox)uc.FindControl("Textbox1");

string value1 = txtbox1.Text;
 
Share this answer
 
Comments
Far sh 15-Dec-11 21:15pm    
Thank Morteza for reply.
the updatepanel is in aspx page and the labels, textbox and all content is located at the usercontrol page. i have fixed it.
please check out the answer.
but for editing part i have done some thing like what you have mentioned and using itemDataBound function of listview.

protected void lvProduct_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
Label EmpIDLabel = (Label)e.Item.FindControl("EmpIDLabel");
System.Data.DataRowView rowView = e.Item.DataItem as System.Data.DataRowView;
EmpIDLabel.Text = rowView["EmpID"].ToString();
}
}

regards

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900