Use javascript and doPostback value?

I have a page where, when the button is clicked, the javascript function is launched. Then it combines some data and puts the data in a hidden field on this page. Then a new window opens. This new window selects this aggregated data as follows: -

$('#accepted').val(window.opener.$('#accepted').val());

where the hidden field in the parent and child window is accepted (runat = "server" was not used). The problem is that I require this data to bind two tables. Currently I have done doPostback on both grids, but what I really want to do is do a Postback for the form once and handle the data binding to the PageLoad event. So, two questions: -

1) How to make a doPostback form?

2) How can I do this, although I can still distinguish from the actual presentation of the form?

+5
source share
2 answers

To publish a form, you just need to add the __doPostback call to your javascript after the accepted field is set. You can use the EventTarget and EventArgument options for __doPostback to control the binding in your grid.

So you can put this in your js:

__doPostback('rebindGrid', '');

and then this event on the page load page:

if (Request.Form["__EVENTTARGET"] == "rebindGrid")
{
    //....Do so stuff
}
+1
source

To associate it more directly with the postback model, I wrap my part with C #

C # Extension Method

public static string GetPostBackLink (this Control c, string argument = "") {
 return c.Page.ClientScript.GetPostBackEventReference(ctl, argument, true) + ";";
}

Aspx

<asp:LinkButton id="lnkDoThis" runat="server" onclick="lnkDoThis_Click" 
      style="display: none;"></asp:LinkButton>

<asp:HiddenField id="hdnParamHolder" runat="server" />

Js

function DoSomething(param) { 
 $("[id$='hdnDealTemp']").val(param);
 <%= lnkDoThis.GetPostBackLink() %> 
}

CodeBehind

protected void lnkDoThis_Click (object sender, EventArgs e) { 
 var myParam = hdnParamHolder.Value;
 // Do server actions here
}

... , , , ? hdnParamHolder .

0

All Articles