Telerik RadWindow Javascript return values to ASP.NET
asp.net, javascript, postback, return-value, telerik
Solution
You are doing the following
GetRadWindow().BrowserWindow.location.reload();
But that wont cause a postback it will simply reload the parent page, you need to cause a potback. You could try adding a button to the parent form with the style set 'display:none', and handling the click event in the code behind, you can fire this button off from your js code.
In Parent Page :
<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
}
You can invoke from your javascript like this (non jQuery), place this in your callback
document.getElementById('<%= btnClick.ClientID').click();
Problem
I have a parent page that launches a telerik radwindow and passes it an argument. Once the radwindow is done processeing the value, I need it to return it to the parent page, and I would like the parent page to have access to this value in my code behind page. I have tried to pass the value to a hidden field on my page and then trigger a page refresh and my code behind watches to see if the value is working. I can't seem to get this to work. I get the return value in the parent javascript, but i can't get it from my hidden field from the code behind. I even get it into the text box like i need to but, when i find the Hidden field in the codebehind, there is no value set. Where I have set alerts, I am getting the values displayed as i need to. I suspect that the reason I can't see my return value in the code behind file, is that when the page is refreshed, I am getting a new page and not only causing a post back. And is there not a better way i can do this. here is my code in the parent page: Parent 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> ``` Parent Code Behind: ``` protected void Page_Load(object sender, EventArgs e) { HtmlInputHidden hidden = (HtmlInputHidden)Page.FindControl("Hidden1"); if (IsPostBack && !string.IsNullOrEmpty(hidden.Value)) { //Code Here } } ``` Here is my Dialog code: 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> ``` Thanks for all the help Ian