本文介绍了从C#用JavaScript doPostBack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有这将打开一个弹出窗口,并在用户在孩子的一些变化弹出页面一个父页面,然后点击保存按钮。
当用户点击保存按钮,我想doPostBack父页面,以便在弹出窗口中所做的更改在父窗口可以看到。

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 doPostBack to the parent page so that the changes made in the pop up window can be seen in parent window.

问题的:我怎样才能achive上面的场景

Question : How can I achive the above scenario?

我想写在aspx.cs文件中的脚本code,我试过

I want to write the script code in aspx.cs file, I tried

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

但什么也没做,只是没有错误罢了。

but this did not do anything, no errors just nothing.

我是新来的JavaScript,需要的所有步骤提供帮助。

I am new to JavaScript, need help with all steps.

推荐答案

父页面:

<asp:UpdatePanel runat="server">
    <ContentTemplate>
        <div>
            <asp:Literal runat="server" ID="ChildWindowResult" />
        </div>
        <hr />
        <input type="button" value="Open Dialog" onclick="window.open('MyDialog.aspx', 'Dialog');" />
        <asp:Button ID="HiddenButtonForChildPostback"  runat="server"
            OnClick="OnChildPostbackOccured" style="display: none;" />
        <asp:HiddenField runat="server" ID="PopupWindowResult"/>
    </ContentTemplate>
</asp:UpdatePanel>

该MyDialog页:

The MyDialog page:

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
    function postData() {
        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:TextBox runat="server" ID="SomeValueHiddenField" />
<asp:Button runat="server" OnClick="PostData" Text="Click Me" />

protected void PostData(object sender, EventArgs e)
{
   SomeValueHiddenField.Value = DateTime.Now.ToString();
   ClientScript.RegisterStartupScript(this.GetType(), "PostData", "postData();", true);
}

但我相信,这将是更好的在这里利用一些像PopUpExtender弹出控制从从jQuery-UI的AjaxControlToolkit库或对话框。

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.

这篇关于从C#用JavaScript doPostBack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 17:03