Solved

Inserting session variable into textbox as default value

Posted on 2004-08-18
14
598 Views
Last Modified: 2010-08-05
I am trying to insert a session variable (Session["OldboyCount"]) as the default value of a textbox.  I've tried the following to no avail:

<asp:textbox id="oldboyqty" columns="7" value='<%#Session["OldboyCount"]%>' runat="server"/>

Please help!!
0
Comment
Question by:markjae
  • 9
  • 4
14 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11833629
Put this in your page load event if you have the session variable already delcared

me.oldboyqty.text = CStr(Session("Oldboycount"))

Regards,

Aeros
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11833641
meant to say if you have the session variable already assigned
0
 

Author Comment

by:markjae
ID: 11833715
I get the following compilation error:

CS0246: The type or namespace name 'me' could not be found (are you missing a using directive or an assembly reference?)
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 17

Expert Comment

by:AerosSaga
ID: 11833820
are you using c# or vb?
0
 

Author Comment

by:markjae
ID: 11833862
c#
0
 
LVL 17

Assisted Solution

by:AerosSaga
AerosSaga earned 200 total points
ID: 11833894
Yeah the ME is for VB, for c#:

this.oldboyqty.text = System.Convert.ToString(Session("Oldboycount"));

Regards,

Aeros
0
 

Author Comment

by:markjae
ID: 11833973
I get the following compiler error:

Compiler Error Message: CS0117: 'System.Web.UI.WebControls.TextBox' does not contain a definition for 'text'


Does the following syntax need to change at all?

<asp:textbox id="oldboyqty" columns="7" value='<%#Session["OldboyCount"]%>' runat="server"/>
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11833984
take out the value entry
0
 

Author Comment

by:markjae
ID: 11834019
Done - but I still get the same compiler error.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11834116
in the code behind after you type the this.oldboyqt hit the . and you should see what properties you can expose, I am a VB programmer, so it must be little different in c#
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11834126
you are looking for text you may have to use something like this.oldboyqty.Items.text etc
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11834173
I think text should be there, there may be someother issue at play here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskgettingsettingvaluesintextboxwebcontrols.asp

Regards,

Aeros
0
 
LVL 25

Accepted Solution

by:
nauman_ahmed earned 300 total points
ID: 11834175
Hey markjae,

Its hard to set the values like this and it is more prone to errors since any time Session["OldBoyCount"] is null you will recieive the ASP.net object error. Why dont you set it in code:

if (Session["MyVar"] != null)
{
  MyTextBox1.Text = Session["MyVar"].ToString();
}

Best, Nauman
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11834191
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question