Reputation: 2075
is there a way to save a detailview that is in Edit Mode from another button that is not part of the DetailView? In other words i have a detailview that is in edit mode and has the Save or the Update button but sometimes the users forget to click the Save button and they just go ahead and click another button that is the bottom of the page. I want to make sure the data they entered in the DetailView to be saved first when they click the other button. I have this command names:
<EditItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="True"
CommandName="Update" Text="Save Changes" />
<asp:Button ID="Button2" runat="server" CausesValidation="False"
CommandName="Cancel" Visible="false" Text="Cancel" />
</EditItemTemplate>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="False"
CommandName="Edit" Text="Save Changes" />
</ItemTemplate>
this is what i have done after your suggestion:
Upvotes: 0
Views: 79
Reputation: 1299
One way that may work, depending on the other button they click, is to have the other button click the update button before doing its action. However, if the other button posts back to the server, then one or the other may not work correctly.
If the other button is an asp:Button, then you could add the following tag (please note, since you are adding javascript you will need to get the client ID of Button1 - I usually do this with a prefix because I can never remember how to get the ClientID inside of a server tag):
OnClientClick="document.getElementById('MainContent_DetailsView2_Button1').click();"
You need this prefix because ASP automatically creates unique IDs that are nested inside of the parent control.
Upvotes: 1