Your "Returning Values from a Dialog " sample doesn't actually return to the code behind part, but updates the form using a java script.
I'm not very familiar with scripts and would prefer to do the work in the code behind part of the form.
How can I do this?
Thanks
Jeremy
4 Answers, 1 is accepted
Hi Jeremy,
There are several approaches you can take, yet they include having a server-side event fired after the user interaction:
1) You can attach a server-side event handler to the OK button you use in the RadWindow, then read the necessary values and execute your custom logic in the code-behind after the postback. This is recommended if you are loading an external page in the RadWindow via the NavigateUrl property, because in that case only the page inside the RadWindow will be postback. The downside here is that the user may choose to close the RadWindow via the close button and not press your OK button.
2) you can call a hidden button's click() method via JavaScript in the OnClientClose event of the RadWindow and have a server-side method attached to it again. This is useful if you are using the ContentTemplate property or you are performing some client-side validation. Here is a simple example how to achieve that:
The aspx:
<
input
type
=
"button"
id
=
"btnHidden"
style
=
"display:none"
runat
=
"server"
onserverclick
=
"serverside_handler"
/>
<
telerik:RadWindow
runat
=
"server"
ID
=
"RadWindow1"
VisibleOnPageLoad
=
"true"
OnClientClose
=
"callMethod"
></
telerik:RadWindow
>
<
asp:Label
ID
=
"Label1"
Text
=
""
runat
=
"server"
/>
The JavaScript:
function
callMethod()
{
document.getElementById(
"<%=btnHidden.ClientID %>"
).click();
}
Some simple code-behind method:
protected
void
serverside_handler(
object
sender, EventArgs e)
{
Label1.Text =
"from code-behind"
;
}
You can pass the values you have collected through the viewstate or a hidden field if you do not wish to directly access the controls on the server-side. How you do that depends on your custom scenario and needs.
All the best,
Marin
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

What I'm creating is a popup dialog, which, if you complete stuff and press OK then it saves to a database, and when it gets back to the calling form it adds to a grid, so after the RadWindow closes I just need to be able to refresh the grid on the main window to show the thing you just added when pressing OK on the RadWindow.

Hi Jeremy,
Please examine the following online demo, as it is very similar to your requirement: http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=window.
Here is another example on how to insert in a Grid via a window: http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/popupeditform/defaultcs.aspx.
If you use the RadWindow with its ContentTemplate then the controls in the RadWindow are a part of the main form and you can directly call functions in its code-behind.
If you are loading an external page in the RadWindow - then you would need to access the methods from that page's code-behind or use JavaScript to call a click of a hidden button from the main form (either by the method I described, or by using the method described in the following article: http://www.telerik.com/help/aspnet-ajax/window-programming-calling-functions.html). Please note that the method I described in my previous post will actually call a method from the main form's code-behind, not from the RadWindow's.
On a side note - we do not recommend using the OpenerElementID property, especially in cases where an INaming container is involved. It is designed for very simple scenarios only. I suggest that you attach a JavaScript handler to the desired button, get a reference to the RadWindow and call its show() method instead.
Kind regards,
Marin
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.