Friday, March 16, 2012

login panel doesnt remember username and password?

I have a simple username, password, image for submit that will not remember the password or submit the form when I hit enter on the password input? The textboxes remember email addresses from other sites, but not for my site. Do I have to change the name or id of the input box to email for the form to remember it? Not sure what I am doing wrong. Also when you hit enter on the password input box it submited the form on the old site can I do that with an image?

<asp:PanelID="_pLogin"runat="Server"Visible="true">

<formmethod="post"name="frmLogin"action="/login.aspx">

<scriptlanguage='JavaScript'type='text/JavaScript'>

document.write("<input type='hidden' name='tzoffset' value=" +new Date().getTimezoneOffset()/-60 +">")

</script>

<divid="login">

<divclass="loginInput">Username:<br/>

<inputid="username"name="username"type="text"maxlength="128"/>

</div>

<divclass="loginInput">Password:<br/>

<inputid="password"name="password"type="password"maxlength="32"/>

</div>

<divclass="loginBtn"><imgstyle="cursor: pointer;"src="/assets/img/login_btn.gif"name="login"onclick="frmLogin.submit()"width="21"height="21"/></div>

</div>

</form>

</asp:Panel>

Hey,

ASP.NET viewstate only captures and remembers values where view state is enabled, and for controls that have runat="server". Try adding runat="server" to those controls... As far as the enter key, if you are using ASP.NET 2.0, you can set the DefaultButton property on the panel to the ID of the button to use that functionality for.


Tried all of that still having issues. Won't remember the username and password and still can't submit even though I have the defaultbutton set to the image. I even tried changing the image to an image button. Does it have something to do with the javascript I have inside of the panel? Any other suggestions? Help or tutorials would be greatly appreciated. Thanks

BC


I found only one answer to this problem, although there probably is a much better solution.

You can store values in the viewstate. If you store the username and password in viewstate as soon as you have them, like this:

viewstate("username") = strUsername

They can always be recalled on post-back like this:

strUsername = CStr(viewstate("username"))

or

tbxUserName.text = CStr(viewstate("username"))

Hope this helps. It works for me.


Hey,

One other thing, an ASP.NET page shoudl have a form with runat="server" and all ASP.NET controls inside of it. ASP.NET does not do form redirection like you have setup. To redirect, either use Response.Redirect in the button click event handler, or new to ASP.NET 2.0 is the PostBackUrl property of all buttons, which specifies the page to post to. Use that instead. But, for your viewstate problem, the form could be causing the problem.

0 comments:

Post a Comment