vb.net 从网页的用户控件中的文本框中获取值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20299812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 15:59:26  来源:igfitidea点击:

Get value from text box in User Control from Web Page

asp.netvb.netuser-controlsweb-controls

提问by user2412351

I have this Web Control call uc_Register.asxc Inside this web control got a Text Box i.e txtName

我有这个 Web 控件调用 uc_Register.asxc 在这个 Web 控件里面有一个文本框,即 txtName

I add this Web Control into my web page call register.aspx

我将此 Web 控件添加到我的网页调用 register.aspx

<%@ Register Src="~/controls/uc_Register.ascx" TagPrefix="ecommmbs" TagName="uc_Register" %>
<hr />
<ecommmbs:uc_SummaryCart runat="server" ID="uc_SummaryCart" />
<hr />

i want to get the value from txtName.txt from uc_Register.asxc at register.aspx. how to make this happen?

我想从 register.aspx 的 uc_Register.asxc 中的 txtName.txt 获取值。如何做到这一点?

采纳答案by Tami

Try this in Register.aspx

在 Register.aspx 中试试这个

TextBox txtbox = (TextBox)uc_Register.FindControl("txtName");

but keep in mind Page_Load() of aspx page is called first than Page_Load()of .ascx is called.

但请记住,首先调用 asx 页面的 Page_Load() ,而不是调用 .ascx 的 Page_Load() 。

回答by panky sharma

Here is an example:

下面是一个例子:

   Declare On User Control (PrevTransList2.ascx.cs)

    public string TransHxPage
      {
        get
        {
            return name;
        }
        set
        {
            name = value;
        }
       }

On Class file
   public interface IUserControlTransHx
    {
        string TransHxPage { get; set; }

    }
            txtSomthing.Text = TransHxPage;

Now On Web page SET its values

现在在网页上设置它的值

          PrevTransList2.TransHxPage = "POSP";