View Full Version : Problems with LoginName control returns.

11-02-2011, 05:22 AM
I'm just wanting a simple return on "Welcome, [UserName]" like on this site..

I have the right code I believe :

<asp:LoginView ID="LoginView3" runat="server">
Welcome to Some.Com Guest
<asp:LoginName id="LoginName1" runat="Server" FormatString="Some.Com Welcomes You Back,{0}"></asp:LoginName>

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?

11-02-2011, 02:49 PM
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

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

11-02-2011, 07:43 PM
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)

11-02-2011, 09:17 PM
what is it returning?
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
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?

11-02-2011, 10:06 PM
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:

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. :thumbsup:

11-03-2011, 01:28 AM
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

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

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


or something like that *doing it on the fly w/o my trusted intellisense :p
... 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

create proc usp_selectUserName @index int, as
select [user_name] from tbl_users where PK_ID = @index

11-03-2011, 01:38 AM
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

<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

11-03-2011, 06:49 AM
LOL .. I was lookin at that trying to comprehend the C# logic .. I got the jist of it :thumbsup: ..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 :confused:

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

11-03-2011, 02:41 PM
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

Dim A as string
Dim B as string

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 :(

11-03-2011, 06:45 PM
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 :thumbsup:. VS2010 for the web application :D.
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 :p

Thanks fer helpin Alykins!

11-05-2011, 04:42 AM
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!