ASP.NET:将值从用户控件传递到页面?

时间:2022-04-21 15:11:10

I am creating a user control in ASP.NET (using VB) that uses the autocomplete ajax control on a textbox to get a value. Then I want the page to post back and run some code according to whatever value is passed to it from this control. Problem is, I'm not exactly sure how to do this. I'm sure it's easy and I should know, but I don't.

我在ASP.NET中创建一个用户控件(使用VB),它使用文本框上的自动完成ajax控件来获取值。然后我希望页面回发并根据从该控件传递给它的任何值运行一些代码。问题是,我不确定如何做到这一点。我确信这很容易,我应该知道,但我不知道。

Thanks in advance!

提前致谢!

3 个解决方案

#1


In your user control expose a property for the value

在您的用户控件中公开值的属性

Public Property SomeValue() As String
Get
    Return textbox1.Text
End Get
End Property

Then in your aspx page load, just reference the user control's value.

然后在你的aspx页面加载中,只需引用用户控件的值。

userControl1.SomeValue

Edit, I just tried changing my syntax to vb.net, I don't actually know vb, so that syntax may or may not be right.

编辑,我只是​​尝试将我的语法更改为vb.net,我实际上并不知道vb,因此语法可能正确也可能不正确。

#2


((NameOfPage)this.Page).VariableOnPage = this.Foobar;

((NameOfPage)this.Page).VariableOnPage = this.Foobar;

#3


In the code-behind on your user-control expose a property e.g.

在您的用户控件的代码隐藏中,公开一个属性,例如

public TextBox UserControlTextBox
{
    return this.TextBoxInstance;
}

Then from you page just call

然后从你的页面打电话

UserControlInstance.UserControlTextBox.Text;

#1


In your user control expose a property for the value

在您的用户控件中公开值的属性

Public Property SomeValue() As String
Get
    Return textbox1.Text
End Get
End Property

Then in your aspx page load, just reference the user control's value.

然后在你的aspx页面加载中,只需引用用户控件的值。

userControl1.SomeValue

Edit, I just tried changing my syntax to vb.net, I don't actually know vb, so that syntax may or may not be right.

编辑,我只是​​尝试将我的语法更改为vb.net,我实际上并不知道vb,因此语法可能正确也可能不正确。

#2


((NameOfPage)this.Page).VariableOnPage = this.Foobar;

((NameOfPage)this.Page).VariableOnPage = this.Foobar;

#3


In the code-behind on your user-control expose a property e.g.

在您的用户控件的代码隐藏中,公开一个属性,例如

public TextBox UserControlTextBox
{
    return this.TextBoxInstance;
}

Then from you page just call

然后从你的页面打电话

UserControlInstance.UserControlTextBox.Text;