Melt
Melt

Reputation: 501

Asp.Net: Passing value from Page to UserControl

I have a textbox on my aspx page and I need a usercontrol to be able to see or access that value, how would I do that please.

I created a public property on my aspx page

public string txtBoolValue
    {
        get { return this.txtBool.Text;}
    }

How do I call that from my ascx page?

Thanks

Melt

Upvotes: 3

Views: 18657

Answers (3)

iDennis
iDennis

Reputation: 19

Try this:

((Textbox)this.Parent.FindControl("YOUR TEXTBOX NAME IN ASPX PAGE")).Text

Upvotes: 2

Amit Rai Sharma
Amit Rai Sharma

Reputation: 4225

Instead of creating a property on page why don't you create a property on user control which can be set by the page. The code you mentioned in your question will create tight coupling between the page and user control.

Upvotes: 15

Related Questions