This is a migrated thread and some comments may be shown as answers.

Returning Values from a Dialog and doing something

4 Answers 278 Views
Window
This is a migrated thread and some comments may be shown as answers.
Jeremy
Top achievements
Rank 1
Jeremy asked on 17 May 2011, 08:12 PM
I want to use a window as a means of collecting data, validating when the user presses OK then if all is OK, return to the parent form and save to the database.

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

Sort by
0
Marin Bratanov
Telerik team
answered on 19 May 2011, 02:56 PM

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.

0
Jeremy
Top achievements
Rank 1
answered on 25 May 2011, 07:03 PM
Thanks, yes I can see how to run code behind on the RadWindow, what I meant was I want to run something at the server on the form that called the RadWindow to popup. So, if the user presses OK on the RadWindow then it will run the server code on the RadWindow first (which will add the entered information into the database), and then call something on the calling form (to reload the form for example).

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.
0
Jeremy
Top achievements
Rank 1
answered on 25 May 2011, 07:25 PM
I forgot to mention, on the main window I have an 'add' button, which I use by setting the OpenerElementID of the popup window to its ClientID, so this is what makes the RadWindow appear.
0
Marin Bratanov
Telerik team
answered on 26 May 2011, 12:36 PM

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.

Tags
Window
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Jeremy
Top achievements
Rank 1
Share this question
or