Solved

Inserting session variable into textbox as default value

Posted on 2004-08-18
14
608 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
Independent Software Vendors: 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

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

630 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