views:

431

answers:

2

Hi,

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.

  1. 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.

  2. Set <asp:parameter name="SampleValue" /> and in the EditTemplate <asp:TextBox Value='<%# Bind("SampleValue")#> The values are always null.

  3. 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

A: 

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.

harpo
+1  A: 

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.

Chris Westbrook