set value from page to webusercontrol textbox
-
Hi i am trying to set value for my user control contained textbox from my aspx page..., But i am getting error..., Whats wrong in this code: //My Aspx Code Behind: myusercontrolpage objTestControl = (myusercontrolpage)Page.FindControl("myusercontrolpage"); TextBox objTextBox = objTestControl.FindControl("TextBox5"); objTextBox.Text = "Hi"; //My Aspx Page And I have tried this logic also: Here i am getting object reference not set an instance of object..., TextBox tbPromoCode = Page.FindControl("myusercontrolpage").FindControl("TextBox1") as TextBox; tbPromoCode.Text = "BLAH"; Thanks & Regards, Member 3879881, please don't forget to vote on the post
-
Hi i am trying to set value for my user control contained textbox from my aspx page..., But i am getting error..., Whats wrong in this code: //My Aspx Code Behind: myusercontrolpage objTestControl = (myusercontrolpage)Page.FindControl("myusercontrolpage"); TextBox objTextBox = objTestControl.FindControl("TextBox5"); objTextBox.Text = "Hi"; //My Aspx Page And I have tried this logic also: Here i am getting object reference not set an instance of object..., TextBox tbPromoCode = Page.FindControl("myusercontrolpage").FindControl("TextBox1") as TextBox; tbPromoCode.Text = "BLAH"; Thanks & Regards, Member 3879881, please don't forget to vote on the post
The object reference not set an instance of object tells me that it either cannot find the myusercontrolpage control on you page or the TextBox5 control on your objTestControl. Debug and see where it happens. Depending on how your control works you can expose the textbox text property as a property on you control that returns and set the textbox value. Just an idea...
-
Hi i am trying to set value for my user control contained textbox from my aspx page..., But i am getting error..., Whats wrong in this code: //My Aspx Code Behind: myusercontrolpage objTestControl = (myusercontrolpage)Page.FindControl("myusercontrolpage"); TextBox objTextBox = objTestControl.FindControl("TextBox5"); objTextBox.Text = "Hi"; //My Aspx Page And I have tried this logic also: Here i am getting object reference not set an instance of object..., TextBox tbPromoCode = Page.FindControl("myusercontrolpage").FindControl("TextBox1") as TextBox; tbPromoCode.Text = "BLAH"; Thanks & Regards, Member 3879881, please don't forget to vote on the post
You should create a public property on the usercontrol and set the textbox value from within the property.
.: I love it when a plan comes together :. http://www.zonderpunt.nl
-
Hi i am trying to set value for my user control contained textbox from my aspx page..., But i am getting error..., Whats wrong in this code: //My Aspx Code Behind: myusercontrolpage objTestControl = (myusercontrolpage)Page.FindControl("myusercontrolpage"); TextBox objTextBox = objTestControl.FindControl("TextBox5"); objTextBox.Text = "Hi"; //My Aspx Page And I have tried this logic also: Here i am getting object reference not set an instance of object..., TextBox tbPromoCode = Page.FindControl("myusercontrolpage").FindControl("TextBox1") as TextBox; tbPromoCode.Text = "BLAH"; Thanks & Regards, Member 3879881, please don't forget to vote on the post
create a public property on your user control and set the value from the page. :)
cheers, Abhijit