Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hii all.

i am anil.. i m facing a problem while to visible panel control on button click..

i m passing a int value in block..


my code is


C#
int block = Convert.ToInt32(Label4.Text);

for (int i = 1; i <= block; i++)
{

    Panel rpt_panel = new Panel();

    rpt_panel.ID = "pnlblock" + i.ToString();
    rpt_panel.Visible = true;


}


help me plz..
thanks in advance
Posted
Comments
Raajkumar.b 2-Apr-14 11:41am    
add panel or place holder to webform
id:addpanel
addpanel.Controls.add(rpt_panel);

Those are new panels: hence the keyword new.
You do not attach them to any Controls collection, and so you don't display them at all.
Just creating a control is not enough: you need to add it to your page or form as well...
 
Share this answer
 
Comments
bindash 2-Apr-14 7:27am    
please explain in detail
this code looks okay but i think you need to add this panel on the page by using some place holder or something.


from your code i can see that you are generating a control from the code and you need to add it to the page . there are some methods by which you can add controls to the page.

page.controls.add(panlel);

or may be inside a panel or placeholder
 
Share this answer
 
Comments
bindash 2-Apr-14 7:28am    
i m not generate .. the panels are present in my page.. i want to show accrding to block value on button click
ravikhoda 2-Apr-14 7:33am    
okay so instead of generating new control use findcontrol("panleid") method.
You are creating a new panel and making it visible.

If you already have the panel and want to make it visible, then use:

C#
Panel rpt_panel = Page.FindControl("pnlblock" + i.ToString());
 
Share this answer
 
Comments
bindash 2-Apr-14 7:35am    
thanks for reply..
bt it's not working
Hi,

I would try this:

C#
foreach (object ctl_loopVariable in this.Controls) {
	ctl = ctl_loopVariable;
	if (ctl is panel) {
		ctl.visible = true;
	}
}


unless you are trying to dynamically create panels using the value in the label as the quantity?
 
Share this answer
 
v2

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