Solved

Inserting session variable into textbox as default value

Posted on 2004-08-18
14
582 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now