User Session Variables as default value in Add Pages

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
aspsteve
User
Posts: 52

User Session Variables as default value in Add Pages

Post by aspsteve »

We have set up a set of values on the user table that we would like to attach to a user as session variables. We have set them up under the user validated event as indicated below.
We have also set them as Global Codes. Also see below.

Now we want to be able to include them as default values when the user is about to add data to those fields in specific tables

// User Validated event

public bool User_Validated(DbDataReader? rs) {
        Session["UserCountry"] = rs["Country"];
	Session["UserDepartment"] = rs["Department"] ;
	return true; // Return true/false to validate the user
}

We have also defined them as Global Codes. See below:

public string UserCountry { get{return System.Convert.ToString(Session["UserCountry"]);} }

public string UserDepartment { get{return System.Convert.ToString(Session["UserDepartment"]);} }

We are getting the error message below when we enter either of the values below as the default value in the Add page

Our sample default value entered in the Add Page:
UserDepartment(),
UserCountry()

Error Message
C:\inetpub\wwwroot\staging_publishing\foldername\Models\MyTableName.cs(139,41): error CS1955: Non-invocable member 'myprojectname.UserDepartment' cannot be used like a method. [C:\inetpub\wwwroot\staging_publishing\folder\projectname.csproj]
C:\inetpub\wwwroot\staging_publishing\foldername\Models\MyTableName.cs(139,41): error CS0120: An object reference is required for the non-static field, method, or property 'myprojectname.UserDepartment' [C:\inetpub\wwwroot\staging_publishing\folder\projectname.csproj]

darkdragon
User
Posts: 148

Post by darkdragon »

Normally I will hide those fields and add/modify them in Row_Inserting or Row_Updating, since they contain some data which doesn't change.
On the other hand if you want to make them available globally during an entire sessions you have various options. Here is an example, I set in a session variable but as client variable, too, the default language for the logged user:

	string _userLang = Convert.ToString(CurrentUserInfo("language_code"));
	Session[currentUserLangCode] = _userLang;
	SetClientVar("currentUserLangCode", _userLang);

you can call then, in C#:

	string _userLang= Session[currentUserLangCode].ToString();

or in client side:

	var _userLang = ew.vars.currentUserLangCode;

Post Reply