views:

439

answers:

1

Hi,

I have developed a user-control which gets bound to an id-field and then enables editing of records from (various) other sources (linked via this id). This is working fine, but I am struggling to save the data when the form is saved - obviously there's more to be done than "just" writing the id back.

I wouldn't like to add extra buttons for the "inner update", but was hoping to understand the ASP.net-mechanisms well enough to do this they way it should be done. Unfortunately I'm not getting anywhere (and time is running out), so I hope someone could share some insight on how to get this integration working, which events to look at etc.

Thanks in advance :)

Michael

Edit: thanks for your comments, I'm trying to give more details on the idea:

<FormView...
   <EditItemTemplate...
      <table...
          <asp:Textbox text="<% Bind('bla1') %>...
          <uc1:MyControl id1="<%# Bind('bla2') %> editeable="True"...
          <asp:ImageButton CommandName="Update"...
...
   <ItemTemplate...
      <table...
          <asp:Textbox text="<%# Bind('bla') %>...
          <uc1:MyControl id1="bla" editeable="False"...

This user-control uc1 displays a whole lot of related records (based on id1) - and in edit-mode also enables editing/adding etc. of these "inner" records. Now, since users have a "standard-way" of saving-records, I don't want to interfere by adding a special save-method just because we happen to edit some internal records elsewhere. That shouldn't matter to the user, UI should behave the same. So that means that I'll have to take care of saving internally. But how do I know the user wants to save and what would be a best practice to handle this? Is there a way the user-control could be "notified" about the Update-event on the containing control, would I have to make it explicit by customizing the Update-command etc. We're trying to make it robust and general enough, so that it could easily be re-used. (Still hoping that doesn't contradict ;))

+2  A: 

The way I understand this problem is that you have a button on your webform, but none on your usercontrol. Then when the button is clicked, you want to persist the changes made on the usercontrol. If this is the case, why not create a method on your usercontrol that saves all the changes made, and call this method from the click event of the button on the form?

Ravish
Thanks Ravish, guess that's what I'm gonna do. I was hoping there might be a way to catch this event "internally", so that I'd only have to modify the usercontrol (and its events), but not having to touch the containing control.
MBaas