Use variable from the code behind
-
I am using this variable from the code behind :
public string UserID; //globally declare the UserId
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
MembershipUser myObject = Membership.GetUser();
UserID = myObject.ProviderUserKey.ToString();
}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? InsertCommand="INSERT INTO table (column1, column2) VALUES (value1, '<%=UserID %>')" Thanks!
-
I am using this variable from the code behind :
public string UserID; //globally declare the UserId
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
MembershipUser myObject = Membership.GetUser();
UserID = myObject.ProviderUserKey.ToString();
}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? InsertCommand="INSERT INTO table (column1, column2) VALUES (value1, '<%=UserID %>')" Thanks!
What about
InsertCommand="INSERT INTO table (column1, column2) VALUES (value1, '" + UserID + "')"
Assuming that you are doing this from within RadGrid1_PreRender routine.
-
What about
InsertCommand="INSERT INTO table (column1, column2) VALUES (value1, '" + UserID + "')"
Assuming that you are doing this from within RadGrid1_PreRender routine.
Thnx for answering but I want to use the variable in the aspx file not in the code behind file.
-
I am using this variable from the code behind :
public string UserID; //globally declare the UserId
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
MembershipUser myObject = Membership.GetUser();
UserID = myObject.ProviderUserKey.ToString();
}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? InsertCommand="INSERT INTO table (column1, column2) VALUES (value1, '<%=UserID %>')" Thanks!
It would help if you defined 'does not work', but I thought that using code blocks like this only worked for properties, not for public variables.
Christian Graus Driven to the arms of OSX by Vista.
-
It would help if you defined 'does not work', but I thought that using code blocks like this only worked for properties, not for public variables.
Christian Graus Driven to the arms of OSX by Vista.
What I mean is that if I use sql management studio and enter the insert query manually there is no problem.
-
What I mean is that if I use sql management studio and enter the insert query manually there is no problem.
But what *is* the problem ? Is the value being passed back blank ? Is it incorrect ? Does it blow up ? Did you try using a property ?
Christian Graus Driven to the arms of OSX by Vista.
-
But what *is* the problem ? Is the value being passed back blank ? Is it incorrect ? Does it blow up ? Did you try using a property ?
Christian Graus Driven to the arms of OSX by Vista.
Can you give me a sample .aspx code of properly passing a value from the code behind? Thank you!
-
Can you give me a sample .aspx code of properly passing a value from the code behind? Thank you!
int _n; // this is a variable protected int N { get { return _n; } // this is a property } Wrap your variable in a property and then access the property.
Christian Graus Driven to the arms of OSX by Vista.