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
Consider placing your data in server side hidden fields and then reading that data after your postback.
<asp:HiddenField id="Data1HiddenField" runat="server" />
<asp:HiddenField id="Data2HiddenField" runat="server" />
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.
You could pass the two values as one JSON string:
function OpenSubTable(bolID, controlID) {
__doPostBack('UpdatePanelSearch', JSON.stringify({ bolID: bolID, controlID: controlID}));
}
And then parse it on the server:
protected void UpdatePanelSearch_Load(object sender, EventArgs e)
{
SomeDTO deserializedArgs =
JsonConvert.DeserializeObject<SomeDTO>(Request["__EVENTARGUMENT"]);
var bolID = deserializedArgs.bolID;
var controlID = deserializedArgs.controlID;
}
public class SomeDTO
{
public string bolID { get; set; }
public string controlID { get; set; }
}
If you're using .Net >=4.0, I believe you can deserialize to a generic touple and avoid having to create SomeDTO
. Edit: More information about deserializing to dynamic types.
I have used multiple parameters before by building and splitting a string.
eg
string args = String.Format("{0};{1}", bolID, ControlID);
You can then pass this in to the arguments for the postback, and when checking for the postback arguments just split the string based on your speration character (in this case ';')