DukeBrymin DukeBrymin - 1 year ago 78
ASP.NET (C#) Question

Would like to trigger Update button inside a DetailsView from external button

I'm working in ASP.Net Webforms, and I have a DetailsView that has, for its last Template, the Update and Cancel buttons:

<asp:LinkButton ID="MyUpdateButton" CommandName="Update" Text="Update" runat="server"></asp:LinkButton>
<asp:LinkButton ID="MyCancelButton" CommandName="Cancel" Text="Cancel" CausesValidation="false" runat="server"></asp:LinkButton>

For esthetics, I want to move those buttons outside of the DetailsView. However, in doing so, I lose the ability to trigger the
handler. I can add an
handler to the buttons, but then I lose the
data, and it doesn't call the validators.

So, I thought, "why not have a button outside the DetailsView that calls the .click() on the button inside the DetailsView?". So I wired up another button, made the current Update button invisible (via
'style="display: none;"'
) and set the
for the external button to a function that finds that internal button and calls the .click() handler on it. I've tested that function, and it's working the way it should, in that it finds the right button. But it still doesn't trigger the

Any thoughts on what I might be doing wrong? Or a better way to trigger that button (internal to the DetailsView) from an external button?

Answer Source

According to my tests, simulating a click on a LinkButton does not trigger a postback. You should replace the hidden LinkButton by a hidden Button:

<asp:Button ID="MyUpdateButton" CommandName="Update" Text="Update" style="display: none;" runat="server" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download