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 have this JavaScript function in my ASPX webpage that includes a __doPostBack function:
function OpenSubTable(bolID, controlID) {
// code
__doPostBack('UpdatePanelSearch', bolID);
// more code
}
Works perfectly and I can get the value of bolID into my code behind like this:
protected void UpdatePanelSearch_Load(object sender, EventArgs e)
{
var bolID = Request["__EVENTARGUMENT"];
// code
}
The problem is, that I have to pass 2 different values through the postback. Are there any simple solutions to this? Obviously something like this doesn't work:
function OpenSubTable(bolID, controlID) {
// code
__doPostBack('UpdatePanelSearch', bolID, controlID); // not that simple, i'm afraid :(
// more code
}
Any help would be most welcome.
Regards, Gunnar
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 requiredClientIDs
. SeeClientScriptManager.RegisterClientScriptBlock()
.Your server side code then looks like this:
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.
I have used multiple parameters before by building and splitting a string.
eg
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 ';')
You could pass the two values as one JSON string:
And then parse it on the server:
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.