Solved

Inserting session variable into textbox as default value

Posted on 2004-08-18
14
606 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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