+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Get Username

Get Username

4 posts, 0 answered
  1. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    03 Mar 2010
    Link to this post
    Can anyone tell me how to get username to the javascript in Generic Content. Here is the test code I am using: 

     <script type="text/javascript">
    var uname =document.getElementById('<%= UserName() %>');

    alert (uname);
    </script>

    Thanks,
    Pik
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    03 Mar 2010
    Link to this post
    Hi Pik Lee,

    getElementById gets the HTML elements' id attributes - MSDN. Could you tell us some more about the way you want to use to get an username and from where you  want to get it?

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    03 Mar 2010
    Link to this post
    Thanks for the prompt reply. In my page, I've inserted Generic content and trying to place the javascript to prompt the username after the user login. I need that username to pass it as a string to an external site. Here is my code:

    <script type="text/javascript">
    function openwin(){
    return  "http://www.abccom?username=<%= HTTPContext.Current.User.Identity.Name %>"}
    </script>

    Generic Contect does not like the HTTPContext. Any idea how to get the username from sitefinity and pass it to external site?

    Thanks,
    Pik
  4. Pik Lee
    Pik Lee avatar
    142 posts
    Registered:
    13 Aug 2012
    04 Mar 2010
    Link to this post
    I've figured it out. In the page load of the master page, I placed

     

    string uname = UserManager.GetCurrentUserName();

     unametxt.Value = uname;
     
    and set a hidden field in the master page. Then I used document.getElementById to get the value from the hidden field.

    Thanks,
    Pik

     

Register for webinar
4 posts, 0 answered