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

[Solved] Returning a string revisitied

5 Answers 139 Views
Window
This is a migrated thread and some comments may be shown as answers.
Paul Taylor
Top achievements
Rank 1
Paul Taylor asked on 27 Apr 2009, 03:44 PM
I've been searching the forum and demos for the last 2 hours now and nothing i have found has worked.

Here's my scenario

I have a radwindow popping up where the user searches for a company by name and the results are populated to a radGrid. the user then selects the correct company and the Company database ID is retrieved using the following code.
protected void rGridComps_SelectedIndexChanged(object sender, EventArgs e)  
    {  
        foreach (GridDataItem item in rGridComps.MasterTableView.Items)  
        {  
            if (item.Selected)  
            {  
                compID = int.Parse(item["ID"].Text.ToString());  
                Label1.Text = "<script>closeWin()</" + "script>";  
            }  
        }  
    } 
What I want to do is return the value now stored in compID to the parent page along with the contents of a text box which holds the company name. I am trying this using the following.
function closeWin()  
{  
     var oWnd = GetRadWindow();  
     alert(compID);   
     oWnd.close(compID, rtbCompName.Text);  
The window will not close when i add the values to the close function, without these values it works just fine

The closest I have come to a solution is the following demo

http://demos.telerik.com/aspnet-ajax/window/examples/clientsideevents/defaultcs.aspx?product=window

but unfortunately it doesn't show the code for the dialog popup window, which I find very strange

I have the following code server side
function OnClientClose(sender, eventArgs)  
{  
    if (eventArgs.get_argument() != null)  
    {  
        alert("'" + sender.get_name() + "'" + " was closed and returned the following argument: '" + eventArgs.get_argument() + "'");  
     }  
     else  
     {  
         alert("'" + sender.get_name() + "'" + " was closed and returned no arguments'");  
     }  

5 Answers, 1 is accepted

Sort by
0
Paul Taylor
Top achievements
Rank 1
answered on 28 Apr 2009, 08:20 AM
Anyone?
0
Shinu
Top achievements
Rank 2
answered on 28 Apr 2009, 10:30 AM
Hi Paul Taylor,

I tried following approach for achieving this. I used one array for passing the values to parent RadWindow. Give a try with following code and see whether it is working fine on your end.

Dialog Page:
CS:
 
protected void rGridComps_SelectedIndexChanged(object sender, EventArgs e)   
{   
    foreach (GridDataItem item in rGridComps.MasterTableView.Items)   
    {   
        if (item.Selected)   
        {   
             compID = int.Parse(item["ID"].Text.ToString());   
             Label1.Text = "<script>closeWin("+compID+")</" + "script>";   
        }   
    }   
}  

JavaScript:
 
<script type="text/javascript"
function closeWin(compID) 
    var compName = document.getElementById('TextBox1').value; // Get the value from TextBox1 
    var myArray = new Array(); 
    myArray[0]=compID; 
    myArray[1]=compName; 
    GetRadWindow().close(myArray); //Pass parameter as an array 
</script> 

And in the parent page:
JavaScript:
 
<script type="text/javascript"
function OnClientClose(sender, eventArgs) 
{      
     if (eventArgs.get_argument() != null)   
     {   
        alert("Returned "+ eventArgs.get_argument().length + " arguments"); 
        alert("'" + sender.get_name() + "'" + " was closed and returned the following argument: '" + eventArgs.get_argument() + "'");   
     } 
     else 
     { 
         alert("'" + sender.get_name() + "'" + " was closed and returned no arguments'");   
     } 
</script> 

Note: You can also find out the code for Dialog page in the demo by clicking the dropdown arrow beside "DefaultCS.aspx".
http://demos.telerik.com/aspnet-ajax/window/examples/clientsideevents/defaultcs.aspx?product=window

Thanks,
Shinu.
0
Paul Taylor
Top achievements
Rank 1
answered on 28 Apr 2009, 11:15 AM
Hi Shinu, thxs for the reply but I still have problems.

The compID value is returning fine but it's failing on getting the value from the text box, it's a RadTextBox btw.
var compName = document.getElementById('rTBCoName').value; // Get the value from TextBox1   


I could however simply return 2 strings from the initial location but I can't seem to get it work

Popup
function closeWin(compID, compName) {   
            var myArray = new Array();  
            myArray[0] = compID;  
            myArray[1] = compName;  
            GetRadWindow().close(myArray); //Pass parameter as an array    
        } 

CS
protected void rGridComps_SelectedIndexChanged(object sender, EventArgs e)  
    {  
        foreach (GridDataItem item in rGridComps.MasterTableView.Items)  
        {  
            if (item.Selected)  
            {  
                Label1.Text = "<script>closeWin(" + item["ID"].Text.ToString() + ", " + item["CompanyName"].Text.ToString() = 2)</" + "script>";  
            }  
        }  
    } 


Also while I have your attention, could you tell me how to trigger a C# function after receiving the arguments so that I can populate a different radtextbox from within the java function
0
Georgi Tunev
Telerik team
answered on 28 Apr 2009, 11:18 AM
Hello guys,

Using a label for outputting JavaScript is not recommended when you are in an ASP.NET AJAX environment (indeed, we've had several such examples but they all were using RadControls for ASP.NET).

Paul, I believe that the following KB article will be of help. Please check the scenarios described there and the source code and use it as a base in your implementation.
RadWindow that postbacks and manipulates opener page on its reload

As for the demo that you have checked, you could see the codebehind of the content page by clicking on the splitbutton as shown in the attached screenshot. Note however that in this particular demo, nothing is done in the codebehind - the demo shows the usage of  RadWindow's client-side API.



All the best,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Paul Taylor
Top achievements
Rank 1
answered on 28 Apr 2009, 11:49 AM
It didn't solve my problem in the way I was expecting it to but i did manage to get a working system by using session variables and reloading the page.
Tags
Window
Asked by
Paul Taylor
Top achievements
Rank 1
Answers by
Paul Taylor
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Georgi Tunev
Telerik team
Share this question
or