我如何在另一个Web用户控件中使用Web用户控件 [英] How I Use Web User Control In Another Web User Control

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

问题描述



i有一个usercontrol .into usercontrol我调用一个strored过程返回表中的记录数。

i想要进入用户控件创建另一个用户控件。 />
i使用此代码


i have a usercontrol .into usercontrol i call a strored procedure return number of records in table .
i want into user control create another user control.
i use this code

SqlConnection con = new SqlConnection("Data Source=MORTEZA-PC\\SQLEXPRESS;Initial Catalog=News;Integrated Security=True");
        protected void Page_Load(object sender, EventArgs e)
        {

            //this code should be into for 
            string myuser = "<CS:userNews runat=" + "server" + "/>";
            divShowOtherComment.InnerHtml = myuser;
            myuser = "<CS:userNews runat=" + "server" + "/>";
            divShowOtherComment.InnerHtml = myuser;
            myuser = "<CS:userNews runat=" + "server" + "/>";
            divShowOtherComment.InnerHtml = myuser;
            

         

        }
<pre lang="c#">



但是,只显示一个usercontrol。

为什么?


but ,only show one usercontrol.
why?

推荐答案

您必须添加动态添加新用户控件的代码到 Page_Init()事件方法而不是 Page_Load()
You have to add your code that add dynamically a new user control into Page_Init() event method and not in Page_Load().


我的问题解决了:

http: //msdn.microsoft.com/en-us/library/vstudio/c0az2h86%28v=vs.100%29.aspx [ ^ ]
my problem solved:
http://msdn.microsoft.com/en-us/library/vstudio/c0az2h86%28v=vs.100%29.aspx[^]


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

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