control textboxes to save typed data - c#

I am writing asp.net C# project and testing this in Chrome browser.
The page consists several textboxes: one for user name, one for email, one for phone, password, etc.
I run the project and fill textboxes. Next time when I start typing in userName textbox all the previously typed words including email,address, phone.. start to appear as hint under the textbox, for example, like in the following picture(but this is not exactly in my project):
Suppose that stack overflow is username typed before in this textbox, and stackhash_0a9e is useraddress typed before in address textbox. I want that stackkash_0a9e will not appear in this textbox, this should appear in textbox for address when user is typing there.
Is there solution of this, if so how?
Thanks

Textbox only shows that data which is entered in it, I don't know why your username textbox is also showing useraddress, probably you had entered useraddress in the username textbox. The textbox retains the previous value due to viewstate. You can disable the viewstate but it will stills shows you the previous data bcz it was also cached in browser.
To disable the cache Add the ViewStateMode to your textbox and set it to ViewStateMode="Disabled" ViewStateMode is only available in .net 4
<asp:TextBox ID="TextBox1" runat="server" ViewStateMode="Disabled"></asp:TextBox>

Related

Does a stored password Break the ASP.NET CompareValidator?

I am trying to create a registration page for my company, and so I put down Password and "Repeat Password" textboxes on my form, along with a CompareValidator. It appears to work just fine, whenever users go into both fields, type data and click the Register/Submit button.
However, I've noticed an issue where my Firefox browser during testing saves a password that I entered. After it's saved the password, if I then go back to the page "fresh", it shows the password already filled in the Password field (though not in the "Repeat Password" field for some reason).
Anyways, if I then populate the e-mail address, I can then click the Register/Submit button with no issues at all!
The most concerning thing is, when I debug into the CodeBehind and even force a validation by triggering both the control's Validate method and the Page's Validate method manually, it still somehow PASSES the validation even though, as you can see in the QuickWatches in my screenshot below, the fields have two different values!
Have I found a bug that I should report to Microsoft, or is it possible that I did something wrong in setting this all up? All I did was plop the CompareValidator on the form, and set the "ControlToCompare" to "txtUserPass" and the "ControlToValidate" to "txtRepeatPass", and the Operation is set to "Equal".
Am I perhaps doing something wrong here, or have I found a genuine bug caused by browsers storing passwords?
As specified on the documentation, the CompareValidator does not trigger for empty values:
If the input control is empty, no validation functions are called and validation succeeds.
Use a RequiredFieldValidator control to require the user to enter data in the input control.
You need to combine the CompareValidator with a RequiredFieldValidator.

Using multiple placeholders on a page?

Currently on my website when a user logs in if their role in their row within the Users table is equal to 0 it will give the user 3 options on options.aspx, however if not it will take them to home.aspx
Now I am trying to just do this on one whole page, so if the user was to be directed to the options page, instead it would take them to the home page where the user would have to click an option amongst the 3, if the user has already selected an option then it would load a different content placeholder.
Is a content placeholder what I need to achieve my idea? If so, wouldn't it be abit too easy to get out of the situation since the client could inspect element and edit the visibility on their side?
When you set the Visible="false" property on a server-side control (runat="server") the tag is NOT rendered to the browser. As a result, the client cannot set it as visible. So for example:
<asp:PlaceHolder runat="server" Visible="false">SomeText</asp:PlaceHolder>
The SomeText will be nowhere to be found in the HTML if the user does View Source. If, however, you do a CSS style on a control such as style="display:none" then your concern is 100% valid as the user could just show this.
This same logic hold true for any ASP.NET server-side control. If you set Visible="false" it's never sent to the browser.

MVC auto complete inputs according to recent user entries

I have a site that manages a database.
Lets say the users enter information about people (height, weight, name etc...)
A lot of people are entered each day and the height range is quite small so if a user entered a person with a certain height I want it to auto complete next time he enters a person.
(like most login forms where you click a textbox and it shows your recent entered login info and when you start typing it auto completes you).
I am using MVC 4 and the person entry is not within a form. When a user clicks save it uses ajax to save.
I know it works with forms but how can I do it on certain textboxes which arent in a form.
The jQuery autocomplete solution doesn't require fields to be in a form.
If you look at the source code of the sample, the previous data is stored as a JavaScript array. You could store previous entries for each user in a database and then use this data to build an JSON array that can be passed via a view-model to the view and then use jQuery.parseJSON() to render it straight into place in the JavaScript.

WinRT - Programmatically tab to next control in C# code behind

Once I successfully validate user data in a TextBox (using TextChanged EventHandler), I'd like to programmatically tab to the next input control. I know I could hard code the name and do
Score2.Focus(Windows.UI.Xaml.FocusState.Keyboard);
but I've got 20 TextBox controls on the page page and I'd like to use the same EventHandler for all of them.
While it may be possible (iterate through the page's control inspecting their tab order and selecting the appopriate next control), I would recommend against it. It will irritate your user if they leave a text box to go back and correct a previous field but your app decides it knows better and gives focus to another field.

Don't post back textbox

I have a fairly complex form (user control actually) with one textbox control on it that needs to NOT post back. Is there a way to remove a control from the post? Yes, this textbox is editable.
More info: This is for a credit card processing form, so the "final" submit will post to another site's page. However, prior to this there is plenty of server-side processing that goes on. I know that I can move the the credit card number text box to another page - but this requirement came very late and I'll trying to not have to re-work a lot of things.
The easiest way would be to use an html input as opposed to an ASP TextBox. These are not accessible from code if runat="server" is not set on them.
Or use the viewstate property (http://msdn.microsoft.com/en-us/library/system.web.ui.control.enableviewstate.aspx)
So the situation is that you have a form that is rendered in the user's browser with an action pointing to a different site and you need to make sure that one of the form fields will not be sent when the form is submitted.
Sounds to me like you cannot in that case make absolutely sure that the value is not posted. There are many different possible ways to solve this using javascript (disable input, clear value, etc before submit) but if scripting is turned off I think you're out of luck.
But since you can prepare for sending the form to the other server (change action on form or enable button with PostBackUrl), I guess you could also then set the Enabled property on the textbox to false. That would mean that it can no longer be edited on the final page beforr posting to the other server. Or you could hide the textbox a (so it's not renered at all) and show the field as a label or literal instead.
But even then you still have to somehow make sure the secret value is not included in the viewstate of the form. Which it will be in case you use a label or literal. And also for a textbox that was disabled or hidden on the last postback. Normally the viewstate is just a base64 encoded string so it would be trivial to find the credit card number from there. You could probably fix this by turning off viewstate for the control in question (or even for the whole page) in the last post back to your page before setting the form up for posting to the other server.
If you cannot tell for sure which will be the last postback to your server, then I think you're out of luck without more significant changes. Sorry to be a downer. Some seemingly trivial things are just hard with Asp.Net web forms.
Maybe you could add a separate page that you populate with just the data that you need to send to the other server and have that a sort of "Confirmation page". In that page you could turn off viewstate, show all the data summarized (using labels and literals etc) and the actual data to post could be included in the form as hidden fields. Then that form would post to the other server when the user "Confirms".

Categories

Resources