从aspx页面找到用户控件的控件 [英] find a control of user control from a aspx page

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

问题描述

嗨专家

我在用户控件中有一个文本框。我的用户控件在母版页中。我想从default.aspx访问这个文本框。



如何访问文本框?



提前感谢

hi experts
i have a text box in a user control. my user control is in master page. i want to access this text box from default.aspx.

how i can access to text box?

thanks in advance

推荐答案

hi


i有一个用户控件,其中包含id为txtname的文本框



我从default.aspx页面更改了文本框值,如下所示



hi
i have a user control which contain below textbox having id "txtname"

and i have change textbox value from default.aspx page like as below

((this.Master.FindControl("usercontrol") as UserControl).FindControl("txtname") as TextBox).Text = "pqr";


这也没关系。



This is also fine.

TextBox txt = ((UserControl)Master.FindControl("TextBox1")).FindControl("TextBox1") as TextBox;


for that you need to put usercontrol in other folder then use it check my code as below
in webconfig file
 <pages masterPageFile="~/Site.Master">
      <controls>
        <add src="~/UserControls/WebUserControl1.ascx" tagname="userControltag" tagprefix="uc1"></add>
      </controls>

    &lt;/pages&gt;

in site master
&lt;uc1:userControltag ID="usercontrol"  runat="server" /&gt;

in sitemaster.cs
you can access usercontrol.

please follow folder structure like usercontrol should be put in other fodler

UserControl ::- WebUserControl1.ascx


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

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