如何访问内容页面上的Web用户控件的控件 [英] How to access controls of webuser control on content page

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

问题描述

我全部
我在主页上放置了一个Web用户控件.
用户控件包含超链接.
我想在内容页面上选择超链接的文本.
任何人都可以提供一些提示.

预先感谢.

hI ALL
i have a web user control placed on master page.
user control contains hyperlinks.
i want to pick the text of hyperlink on content page.
Can any one please provide some hint.

Thanks in advance.

推荐答案



我认为您必须使用 delegate

尝试以下示例:
在页面后面的代码中:


Hi,

I think you must use delegate

Try this example:
In your code behind page:


protected void Page_Load(object sender, EventArgs e)
{
   //Do something?...
  ucOverride.SendValue += delegate(bool checkedOverride,string firstName, string lastName)
   {

      // Your chckedOverride.Check = checkedOverride;
      // Your txtFirstName.Text = firstName;
      // Your txtLastName.Text = firstName;
   };
   //Do something?...
   //.....
}




在您的自定义控件页面代码后面:
示例:




In you custom control page code behind:
Example:

public delegate void SendData(bool checkedOverride,string firstName, string lastName);
public event SendData SendValue;


protected void btnOk_Click(object sender, EventArgs e)
{
  //UpdatePanel1.Update();
  bool checkeds = false;
  if (chkOverride.Checked)
  {
     checkeds = true;
  }
  else
  {
     checkeds = false;
  }
  firstName = txtFirstName.text;
  lastName = txtLastName.Text;
  if (SendValue != null)
  {
            SendValue(checkeds,firstName,lastName);
  }
}





希望这可以帮助...

请记住,如果有帮助,请将其标记为答案;如果没有帮助,则将其取消标记.

问候,

Algem





Hope this could help...

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Regards,

Algem


在这种情况下,最合乎逻辑的事情是在用户控件上放置一个公共属性来设置文本.然后您的页面可以设置该属性,甚至可以将其设置为aspx而不是后面的代码.在这种情况下,不需要委托,因为您可以通过清晰的路径来设置值,而无需进行任何回调.
The most logical thing in this case, is to put a public property on the user control to set the text. Then your page can set that property, you can even set it in your aspx instead of your code behind. Delegates are not needed in this case, as you have a clear path to set the value without any sort of callback.


您可以使用两种方法.首先是使用
You can use two methods. The first is by using
Page.Master.FindControl(''controlID'')

,然后可以将其强制转换为用户控件的类型.第二种方法是在您的aspx页面上添加一个

Then you can cast it to the type of your user control. The second method is by adding a

<%@ MasterType VirtualPath="" TypeName=""%>

标记.在VirtualPath中,将虚拟路径添加到母版页,并在TypeName中添加类.然后,您可以使用intellisense访问所有内容.

信誉可在此处

您还可以在此处

tag to your aspx page. In the VirtualPath add the virtual path to the master page, and the class in the TypeName. You can then access everything with intellisense.

Credit goes here

You can also get detail examplehere


这篇关于如何访问内容页面上的Web用户控件的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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