This topic is locked
[SOLVED]

 Set default value based on logged in user

11/5/2013 5:29:44 AM
ASPRunner.NET General questions
M
marcoardiawenink author

ASPRunner.NET 6.0 using MSSQL
Hi,
On my add page I have one field that is edited using a lookup wizard. I want to set the default value based on the logged in user.

  • my table is called prospects, the field is club_id
  • the lookup table is clubs and links through club_id
  • in the user table, I also have club_id
    So I need kinda like: default value = select club_id from users where user_name = {current user}
    How can I do this ?

admin 11/6/2013

Marco,
here is an idea of how this an be done.

  1. Perform this query in BeforeProcess event of the Add page in question. Save this value in one of session variables.
  2. Use this session variable as a default value on Lookup wizard setup screen

M
marcoardiawenink author 11/12/2013

Hi Sergey,
Thanks for your reply! What you describe is exactly what I'm trying to achieve. However, I can't get the syntax for the query right.
Dim defclub = select club_id from users where user_name = {current user} ???

admin 11/13/2013

You can access current logged username as XSession.Session["UserID"]
More info on session variables at http://xlinesoft.com/asprunnernet/docs/asprunnernet_session_variables.htm
When you build your SQL query query make sure user name is wrapped by single quotes.
Assuming you use C#:

"select club_id from users where user_name = '" + XSession.Session["UserID"] + "'"