ASP.NET:JavaScriptを使用してWindow.Openerでサーバーサイドイベントをプログラムで発射する

StackOverflow https://stackoverflow.com/questions/5043866

質問

onSelectedIndexChangedイベントでサーバーサイドデータバインドを解除するドロップダウンリストを持っています。

<asp:DropDownList ID="ddlGroup" runat="server" 
     AutoPostBack="True" OnSelectedIndexChanged="SelectGroup" />
.

ページ内の他の場所では、いくつかのJavaScriptがポップアップを開きます。ポップアップが記入されて送信されると、JavaScriptを使用してOpenerページでOnSelectedIndexChangedイベントを発生させたいです。私は似たような何かをする他のコードを見つけました:

    if (window.opener != null ) {
    var cf = window.opener.document.forms['aspnetForm'];
        if (!cf) {
            cf =  window.opener.document.aspnetForm;
        }
        cf.__EVENTTARGET.value = "prAdded";
        cf.__EVENTARGUMENT.value = "winClosed";
        cf.submit(); 
    }
.

私は私が探しているものであると思いますが、EventTargetとEventArgumentの部品で何が起こるべきかわからない、あるいはまったくそれらを必要としていてもわかりません。OnSelectedIndexChangedddlGroupイベントハンドラを特別に発射したいです。これは可能/実用的ですか?

セカンダリ質問:ポップアップでサーバーサイドコードを実行した後に親ページを更新できますか?

役に立ちましたか?

解決

Eh, you could do it that way, but I'd just use __doPostback() instead. That sets __EVENTTARGET and __EVENTARGUMENT to the two parameters, and assuming your first parameter is the UniqueID of an UpdatePanel, causes just that UpdatePanel to refresh.

So either you can set things up so refreshing the updatepanel does what you want to happen, or you can check those values on postback -- Request.Form["__EVENTTARGET"] ... and go from there.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top