[removed] Multiple parameters in __doPostBack

前端 未结 3 983
时光说笑
时光说笑 2021-01-04 05:48

First of all, the only post (calling-multiple-dopostback-from-javascript) I found about this didn\'t help my problem, so I don\'t belive this post is a duplicate.

I

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-04 06:20

    Consider placing your data in server side hidden fields and then reading that data after your postback.

    
    
    

    Your client script should include the ClientID values to handle server side naming container modifications. Using the <%= expression %> syntax (Expression Builder) requires that your script (or at least this part of the script) be maintain within your .aspx file. If you maintain your JavaScript in external files, you can "register" a simple function that gets called by your main JavaScript to move the data and compose that function server side along with the required ClientIDs. See ClientScriptManager.RegisterClientScriptBlock().

    var data1 = "data value 1";
    var data2 = "data value 2";
    $("#<%= Data1HiddenField.ClientID %>").val(data1);
    $("#<%= Data2HiddenField.ClientID %>").val(data2);
    

    Your server side code then looks like this:

    string data1 = Data1HiddenField.Value;
    string data2 = Data2HiddenField.Value;
    

    There are certainly other techniques to passing multiple data values but I have found this to be both simple and easy to maintain. You can pass all kinds of data and encode it using JSON if needed.

提交回复
热议问题