Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    81
    Thanks
    13
    Thanked 3 Times in 3 Posts

    Problems with LoginName control returns.

    I'm just wanting a simple return on "Welcome, [UserName]" like on this site..

    I have the right code I believe :
    Code:
    <asp:LoginView ID="LoginView3" runat="server">
                   <AnonymousTemplate>
                        Welcome to Some.Com Guest
                  </AnonymousTemplate>
                   <LoggedInTemplate>
                   <asp:LoginName id="LoginName1" runat="Server" FormatString="Some.Com Welcomes You Back,{0}"></asp:LoginName>
                   </LoggedInTemplate>
                    </asp:LoginView>
    So when I login it returns the primary key of the user instead of the UserName
    i don't have any vb code for this and don't know why I need it if I do
    any help?

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,929
    Thanks
    46
    Thanked 203 Times in 202 Posts
    I've never tried it from the front end like you are doing here, but the format for doing that would be something like this

    Code:
    string userName = "whatever";
    lbl_welcome.Text = "Some.com welcomes you back {0}", userName;

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #3
    New Coder
    Join Date
    Nov 2010
    Posts
    81
    Thanks
    13
    Thanked 3 Times in 3 Posts
    Ya that's what I'm trying to accomplish yet like you said Front-end style, Apparently it's suppose to just work! and the syntax is correct but it keeps pulling and displaying the ID from the Database and not the UserName like it's suppose to. :/ .. If ya look I'm not using a label either.

    just a loginView to toggle from in(LoggedIn) and out(Anonymous) .. i'm still lookin into figuring this out somehow
    (VB btw)

  • #4
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,929
    Thanks
    46
    Thanked 203 Times in 202 Posts
    what is it returning?
    eg
    let's say my table looks something like
    username | The_Great_Bob
    Name | Billy-Bob
    Password | demo
    and "Billy-Bob" logs in with the following credentials....
    The_Great_Bob | demo

    I am guessing according to what I see up there it is returning
    "The_Great_Bob"
    but you want it to return "Billy-Bob"
    is that correct?
    if so (granted idk this for a fact since I don't generally play with the front end) I assume that the username (in this case "The_Great_Bob") is bound to {0} (that {0} even though it is showing as {0} I am pretty sure behind the scenes is bound to a string similar to what I typed)

    is there a reason you are not doing it from codebehind?

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #5
    New Coder
    Join Date
    Nov 2010
    Posts
    81
    Thanks
    13
    Thanked 3 Times in 3 Posts
    You got it! that's exactly the problem..

    It's returning the "The_Great_Bob" and I want it to return "Billy-Bob" how you have it set. w/o any PKs so essentially "UserName" is your PK or {0}

    MINE is "ID" and it pulls from the ID witch is auto incremented and would be the integer related to the "ID" ..

    I'm sure there is a way to do this front-end because that's essentially what the control is for, and future projects I can know the front-end for it, and I'm just plain not great at the VB codeBehind for figuring that out.

    I'm trying different methods in the LoginName control tryin to see any of 'em would work. like:
    Code:
     FormatString="Some.Com Welcomes You Back,{0}"
     FormatString="Some.Com Welcomes You Back,{0,1}"
     FormatString="Some.Com Welcomes You Back,{"VariableNametoPull"}"
    I just cant really find any quality info on it.

    I'd wouldn't care if it was codeBehind but I wouldn't know where to start on it because it's pullin from a DB.
    plus I thought front end would be cooler to figure out after I started to think about it.

  • #6
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,929
    Thanks
    46
    Thanked 203 Times in 202 Posts
    i tinkered w/ that login control myself recently... it is actually a lot more complex than it seems at first glance... I really do not see any way you will be able to access it w/o going to the code behind... the problem is those tables are really in depth, getting the data from them will be a huge pain, and w/o making ur own login I think this may be more than you're bargaining for.... but some advice...
    first using different configurations of the {} won't work.... what that does is let's say I have
    Code:
    Console.WriteLine("String one is: {0} String two is: {1} Just to re-touch String one is {0}" , str_One, str_Two);
    that will throw str_One into both the {0} spots and str_Two into the {1} spot... it's not like accessing an array, it is just a way to set multiple argument (might be wrong word for it)...

    the : in the {} is for formating so
    Code:
    Console.Write("Today's date is {0:mm/dd/yyyy}" , DateTime.Now);
    would format the date time so it looks like the mm/dd/yyyy format
    *Note idk if it will work "just like that" I havent done it much and have always done it in the past via somehting like string.Format("text {0:mm/dd/yyyy}.... etc

    what you need to do is access the datatable that comes back, so something like
    Code:
    datatable.Column[0];
    or something like that *doing it on the fly w/o my trusted intellisense
    ... anyways point being you need to do it from code behind; i think it will be a huge pain though.... you need to get into that database... i cannot remember how exactly i got into mine...
    I know I connected via sql management studio to .\SQLEXPRESS, but when I went to do this again; I must have deleted the table bc it is not there... you might have to have the project running... I can't remember honestly... that login cntrl is cool but a lot of problems, main one being when you try to migrate to an actual server running SQL (for real) ... I personally am having a bi** of a time getting the "redirect" functionality to work....
    anyways if you can get that to work, all you need to do is make a little stored proc that you call on click to fetch the name of the person from the DB
    something like
    Code:
    create proc usp_selectUserName @index int, as
    select [user_name] from tbl_users where PK_ID = @index

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #7
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,929
    Thanks
    46
    Thanked 203 Times in 202 Posts
    hmmm... I tried to find it via my regular SQL but to no avail... idk what happened to it lol... anyways the "out of the box" connection string for it is
    Code:
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
    which can be found in the config file, and also will tell u all you need to know.
    connect to the .\SQLEXPRESS database, the database should be attached there named "aspnetdb" ... then drill through the tables till you find the data you are looking for. Good luck

    Side note: sry i did all examples in C#.... I know you said vb, but most were off-the-cuff and idk the syntax for vb well enough to do that; those should point you to the appropriate msdn ref pages though

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #8
    New Coder
    Join Date
    Nov 2010
    Posts
    81
    Thanks
    13
    Thanked 3 Times in 3 Posts
    LOL .. I was lookin at that trying to comprehend the C# logic .. I got the jist of it ..and I've been at this all day(until my internet went out!) ..back and runnin smooth tho..Ya I have a SQL database all made up and stored procedures created got some clean code for the login (used that loginstatus dropin thank you VS2010 lol) and it runs fine! the site ain't online but the db is and it's all good. the LoginStatus and LoginView controls are a breeze. and I even did some JavaScript right in the LoginStatus for onmouseover.. idk how it works but it does LOL. Just really wanted to get that stupid LoginName figured out!..I know there's GOTTA be a way.

    btw I did the DB with SQL server 2008 r2 and using VS2010 so .. I'm still pluggin away at it

    oh and I've DRILLED the msdn pages .. most of its too techy for me.
    I just make it work cause I know how, figure it out, read layman's terms, er ask
    Last edited by joanzn; 11-03-2011 at 06:54 AM.

  • #9
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,929
    Thanks
    46
    Thanked 203 Times in 202 Posts
    well stop back if u have more Q's on the matter... the Console.WriteLine() is actually the same for C# as it is VB minus the ";"

    so the part where I have all the {} thins within the "text" .... those {} are populated by order of the variables called out after the text has completed sepreated by commas... the strings would only be changed to something like
    Code:
    Dim A as string
    Dim B as string
    etc
    the creat proc part is SQL (I assume you knew that, but the only other thing I saw that I put that was "weird")

    anyways... I can help you when I have time (note I am taking a hiatus next week so won't be here to respond) but it is all a matter of connecting to the DB, sending the parameter, returning the result....

    Good luck

    Note: I forgot to mention- yeah the dropin login is GREAT! until you move the project to a server (hence why I do not like it) ... VS runs a native version of express (the .\SQLEXPRESS) this will NOT be running on your server, and will become a huge headache- be forewarned

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #10
    New Coder
    Join Date
    Nov 2010
    Posts
    81
    Thanks
    13
    Thanked 3 Times in 3 Posts
    ya that built-in one in VS (SQLEXPRESS) isn't something you use for your reasons stated.Prolly shoulda clarified I use SQL Server R2 2008 for the DB development . VS2010 for the web application .
    But ya I'm gonna still try n mess with it ..
    I got most of the process down so far.
    Connected to the DB, sending the WRONG parameter(LOL), receiving the correct result(according to the parameter...
    I'ma start with your debugging for ORDER as u suggested.. I'll let you know

    Thanks fer helpin Alykins!

  • #11
    New Coder
    Join Date
    Nov 2010
    Posts
    81
    Thanks
    13
    Thanked 3 Times in 3 Posts
    Got it ... I went back and checked everything. In the SP it was calling I saw it was selecting the ID to compare userName and password. so I changed the selector to userName and added some VB FormsAuthentication and it worked.
    So checking the SP was the key.. I feel like an idiot now :/
    Thanks Alykins!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •