I have done this many times in PHP using JS but being new to webforms I'm really struggling on this one...
OKay, on my form I have an "asp:TextBox" that I want the user to enter an amount of money into.
What I would like is once the user moves out of the "asp:TextBox", I would like it formatted like ###,###,###.## for display purposes. I dont need the currency symbol.
Can anyone give any guidance on how to do this and also is the formatting submitted along with the value on submit as standard or is that stripped away and only used for user display purposes?
Thanks
Paul
You can add client-side functionality to webform controls by adding attributes to them before they get rendered. You can add a property to the textbox in your code:
myTextbox.Attributes.Add("onblur", "myJavascriptFormattingFunction();");
You can take a look at this article for other methods of linking webcontrols to javascript.
Whatever value is in the textbox itself is what will be submitted, so if you add commas and whatnot, then they will be submitted.
Related
In my Content page I have 4 different TextBox's which is used to enter phone number - Mobile, Office Phone, Office Mobile & Other. I have RegularExpressionValidator for each.
I want to make sure atleast one of the above 4 textbox's has entered a value. I didn't find any example or article on net showing this situation. One way I think is in Submit button click, before Page.IsValid call, call a function that checks that one of the control has valid value. If the function returns false, show MessageBox. Is their any other way using Validators or so to comfirm that one textbox out of 4 has a valid value.
What can be the best way to achieve this ?
Any help is highly appreciated.
Thankss
You can create a Custom Validator in ASP.NET.
This post should help you out.
asp.net required field validator for at least one textbox contains text
Am working on Ektron 9.I have created an ektron html form with n number of fields.
Suppose i have a radio button list(Choice Field) following a text field.My choice radio button list has
two values Yes and No and the end user select one of those values.
I need to make the following text field required if the user select Yes in the choice radio button list.If selected No no need to make the text field required.
Is there any way to achieve the same by ektron custom validation?i have tried that but when am checking the fields the choice field not listing in the the insert field part of validation tab.
Is anything wrong with me ,if not anyone suggest a solution for this?
Custom validation like you describe is not possible with standard Ektron HTML forms. Your best bet would be to create an ASPX web form to achieve what you need.
There is the possibility of creating the HTML form, displaying it on an ASPX page and then adding your own custom javascript. However this is error prone as the HTML form and JS are very closely tied together. You are better off using an ASPX web form, and not an Ektron HTML form for this.
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".
I need to be dynamically build controls like textbox, checkbox, radiobutton etc by making a Ajax request and downloading the HTML. However once enough controls are on the screen and user submits the form, I need all the controls and it's posted values. Posted values are easy to get using Non sequential indices in Asp.Net MVC. But, how do I get which control's value it is? Put simply if the form has submitted the value "Hello World". I need to be able to know from where did the Hello World. Was the textbox that submitted this value or the textarea?
I don't need anything else like ID, name etc. Just need to know the type of control whether it was texbox, textarea, select or which one.
when you dynamically build these client elements, you give them a name so they will post to the server.
just follow a naming convention like:
textarea1,textarea2...
txt1,txt2,...
then at the server, to collect the values - take all the keys that start with textarea to collect the values of textAreas...
a nicer way will be to have a model with lists for each type, and when you generate the client elements, build their names so the values will be mapped to the correct list by the ModelBinder
the syntax for these names is a bit nasty so work with client templates
I used this post by haacked when i needed to build something like this
You need know more about http get or post.
There is another relevant question asked Validation Check in asp.net
In the same scenario we need a custom validator control which will alert user for any wrong entry. This will work like this :
Developer will pass the control-name, input-value and format-required
For instance like for textbox it can be: txtName,txtName.Text, allow-alphabets-only
The accordingly format if the user input is invalid he/she will be got prompt.
Please suggest the right way to do the smae.
Thanks in advance.
You've described the default behaviour of all asp.net validators (pass control to validate etc).
What you want to achive (eg, alpha charaters only, or alphanumeric only etc) can be achieved mostly with the RegularExpressionValidator.