Execute client and server code with one click?

I'm not sure that my design has a flaw, but I would like to know what others are saying, I am in a situation where I try to achieve two things with one click.

using: asp.net web form

I have a web form with several text fields and a grid and button control.

if i click on the button i do two things

1) asynchronously receives data from server to client (works fine) and is able to display data in text files.

2) the same click that I want to associate with gridview.

<asp:Content ID="Content2" ContentPlaceHolderID="cphMaster" runat="server">
     <asp:Label runat="server" ID='Label1' >Id:</asp:Label>

        <asp:TextBox ID="txtId" runat='server'></asp:TextBox>

        <asp:Button ID="btnSubmit" OnClientClick="LoadDataById();" runat="server" Text="Submit" 
         onclick="btnSubmit_Click" />
        <br />
         <br />
        <asp:TextBox ID="txtName" runat='server'></asp:TextBox> <br />
        <asp:TextBox ID="txtPurpose" runat='server'></asp:TextBox>    <br />
     <br />

     <asp:GridView ID="GridView1" runat="server">
     </asp:GridView>
</asp:Content>

server side

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            GridView1.DataSource = laodData(int.Parse(txtId.Text));
            GridView1.DataBind();
        }

Jquery:

function LoadVisitBasicByVisitId() {


    ContactServiceProxy.invoke({ serviceMethod: "GetDataById",
        data: { request: request },
        callback: function(response) {

           processCompletedContactStore(response);
        },
        error: function(xhr, errorMsg, thrown) {
            postErrorAndUnBlockUI(xhr, errorMsg, thrown);
        }
    });
    return false;
} 

summary:

1) jquery script execute asynchronously to get data from server to client and display in the textboxes
2) server side code to bind the gridview.

Problem:

if I have onClientClick = "return LoadDataById (), then it executes ONLY ajax code and does not execute server side

onClientClick = "LoadDataById(), , wipeout ( popuplate ajax)

+3
2

jquery true, . false .

onClientClick="return LoadDataById();"

+5

- , , , .

false jQuery, .

0

Source: https://habr.com/ru/post/1746049/


All Articles