I have the control id name in string, and try to find it in the event handler:

1 protected void btnGo_OnClick(object sender, EventArgs e)
2 {
3 ((TextBox)Page.FindControl("txb" + strColumn)).Text
4 }

but that throws an object reference not set to an instance of an object. It seems as if the control cannot be found?

Recommended Answers

All 3 Replies

where do you define "strColumn"?

Often controls are buried into deeper level of control hierarchy. Obviously the control you were trying to find is not in the next level. Add trace="true" in your Page directive attributes and try to locate the control. Also, it is often decorated with some additional symbols, especially if it is repeatedly created by, say, a data control. Try to add a TextBox in a Repeater and watch the control list...

hi,

there are few flaws in u r code.did u declare strcolumn

protected void btnGo_OnClick(object sender, EventArgs e)
2 {
3 ((TextBox)Page.FindControl("txb" + strColumn)).Text [B];[/B]
4 }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.