簡體   English   中英

Telerik RadWindow Javascript將值返回給ASP.NET

[英]Telerik RadWindow Javascript return values to ASP.NET

我有一個父頁面啟動telerik radwindow並傳遞一個參數。

一旦完成radwindow處理值,我需要它將它返回到父頁面,我希望父頁面可以在我的代碼頁面后面訪問該值。

我試圖將值傳遞給頁面上的隱藏字段,然后觸發頁面刷新和我的代碼隱藏在監視之后,看看值是否正常。

我似乎無法讓這個工作。 我在父javascript中獲得了返回值,但我無法從后面的代碼中隱藏字段中獲取它。

我甚至把它放到文本框中,就像我需要的那樣,當我在代碼隱藏中找到隱藏字段時,沒有設置值。

在我設置警報的地方,我正在顯示我需要的值。

我懷疑我無法在代碼隱藏文件中看到我的返回值的原因是,當頁面刷新時,我得到一個新頁面而不僅僅是導致回發。

並且我沒有更好的方法可以做到這一點。

這是我在父頁面中的代碼:

家長ASPX:

<script type="text/javascript">
    function OpenWnd() {
        var oWnd = radopen(null, "RadWindow1");
    }
    function OnClientShow(oWnd) {
        //Create a new Object to be used as an argument to the radWindow
        var arg = new Object();
        //Using an Object as a argument is convenient as it allows setting many properties.
        arg.text = document.getElementById("TextBox1").value;
        //Set the argument object to the radWindow  
        oWnd.Argument = arg;
    }

    function ClientCallBackFunction(radWindow, returnValue) {
        //check if a value is returned from the dialog
        if (returnValue.newtext) {
            document.getElementById("Hidden1").value = returnValue.newtext;
            alert("HiddenValue: " + document.getElementById("Hidden1").value);
        }
    }
</script>
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<div>
    <telerik:RadWindowManager ID="RadWindowManager2" runat="server">
        <Windows>
            <telerik:RadWindow ID="RadWindow1" runat="server" OnClientShow="OnClientShow" ClientCallBackFunction="ClientCallBackFunction"
                NavigateUrl="Dialog2.aspx" />
        </Windows>
    </telerik:RadWindowManager>
</div>
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox>
<input type="button" value="Send content to dialog page" onclick="OpenWnd()" />
<p>
    <input id="Hidden1" type="hidden" runat="server" />
</p>
</form>

家長代碼:

        protected void Page_Load(object sender, EventArgs e)
    {
        HtmlInputHidden hidden = (HtmlInputHidden)Page.FindControl("Hidden1");

        if (IsPostBack && !string.IsNullOrEmpty(hidden.Value))
        {
          //Code Here
        }
    }

這是我的Dialog代碼:

Dialog ASPX:

  <script type="text/javascript">
        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow) oWindow = window.radWindow;
            else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
            return oWindow;
        }
        function ConfigureDialog() {
            //Get a reference to the radWindow wrapper
            var oWindow = GetRadWindow();
            //Obtain the argument 
            var oArg = oWindow.Argument;
            //Use the argument
            var oArea = document.getElementById("TextBox1");
            oArea.value = oArg.text;
        }
        function SendAndClose() {
            var oWindow = GetRadWindow();
            //Get current content of text area
            var arg = new Object();
            arg.newtext = document.getElementById("TextBox1").value;
            oWindow.Close(arg);
            RefreshParentPage();
        }
        function RefreshParentPage() {
            GetRadWindow().BrowserWindow.location.reload();

            alert("RefreshParentPage");
        }
    </script>

謝謝你的幫助

伊恩

您正在執行以下操作

GetRadWindow().BrowserWindow.location.reload(); 

但是這不會導致回發它只會重新加載父頁面,你需要引起一個反叛。 您可以嘗試在樣式集'display:none'的父表單中添加一個按鈕,並在后面的代碼中處理click事件,您可以從js代碼中觸發此按鈕。

在父頁面中:

<asp:Button runat="server" id="btnClick" Style="display:none"    OnClick="btnClick_Click"/>

protected void btnClick_Click(object sender,EventArgs e)
{
     string val = this.Hidden1.Value; //Code goes here
}

你可以從你的javascript中調用這個(非jQuery),把它放在你的回調中

document.getElementById('<%= btnClick.ClientID').click();

在aspx方面,更好的方法是:

<%=this.ClientScript.GetPostBackEventReference(new System.Web.UI.PostBackOptions(btnClick))%>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM