473,327 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Use variable from the code behind

I am using this variable from the code behind :



Expand|Select|Wrap|Line Numbers
  1. public string UserID; //globally declare the UserId 
  2.     protected void RadGrid1_PreRender(object sender, EventArgs e)
  3.     {
  4.         MembershipUser myObject = Membership.GetUser();
  5.         UserID = myObject.ProviderUserKey.ToString();    
  6.     }
I am trying to use the variable in the INSERT command in the aspx file but it seems that the following command does not work,any ideas why?

Expand|Select|Wrap|Line Numbers
  1. InsertCommand="INSERT INTO table (column1, column2) VALUES (value1, '<%=UserID %>')" 

Thanks!
Nov 26 '08 #1
4 3109
MrMancunian
569 Expert 512MB
@skiabox
The variable holding the userID is inserted as a string now, so it litterally tries to enter <%=UserID %>. You'll have to concatenate the value. Something like this:

Expand|Select|Wrap|Line Numbers
  1. InsertCommand="INSERT INTO table (column1, column2) VALUES (value1, '" & <%=UserID %> & "')"
Steven
Nov 26 '08 #2
If I use this one it causes an error to the whole SqlDataSource tag!
:(
Thnx anyway!
Nov 26 '08 #3
jkmyoung
2,057 Expert 2GB
Assuming this is Java and not VB, use + instead of &.
Dec 10 '08 #4
Plater
7,872 Expert 4TB
yes, try this:
Expand|Select|Wrap|Line Numbers
  1. InsertCommand="INSERT INTO table (column1, column2) VALUES (value1, '" + <%=UserID %> + "')" 
  2.  
And if not, maybe this:
Expand|Select|Wrap|Line Numbers
  1. InsertCommand="INSERT INTO table (column1, column2) VALUES (value1, '" + UserID + "')" 
  2.  
Dec 10 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: lsf_80 | last post by:
I am using ASP.net and C# as code behind. I wrote one function in the "page load" (code behind) and how can i call back the variable in the aspx page? Thank you. if i put response.write,...
19
by: Skybuck Flying | last post by:
Hi, I think I might have just invented the variable bit cpu :) It works simply like this: Each "data bit" has a "meta data bit". The meta data bit describes if the bit is the ending bit...
4
by: Bob T | last post by:
Hi All, I am trying to pass a variable from my VB asp.net script (from for example Sub Page_Load in mypage.aspx.vb) to my Client side script. I have found and looked at a very good example...
3
by: Wayne Wengert | last post by:
I have an application where a session variable is set in an ASPX page, The process calls an ASP page and when in that page the session variable appears to be null. How can I pass a session variable...
1
by: Machi | last post by:
let say i have a web form with a button on it ... when i click the button, it will pop up one small window to allow me to save a pdf file, everything is done using code behind as below ... however,...
3
by: Ryan Taylor | last post by:
Hi. I need to be able to access a public code behind variable within my ASPX page. The reason is that I have a user control "Header" which defines a table layout, and is included in all my...
12
by: Phil Certain | last post by:
Hi, I'm trying to do something very simple...or at least it should be. I have created a host page (gen.aspx) and a very simple user control (us.ascx). The corresponding code-behind files are...
5
by: Steve Richter | last post by:
I have a public variable ( "mZipServiceUrl" ) in my code behind class that I am able to substitute into the HTML of the .aspx file: <span onclick="WindowOpen('<%=mZipServiceUrl%>')"...
3
by: Pierre | last post by:
Hello, In an aspx page (mypage.aspx) from a web projet, I would like to get the value of a variable of the projet that is declared as public in a module. The variable can be called from...
1
by: supin | last post by:
hi, i work in asp.net2.0/c#.not much expert in javascript.i have a variable declared in the c# code behind page.assume the variable contains some value. i have a javascript function in the...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.