[RESOLVED]How to pseudo click Update link button from javascript

Hi,

How can I click a Formview Update link button from javascript ?

Hi shtrudel,

From your description, if you want to add client event for update button, you could refer to the following code.

    <script type="text/javascript">
        function updateClick() {
            alert("Update?");
            return false;
            
        }
    </script>

        <asp:FormView ID="FormView1" runat="server" DataKeyNames="Id" DataSourceID="SqlDataSource1" OnItemUpdating="FormView1_ItemUpdating" DefaultMode="Edit">
            <EditItemTemplate>
                Id:
                <asp:Label ID="IdLabel1" runat="server" Text='<%# Eval("Id") %>' />
                <br />
                Name :
                <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
                <br />
                Gender :
                <asp:TextBox ID="GenderTextBox" runat="server" Text='<%# Bind("Gender") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" OnClientClick="return updateClick();" CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            ...

        </asp:FormView>

If you want to trigger update button click event from JavaScript. You could refer to the following code.

document.getElementById('<%= FormView1.FindControl("UpdateButton").ClientID %>').click()

If you have any other questions about my reply, please let me know freely.

Best Regards,
Dillion

Leave a Reply