J
joey.powell
I have a home page with username and password textboxes and a login
button for purposes of users being able to log in (forms
authentication) directly on the site home page. I also have a dedicated
"Login.aspx" page, but I don't want users redirected there unless
absolutely necessary.
I have registered a javascript block via "Page.RegisterStartupScript"
that sets focus to the "txtUserName" textbox control on Page Load. It
works great for IE and Firefox.
But...
The problem is that the "txtUserName" textbox does not exist once the
user has logged in and the page posts back. The code behind then knows
that the user is authenticated, and so it does a ".Visible=false" for
the "txtUserName", "txtPassword" and "btnLogin" controls.
Then, when the page loads after the postback, the javascript block
causes an error icon in the lower left corner of the browser.
Apparently it is still trying to set focus to the control? I thought I
had this fixed when I set the code behind to register the page startup
script only when the page loaded for the first time...but that didn't
work for some reason, because it still tries to set focus on postbacks.
I also tried disabling the page viewstate along with the above, but
that didn't work either.
Can the javascript block be coded to test if the "txtUserName"
(document.txtUserName ?) textbox exists before trying to set focus to
it? If so then that would do it...but how would the code look? Also, is
there another solution that I am not seeing here? I need to get this
working correctly.
Any suggestions are appreciated. Thanks.
button for purposes of users being able to log in (forms
authentication) directly on the site home page. I also have a dedicated
"Login.aspx" page, but I don't want users redirected there unless
absolutely necessary.
I have registered a javascript block via "Page.RegisterStartupScript"
that sets focus to the "txtUserName" textbox control on Page Load. It
works great for IE and Firefox.
But...
The problem is that the "txtUserName" textbox does not exist once the
user has logged in and the page posts back. The code behind then knows
that the user is authenticated, and so it does a ".Visible=false" for
the "txtUserName", "txtPassword" and "btnLogin" controls.
Then, when the page loads after the postback, the javascript block
causes an error icon in the lower left corner of the browser.
Apparently it is still trying to set focus to the control? I thought I
had this fixed when I set the code behind to register the page startup
script only when the page loaded for the first time...but that didn't
work for some reason, because it still tries to set focus on postbacks.
I also tried disabling the page viewstate along with the above, but
that didn't work either.
Can the javascript block be coded to test if the "txtUserName"
(document.txtUserName ?) textbox exists before trying to set focus to
it? If so then that would do it...but how would the code look? Also, is
there another solution that I am not seeing here? I need to get this
working correctly.
Any suggestions are appreciated. Thanks.