Skip to content Skip to sidebar Skip to footer

Dopostback From C# With Javascript

hi I have one parent page which opens a pop up window, and user makes some changes on child pop up page then clicks a save button. When the user clicks the save button, I want to d

Solution 1:

The parent page:

<asp:UpdatePanelrunat="server"><ContentTemplate><div><asp:Literalrunat="server"ID="ChildWindowResult" /></div><hr /><inputtype="button"value="Open Dialog"onclick="window.open('MyDialog.aspx', 'Dialog');" /><asp:ButtonID="HiddenButtonForChildPostback"runat="server"OnClick="OnChildPostbackOccured"style="display: none;" /><asp:HiddenFieldrunat="server"ID="PopupWindowResult"/></ContentTemplate></asp:UpdatePanel>

The MyDialog page:

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>
<scripttype="text/javascript">functionpostData() {
        var resultField = $("input[type='hidden'][id$='PopupWindowResult']", window.opener.document);
        var parentPosDataButton = $("[id$='HiddenButtonForChildPostback']", window.opener.document);

        resultField.val($("#<%= SomeValueHiddenField.ClientID  %>").val());
        parentPosDataButton.click();
    }
</script><asp:TextBoxrunat="server"ID="SomeValueHiddenField" /><asp:Buttonrunat="server"OnClick="PostData"Text="Click Me" />protectedvoidPostData(object sender, EventArgs e)
{
   SomeValueHiddenField.Value = DateTime.Now.ToString();
   ClientScript.RegisterStartupScript(this.GetType(), "PostData", "postData();", true);
}

But I believe that it would be much better to utilize here some pop-up controls like PopUpExtender from the AjaxControlToolkit library or dialog from the jQuery-UI.

Solution 2:

You probably need to use ClientID:

string script = "";
script = "<script>window.opener.__doPostBack('" + UpdatePanel1.ClientID + "', '')</script>";
ScriptManager.RegisterClientScriptBlock(Literal1, typeof(Literal), "yenile", script, true);

Solution 3:

The last parameter is to whether include script tag or not

So, if you do

RegisterClientScriptBlock(page,type, "<script>foo();</script>", true);

You will end up with:

"<script><script>foo();</script></script>"

So, change your last parameter to false, or better yet, remove the tags in the string

Solution 4:

Post a Comment for "Dopostback From C# With Javascript"