ASP.net VB.net change text of template button whe clicked

Hi
I am using the following code to change the backcolor of an ASP.net GridView cell
What VB.net code do I use to change the text of the actual button to?
I tried
Dim btn1 As Button = DirectCast(FindControl("MyButton1"), Button)
btn1.Text = "btn1"
but got an error "Object not set to an instance of an object"

Are you sure that the FindControl function returned a control? Possible reasons for retuning a null/Nothing is that the control name was mis-spelled, the TextBox is embedded in another container which you have no direct access from your current location. First check to see if you got a control back then operate on that control if is nothing.

Dim btn1 As Button = DirectCast(FindControl("MyButton1"), Button)If ( Not btn1 Is Nothing ) ' You have a valid control, you can use itElse Response.Write("Control not found.....")End If

Featured Post

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.