如何动态加载UserControl. [英] How to Load UserControl Dynamically.
本文介绍了如何动态加载UserControl.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友.
我已经开发了用于登录的用户控件.
现在,如果用户单击登录按钮",我想在占位符中动态加载该用户控件.我该如何完成这项任务.
如果有人有想法,请建议我.
您的建议将不胜感激.
Hi Friends.
I have developed a User Control For Login.
Now I want to Load that User Control dynamically in Placeholder if User Click Sign in Button. How can i achieve this task.
If any body have Idea , Please suggest me.
Your suggestion will be highly appreciate.
推荐答案
您好,
您只需在登录按钮点击事件中做到这一点:
Hi,
You just do like this in the sign in button click event:
Control uc = LoadControl("YourLoginWebUserControl.ascx");
YourPlaceHolder.Controls.Add(uc);
然后,请记住在以下回发中重新创建控件,否则,如果usercontrol引发了任何按钮单击事件,则它们不会在后面的代码中触发.
就这样:-)
问候
Joachim
And then, remember to re-create the control in the following postback''s otherwise if the usercontrol was raising any button click events or so, they will not get fired in the code behind.
That''s it :-)
Regards
Joachim
最简单的方法是将用户控件从解决方案资源管理器面板拖放到要放置的页面的内容占位符上.我希望它能给你一个主意. :)
the easiest way to do is to drag and drop the user control from the solution explorer panel to the content place holder of a page you want it to place. i hope itll give you an idea. :)
这篇关于如何动态加载UserControl.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文