Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Inserting session variable into textbox as default value

Posted on 2004-08-18
14
Medium Priority
?
614 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
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 800 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 1200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

772 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