Re: [RESOLVED] On Focus...
One more question...
When I click on the submit button I have it redirect to "#" for testing. When this happens the postback repopulates the login textbox.
VB Code:
Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Response.Redirect("#")
End Sub
Re: [RESOLVED] On Focus...
Thats because ASP.NET has a different State Management that classic ASP. Read about state management on MSDN.
If you want this should not happen then set EnableViewState of the control to False.
Re: [RESOLVED] On Focus...
Ok, thanks. I'll look it up. :)
Re: [RESOLVED] On Focus...
I tried setting it to false in the page_load but if i type in a username and submit, it repopulates it with "Enter UserName" :(
Re: On Focus... Still 1 more issue
You must be calling a function in the body onload that populates that textbox. Instead of calling the function in body load, send a call to it to the output using Page.RegisterStartupScript.
In your page load event:
VB Code:
If Not Page.IsPostBack
Page.RegisterStartupScript("myscript","nameofthefunction();")
End If
Re: On Focus... Still 1 more issue
I did this in the page_load event procedure
VB Code:
If Page.IsPostBack = False Then
Me.txtUsername.Text = "Enter UserName"
End If
Me.txtUsername.EnableViewState() = False
It appears to work but I wont be 1000% until I finish creating the db and writting the login code.
Does this look correct now? I did have the textbox being populated in the aspx element tag in the html section.
Re: On Focus... Still 1 more issue
Re: On Focus... Still 1 more issue
Re: [RESOLVED] On Focus... Still 1 more issue
Actually if you had done your response.redirect to the name of the page "default.aspx" for example, it would not have retained the settings.
When you redirect to an anchor, it instead of redirecting the page just sends the browser a different URL, but maintains state. It does this to help, not hinder, your coding.
Just letting you know that you just killed the proverbial fly with an elephant gun.
Re: [RESOLVED] On Focus... Still 1 more issue
Well I like overkill but I just dont have a second page to redirect to yet. I'll test it out with a dummy page.
Re: [RESOLVED] On Focus... Still 1 more issue
the second page I speak of is the same page.
Lets say the "test" page was called "test.aspx" then what I was saying is instead of redirecting to "#" you redirect to "test.aspx" (which is the same page).
Re: [RESOLVED] On Focus... Still 1 more issue
I'm still new to asp.net but I did redirect to the same page and it didnt retain the login name I used. It repopulated it with the "Enter UserName" again. Is this what you meant?
When it goes to a secondary page it shouldnt be populated at all since they will already be logged in.
Re: On Focus... Still 1 more issue
Ok, related issue still here. The login txtUserName textbox contents should be added to the User_Name session variable but its not retaining or able to even be placed into a label control. :(
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'Login code
If Session.SessionID Is Nothing Then
'code to alert or redirect to login in again
Response.Redirect("index.aspx")
End If
If Session.Item("sesUser_Name") = Nothing Then
Session.Add("sesUser_Name", "RobDog888")
End If
If Page.IsPostBack = False Then
Me.txtUsername.Text = "Enter UserName"
End If
Me.txtUsername.EnableViewState() = False
End Sub
Re: On Focus... Still 1 more issue
Maybe you left it out accidentally but it does not look like you are inserting the contents of the sesson variable anyway :)
Something like:
VB Code:
If Session.Item("sesUser_Name") = Nothing Then
Session.Add("sesUser_Name", "RobDog888")
Else
If Page.IsPostBack = False Then
Me.txtUsername.Text = "Enter UserName"
Else
Me.txtUsername.Text = Session.Item("sesUser_Name")
end if
end if
?
Re: On Focus... Still 1 more issue
Sorry, forgot to post the btnLogin click code. RobDog888 was a test. Like a temp guest user id.
VB Code:
Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If Session.Item("User_Name") Is Nothing Then
Session.Add("User_Name", Me.txtUsername.Text)
End If
Me.lblUserName.Text = Session.Item("User_Name").ToString 'THIS IS NOT POULATING MY LABEL :(
Session.Timeout = 15
'...
End Sub
Btw, thats a really nice looking forums site in your sig. vBull 3.5 :)
Re: On Focus... Still 1 more issue
is btnLogin your submit button? If so I recommend placing that code in the page load event. Check if you have a username posted and if so add it as a session variable. Elseif check if a session variable is already present and if so place it in the text box.
Then again, I could just be showing my ignorance of ASP.NET. Sorry :(
Re: On Focus... Still 1 more issue
This is the home page so to be able to login only once and access the secured pages it needs to check on the page load for if they just refresh or renav to the home page after they already logged in. Now if they havent logged in at all then the pageload will not have a txtUserName content to load into the session var. It needs to ignore the "Enter UserName" auto text htat I had populated in the js in the html for the page as shown by Shuja Alis posted code.
So it seems that when the postback happens it doesnt pickup the session var. :(
Re: On Focus... Still 1 more issue
w00t, got it. It was the stupid Session.SessionID check that was throwing it off. This now retains the uisername (without any verification of login yet) and populates a label control with the username and starts the session timeout of 15 minutes and redirects with SSL. :D
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Session.Item("User_Name") = Nothing Then
Session.Add("User_Name", "Guest")
End If
If Page.IsPostBack = False Then
Me.txtUsername.Text = "Enter UserName"
End If
Me.txtUsername.EnableViewState() = False
End Sub
Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If Session.Item("User_Name") Is Nothing Then
Session.Add("User_Name", Me.txtUsername.Text)
End If
Me.lblUserName.Text = Session.Item("User_Name").ToString
Session.Timeout = 15
Response.Redirect("https://secure.blah.com")
End Sub
Now I just need to clear the txtUserName box and clear the lblUserName upon page load to take out the control name thats in it by default.
another step closer. :)
Re: On Focus... Still 1 more issue
Glad to not be of assistance :D
Re: On Focus... Still 1 more issue
But a second set of eyes is always a help. :) I noticed that when you reposted my code my sesUser_Name var was named differently then it was in the btnLogin clck event. ;)
Now I am multi-tasking and in the middle of creating the users sql table.
Thanks everyone :thumb:
Re: On Focus... Still 1 more issue
Quote:
Originally Posted by RobDog888
But a second set of eyes is always a help. :) I noticed that when you reposted my code my sesUser_Name var was named differently then it was in the btnLogin clck event. ;)
Now I am multi-tasking and in the middle of creating the users sql table.
Thanks everyone :thumb:
You are still here. :eek:
I though you would have finished your project by now. :)
All the best. :thumb:
Re: [RESOLVED] On Focus...
Thanks but unfortunately I am a noob at asp.net so its going to take some time. :(
Ps, I have 5 or 6 hours left to finish the entire login and security part. :cry: