Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get a value from a Web Control

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
I am trying to get the value/text on a label located within a Web User Control and parse it to the following:

This is my current code, which worked before I put in the web user control. The lblUserID is now located in the web user control 'Header'

Code:
cmd.Parameters.Add("@Sender", SqlDbType.Int).Value = lblUserID.Text.Trim()

I am getting the error

Code:
 Name lblUserID is not declared

Help please

Thanks
 
I 'think', (i.e., without checking/testing oe looking it up), that for your controls to be registered in the code behind they have to be resident inside the form element which if they're in the header they won't be.

Rhys

"The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it"
Terry Pratchett
 
You have to get a reference to the usercontrol first, then use FindControl("") to get a refernce to that control.
 
or expose the value of the textbox as a property of the usercontrol.
Code:
class myusercontrol: usercontroler
{
   public string UserID
   {
      get { return lblUserID.Text.Trim(); }
      set { lblUserID.Text = value; }
   }
}

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Thanks for your tips guys. I will give them a go and let you know how I get on
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top