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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass local variable from code behind to <TextBox> in aspx page?

Status
Not open for further replies.

BunBo900

MIS
Dec 11, 2009
50
US
How to pass a local variable from code behind page to the <TextBox> in aspx page? specifically in the <InsertItemTemplate> section of the page. I could pass to a label fine. thanks

*************************************
************aspx page*****************
<InsertItemTemplate>
<asp:Label id="lblName" Text="Location:" AssociatedControlID="txtName" Runat="server" />
<br />
<asp:TextBox id="txtName" Text='<%#Bind("Name") %>' TextMode="SingleLine" Runat="server" />
</InsertItemTemplate>

************CS codebehind page ************

protected void Page_Load(object sender, EventArgs e)
{
String tMessage = Sec.GetUserName(EDIPI);
lblLogin.Text = tMessage; // I could pass this to the aspx page
txtName.Text = tMessage
}

 
You said lblLogin, which is probably part of your masterpage.

You need to do a myTemplate.Find in Control("txtName");

Lodlaiden

You've got questions and source code. We want both!
There's a whole lot of Irish in that one.
 
There is no masterpage. Only the presentation and code behind page. I just want to put a local variable value into a TextBox instead of a label. Is it do able?

for example:
string tMessage = "Hello World";
lblLogin.Text = tMessage; // I could pass this to the aspx page
txtBoxName.Text = tMessage; // Can't pass to here. Why???
 
You're using an INSERTITEMTEMPLATE. THis means you have to do do a "FindInControl"

You've got questions and source code. We want both!
There's a whole lot of Irish in that one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top