I am developing a form using all asp:textbox and asp:label. Currently, I am using the RequiredFieldValidator to validate text boxes and display an error inline. What I am trying to do is to change the color of one of the asp:labels after validation fails for one of the textboxes fields. Would I accomplish this with javascript, or is there any commands that can do it within asp to modify labels. I would really appreciate any help and code examples.
I'd say that javascript is the way forward here if you don't want to postback to the server. If you use ASP.NET only the page will normally have to be posted back so that the server can change the properties of the label - not very user friendly. A colleague of mine has accomplished this very nicely using JQuery (a javascript libraray) but unfortunatly I don't have a copy of the code to hand. He's an SO user too so I'll pass on a link to this post for you.
Related
I have text-box and grid-view is present in same asp.net page. while typing some text in text-box I want suggestions, if text is present in data grid-view.
Example: Google Suggest.
What will be the procedure to achieve this.
There are several ways to get this done.
Since you're using asp.net (if you're using webforms) you can use the ajax control toolkit which has a combobox control
http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/ComboBox/ComboBox.aspx
Or you can go with jquery ui
http://jqueryui.com/autocomplete/
There are many other plugins and frameworks you can try, but these two are pretty basic.
By jQuery hint plugin i mean a plugin which shows a line of guiding text like "Enter your name here ..." inside an input.
When i use such a plugin in combination with jQuery asp.net mvc clientside validation it will validate against the hint when it is actually empty.
Im wondering if there is already a plugin which plays nice with the jQuery asp.net mvc clientside validation, meaning that it either clears the input of the hint on validation or simply ignores the contents of the input if its equal to its hint.
Took the time to create a plugin myself. This plugin doesnt show the description/hint inside the input but on top of it.
http://plugins.jquery.com/project/Description
I'm writing an ASP.NET app in which a table of objects is created by the user client-side.
I envisage them clicking "Add item" and a new 'row' is created in the table with textboxes for them to enter their stuff.
I can do this fine by adding HTML with jQuery. The problem is that one of the fields in the row for the user to fill in needs to be a colour picker.
I have an ASP.NET web user control for my colour picker. How do I add an instance of it to the page within my html row? Or am I barking up the wrong tree here - is there a better way of encapsulating the functionality of my colour picker so that it can be put on every row?
No, you can't add a server-side asp.net control to a page that has already been rendered using client-side techniques (aka Javascript)
Two options:
Firstly, switch to using a client-side colour picker. You can then have the data from this included in the post-back by dynamically adding hidden fields to your form.
Secondly, have a single editing panel which includes your colour picker. Users then select a row to edit, which updates the edit panel with current values etc. Values are stored in hidden fields created when you dynamicaly add rows to your table, and included in the post-back
Without seeing your UI, I can't comment as to which would be best. The asp.net control might look nicer, but it might be difficult to work into your design. A pure client-side solution might fit your designer better, but might not look so good. You also need to consider what happens if / when a users adds lots of rows (this might be 10, 50 or 100 depending on your app /code). Lots of dynamically added controls (the first solution) might cripple the performance of the page.
I'm not sure what version of ASP.NET you're using, one approach that would work is to turn your usercontrol into a custom control. You'd then need to implement ICallbackEventHandler (the first way to do Ajax on asp.net); for sure it's a bit more work but it does give you a good level of control.
Alternatively, you could try this
You can't add ASP.NET controls with jQuery (at least not easily). You could, however, perform a postback when you need to add the colour picker to the row.
In the code in front declaratively define a template of what the new row should look like, then hide it using css.
When the user clicks the 'Add new button' select and cloen the contents of your hidden template and write that into your target div. Just make sure to remove the hiding css when you do this.
You will, of course, just be copying the rednered html of your server controls, but htis apporach may give you a quick and easy way of doing what you need
I'm struggling with an issue I just can find a solution for.
First of all, I can't use asp.net AJAX or anything else thant standard asp.net 2.0 as the server admin won't install anything else.
So here is, what I try to do. (For the curious, skip to the bold question below)
My page consists of several parts, each of which gets loaded by jquery.load(url). One of these page parts gets filled with an aspx that contains a form view. As I don't want to have postbacks, I switch to the EditTemplate of the form view by a simple click on a regular html button that submits a parameter indicating the aspx page to switch to edit mode, e.g.
Page_Load(...)
{
if(Request.Params["SwitchEditMode"]) SwitchEditMode();
}
This works perfectly! Now here the part where I'm stuck. The elements in the EditTemplate are based on a select from a database view and bound to the fields by <%# Bind("xx"). Then I have a html button (no asp control) that submits a parameter to the aspx page that tells it to invoke the DataSource update method. In the dataSource_updating method I look for the controls that contain the values I want to save. But these values are always the same, as when I switch to the edit view. No changes I make in the textboxes or dropdowns are preserved.
A long story short, the question how to save the values from EditTemplate back to the database with jquery?
Up to now I tried several approches, that didn't work out.
In the updating() method look for the controls by FindControl and set e.Command.Parameter["xyz"] = foundcontrol.SelectedValue;. The values are always the same as in the beginning.
Set <asp:parameter name="SampleValue" /> and in the EditTemplate <asp:TextBox Value='<%# Bind("SampleValue")#> The values are always null.
Set a hidden input field with the selected value via javascript. This doesn't work as the control within EditTemplate are only visible after the switch into edit mode
So maybe I'm totally wrong with my ideas, heading into a totally wrong direction and this can be accomplished much easier, but up to now I don't know how to achieve this. I could do it without ajax, but for the user experience I'd prefer the version with jquery.
For all that have read this far and not got confused :-), thanks for your effort!
Best regards,
Andreas
I would forget using a form view and just use a regular html form with regular input controls. Return an object from your web service that has all of your values and populate the controls with ajax and then subjmit with ajax. Either do fully asp.net or fully html/jquery with asmx back end. Otherwise it's just too confusing.
If you load both "modes" of the FormView into the same page using AJAX, you're probably getting duplicate field names. One of them contains the unchanged values which are being saved. How will ASP.NET know the difference? You only want to submit the ones from the EditTemplate, which will require a separate form (or some other hack).
Or perhaps your HTML submit button isn't giving ASP.NET what it needs to repopulate the controls. Are you using ViewState in the page with the FormView?
All in all, this sounds like a hairy combination of technologies... as you well know.
iam into problem of reading the value of the control which i alterd using javascript
the sequence goes like this
i got the text box control by using its id
cleared the value of the text box
make the control disabled.
when i tried to retrive the value of the textbox in aspx.cs
iam still getting the old value of the text box which i actualy cleared in the javascript
kindly suggest me to over come this issue
Thanks
Disabled input controls don't get their values posted back so ASP.Net doesn't know you changed the value. You need to enable the control.
With ASP.NET Web Forms, IDs for elements get assigned automatically by the Page on the server side. It is tricky, but possible, to manipulate element values using javascript. One way to avoid this would be to use ASP.NET MVC where the HTML would be rendered as is and javascript or jquery can be easily used to "play" with the HTML elements. We need more information to help you with the details of your request.