用户控件 [英] UserControll

查看:49
本文介绍了用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在linkbutton_click上加载用户控件...
str str = VirtualPathUtility.GetFileName("//Manoj.ascx");
控件C = Page.LoadControl(str);
PlaceHolder1.Controls.Add(C);

该代码正常工作...
但是当按下用户控件中的按钮时,则用户控件
从占位符可以清楚地看到.
请帮忙.
感谢您的帮助.

I m loading a user control on the linkbutton_click i m using following code...
str str=VirtualPathUtility.GetFileName("//Manoj.ascx");
Control C=Page.LoadControl(str);
PlaceHolder1.Controls.Add(C);

This code is work properly...
but when press the button from the user control then the user control
is clear from the placeholder.
Please help.
Thank''s for the help.

推荐答案

您需要重新创建,重新绑定并将用户控件再次放置在占位符中.由于您是动态创建的,因此它本身不会保留在回发中.

重新创建并将其放回相同的占位符,也将还原控件的视图状态.因此,在事件发生之前(可能是在页面加载中),请在占位符中重新加载Usercontrol.
You need to re-create, re-bind and place the user control again in the place holder. Since you created it dynamically, it won''t persist at postbacks by itself.

Re-creating and putting it back to the same placeholder, would restore the viewstates of the control too. So, before the event, probably in your page load, reload the Usercontrol in Placeholder.


这篇关于用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆