3

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

Iswanto San
  • 18,263
  • 13
  • 58
  • 79
Melt
  • 481
  • 2
  • 10
  • 17

3 Answers3

15

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.

Amit Rai Sharma
  • 4,015
  • 1
  • 28
  • 35
5

Hai have a look at this http://www.codedigest.com/CodeDigest/22-Passing-value-from-Page-to-UserControl-in-ASP-Net.aspx

ACP
  • 34,682
  • 100
  • 231
  • 371
  • That only works but only for static values set on the page, does anyone know if it's possible to do for dynamically generated values? – Armin Nehzat Mar 07 '12 at 05:02
  • @ArminNehzat, I think you'll have to use the codebehind to do that. – Sam May 31 '13 at 06:17
2

Try this:

((Textbox)this.Parent.FindControl("YOUR TEXTBOX NAME IN ASPX PAGE")).Text
gunr2171
  • 16,104
  • 25
  • 61
  • 88
iDennis
  • 19
  • 1