Is it possible to return the value from my radwindow to the edit form of a radgrid (radtextbox)?
(line 27)
function ShowDialog() { | |
//window.radopen(null, "DialogWindow"); | |
//Forced reload (option 1): In order to force a reload on the dialog, the following approach should be used | |
//window.radopen("./SimpleDialog.aspx", "DialogWindow"); | |
//Forced reload (option 2): If one is not sure what the current url is, forced reload can be achieved like this: | |
var oWnd = window.radopen(null, "DialogWindow"); | |
oWnd.SetUrl(oWnd.GetUrl()); | |
} | |
/* Called when a window is being shown. Good for setting an argument to the window */ | |
function OnClientShow(radWindow) { | |
//Get current content of textarea | |
var oText = document.getElementById("<%=radtextbox1.ClientID %>").value; | |
//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.TextValue = oText; | |
//Set the argument object to the radWindow | |
radWindow.Argument = arg; | |
} | |
function CallBackFunction(radWindow, returnValue) { | |
var oArea = document.getElementById("<%=ChequeDetailsGrid.ClientID %>"); | |
if (returnValue) oArea.value = returnValue; | |
else alert("No text was returned"); | |
} | |
/* Called when a window is being closed. */ | |
function OnClientClose(radWindow) { | |
//Another option for passing a callback value | |
//Set the radWindow.Argument property in the dialog | |
//And read it here --> var oValue = radWindow.Argument; | |
//Do cleanup if necessary | |
} |
Thanxs in advance
Panos
27 Answers, 1 is accepted
I believe that this and this online demos will be of help.
Sincerely yours,
Fiko
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.
I was able to return the value in a textbox in my form. But what i want to do is to return the value in the Radgrid inside a radtextbox while i am inside the edit form template. So how should i change the geteelementbyId in order to save the returned value from by dialog.aspx page to a the radtextbox inside the edit form template?
function CallBackFunction(radWindow, returnValue) {
var oArea = document.getElementById("<%=textbox1.ClientID %>");
if (returnValue) oArea.value = returnValue;
else alert("No text was returned");
}
Regards
You can try handling the OnLoad client-side event of RadTextBox and get the instance of the RadTextBox object there. Then you could use it in the RadWindow callback function.
<script type="text/javascript"> |
var textBox = null; |
function Load(sender, eventArgs) |
{ |
textBox = sender; |
} |
</script> |
<telerik:RadGrid ID="RadGrid1" runat="server"> |
<MasterTableView> |
<Columns> |
<telerik:GridTemplateColumn UniqueName="TemplateColumn"> |
<EditItemTemplate> |
<telerik:RadTextBox ID="RadTextBox1" runat="server"> |
<ClientEvents OnLoad="Load" /> |
</telerik:RadTextBox> |
</EditItemTemplate> |
</telerik:GridTemplateColumn> |
</Columns> |
</MasterTableView> |
</telerik:RadGrid> |
Greetings,
Iana
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.
What should i include in the quotes?
var oText = document.getElementById(").value;
Thanxs
In the sample code I send you the textBox variable is indeed a reference to the RadTextBox client-side object. So if you add the mention code to this of yours, then try modifying the rest of it as below:
12 /* Called when a window is being shown. Good for setting an argument to the window */ |
13 function OnClientShow(radWindow) { |
14 //Get current content of textarea |
15 var oText = textBox; |
16 |
17 //Create a new Object to be used as an argument to the radWindow |
18 var arg = new Object(); |
19 //Using an Object as a argument is convenient as it allows setting many properties. |
20 arg.TextValue = oText; |
21 //Set the argument object to the radWindow |
22 radWindow.Argument = arg; |
23 } |
I hope this helps.
Best wishes,
Iana
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.
function CallBackFunction(radWindow, returnValue) { |
var oArea = textbox; |
if (returnValue) oArea.value = returnValue; |
else alert("No text was returned"); |
} |
The value from my dialog window produces the error : textbox is undefined.
I apologize for any misunderstandings.
It seems that you have missed the code in Iana's reply from yesterday. The idea is to use RadTextBox's OnLoad event to get a reference to the currently activated RadTextBox.
To avoid further misunderstanding, I created a small sample based on her reply and attached it to this thread - please check it and use it as a base in your implementation. Note that I am using the OnClientClose function for receiving the argument - ClientCallBack is deprecated.
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.
In my default page:
<script type="text/javascript"> | |
var textBox = null; | |
function Load(sender, eventArgs) { | |
textBox = sender; | |
} | |
function ShowDialog() { | |
//window.radopen(null, "DialogWindow"); | |
//Forced reload (option 1): In order to force a reload on the dialog, the following approach should be used | |
//window.radopen("./SimpleDialog.aspx", "DialogWindow"); | |
//Forced reload (option 2): If one is not sure what the current url is, forced reload can be achieved like this: | |
var oWnd = window.radopen(null, "DialogWindow"); | |
oWnd.SetUrl(oWnd.GetUrl()); | |
} | |
/* Called when a window is being shown. Good for setting an argument to the window */ | |
function OnClientShow(radWindow) { | |
//Get current content of textarea | |
var oText = document.getElementById("<%=radtextbox1.ClientID %>").value; | |
//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.TextValue = oText; | |
//Set the argument object to the radWindow | |
radWindow.Argument = arg; | |
} | |
/* Called when a window is being closed. */ | |
function OnClientClose(sender, args) { | |
var oNewText = args.get_argument(); | |
//set the needed value for the currently opened textbox | |
textBox.set_value(oNewText); | |
} | |
Inside my rad grid form template: | |
<telerik:radtextbox ID="regnumber" runat="server" | |
Text='<%# Bind("RegNumber") %>' Width="125px"> <ClientEvents OnLoad="Load" /> | |
</telerik:radTextBox> Rad window manager: <
Telerik:RadWindowManager id="Singleton" runat="server" Skin="Web20">
<windows>
<Telerik:RadWindow id="DialogWindow" Modal="true" Runat="server" Width="300px" Height="300px" Title="Dialog" OnClientShow="OnClientShow"
OnClientClose="OnClientClose"
NavigateUrl="yearSelection.aspx"></telerik:RadWindow>
<Telerik:RadWindow id="RadWindow1" Modal="true" Runat="server" Width="900" Height="400" Title="Dialog"
NavigateUrl="customers.aspx"></telerik:RadWindow>
</windows>
</Telerik:RadWindowManager>
|
Then a value that gets calculated in my dialog window i want it to be passed back in the radgrid in a different radtextbox that is located inside the radgrid edit form template i created.
In my dialog page:
<body onload="ConfigureDialog();"> | |
<form id="form1" method="post" runat="server"> | |
<div> | |
<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("store"); | |
oArea.value = oArg.TextValue; | |
oArea.style.color = oArg.Color; | |
oArea.style.backgroundColor = oArg.BackColor; | |
} | |
function OK_Clicked() { | |
var oWindow = GetRadWindow(); | |
//Get current content of text area | |
var oNewText = document.getElementById("<%=reqnumber.ClientID %>").value; | |
alert("Req Number to be returned to main page: " + oNewText); | |
//Variant2: Passing the argument to the Close method will result in the same behavior | |
oWindow.Close(oNewText); | |
//Variant3: Possible to set the Argument property of RadWindow here, and read it in the OnClientClose event handler! | |
//oWindow.Argument = oNewText; | |
} | |
function Cancel_Clicked() { | |
var oWindow = GetRadWindow(); | |
oWindow.Close(); | |
} | |
<button onclick="OK_Clicked(); return false;" class="bButton">OK</button> | |
<button onclick="Cancel_Clicked(); return false;" class="bButton">Cancel</button> | |
In the function ok_clicked (line 27) the message box gets succesfully displayed with the value i want to pass, closes the Radwindow but gives me the javascript error.
Please open a support ticket and send me your project or rework the project that I posted so it reproduces the problem and attach it to the ticket - I will check it and fix it for you.
Sincerely yours,
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.
I think that args.get_argument(); is not supported from my trial. I am using telerik 2008 Q3. DO you think that this may be the case? If yes what should i do?
If i update from this version to the current one would my existing controls work?
Thanxs for your patience :)
function callbackfunction(sender, args) { |
alert("Please enter some text in the textbox" + args); |
var oNewText = args; |
//set the needed value for the currently opened textbox |
textBox.set_value(oNewText); |
} |
I am using the callback function and the second argument as the returned text (args)
As i said before maybe its a version thing.
If this is the case let me present you with another problem i am facing.
I am following your example Window / Edit Dialog for RadGridi
I am opening my Radgrid in edit mode form template and i am placing a link next to a Radcombo that i want to edit that passes a key to the radwindow which is used as a select parameter for my formview. So after i edit the record and press ok
i am using this function to refresh the grid
function CloseAndRebind(args) { |
var oWindow = GetRadWindow(); |
oWindow.Close(); |
oWindow.BrowserWindow.refreshGrid(args); |
} |
The window closes but the value in the Radgrid do not get refreshed.
This is the code i am using in the default page.
Is there any way of refreshing only the Radcombobox with the new value.?
function refreshGrid(arg) { |
if (!arg) { |
$find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind"); |
} |
else { |
$find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindAndNavigate"); |
} |
} |
Private Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest |
If e.Argument = "Rebind" Then |
ChequeDetailsGrid.MasterTableView.Rebind() |
ElseIf e.Argument = "RebindAndNavigate" Then |
'ChequeDetailsGrid.MasterTableView.SortExpressions.Clear() |
'ChequeDetailsGrid.MasterTableView.GroupByExpressions.Clear() |
'ChequeDetailsGrid.MasterTableView.CurrentPageIndex = ChequeDetailsGrid.MasterTableView.PageCount - 1 |
ChequeDetailsGrid.MasterTableView.Rebind() |
End If |
End Sub |
Thanxs again for your wonderfull support.
Could you please clarify where is that RadComboBox which value you want to set? Is it inside the grid edit form or out of it?
If you could open send us a sample project or at least the page with the grid and this open in the RadWindow, could help for finding a resolution for you.
Sincerely yours,
Iana
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.
It is inside the radgrid edit form template.
Basically this is the scenario:
- User clicks on edit button on Radgrid. Edit template form opens. (done)
- In the customers Radcombo there is a link where the selected customer number is transfered to a radwindow as a parameter to fill a formview. (done)
- I edit the record in formview ex change name.(done)
- Press Update, the Radwindow closes abd goes back in the open edit form template but the selected customer name in radcombo stays the same. (not refreshing)
Thanxs , i ll try to send you a sample if you prefer though.
Please try the attached sample and let me know if it works for you.
Additionally, you can find more information on RadComboBox client-side API here.
Kind regards,
Iana
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.
hi thanxs for the responce,
I dont want to return a value to the radcombobox i want the values of the radcombobox to be refreshed when radwindow closes.
thanxs
Panos Pelekanos
In this case you need to chenge the datasource of the combo correspondingly and databind it. You can find more information on how to manipulate RadComboBox items in the below demos:
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/declarativedatasources/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/combobox/examples/populatingwithdata/autocompletesql/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/combobox/examples/programming/addremovedisable/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/combobox/examples/programming/addremovedisableitemsclientside/defaultcs.aspx
You could perform ajax request in the OnClientWindowClose event handler and handle the combo data refreshing in the AjaxRequest event. Find more information on that approach below:
http://www.telerik.com/help/aspnet-ajax/ajxaddajaxrequesttoclientevent.html
http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=grid
Best wishes,
Iana
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.
I have another problem now. I am following a demo on using url for server arguments.
I am passing my value through the selected value from an asp dropdown list succesfully though the edit form inside a radgrid.
The problem is when i select something else from the dropdown list and click the details link the radwindow appears but passes again the first value that was loaded in the dropdown list when the radgrid edit form was loaded. Same problem when i go to insert mode.
Javascript |
function OpenPositionedWindow(oButton, url, windowName) { |
var oWnd = window.radopen(url, windowName); |
} |
function openRadWindow(CustomerID) { |
var oWnd = radopen("customers.aspx?customernumber=" + CustomerID, "RadWindow1"); |
oWnd.center(); |
} |
dropDownList |
<asp:DropDownList ID="customerdrop" AppendDataBoundItems="True" runat="server" DataSourceID="customerDS" |
DataTextField="CustomerName" DataValueField="CustomerNumber" Height="25px" |
Width="276px" SelectedValue='<%# Bind("CustomerNumber") %>' |
AutoPostBack="True" onselectedindexchanged="customerdrop_SelectedIndexChanged"> |
<asp:ListItem Text="-Please Select Customer-" Value="" /> |
</asp:DropDownList> |
Details link to pass parameter |
<a href="#" onclick="openRadWindow('<%#DataBinder.Eval(Container.DataItem,"Customernumber")%>'); return false;"> |
Details</a> |
<Telerik:RadWindowManager id="Singleton" runat="server" Skin="Web20"> |
<windows> |
<Telerik:RadWindow id="DialogWindow" Modal="true" Runat="server" Width="300px" Height="300px" Title="Dialog" OnClientShow="OnClientShow" |
ClientCallBackFunction="OnClientClose" |
NavigateUrl="yearSelection.aspx"></telerik:RadWindow> |
<Telerik:RadWindow id="RadWindow1" Modal="true" Runat="server" Width="900" Height="400" Title="Dialog" |
NavigateUrl="customers.aspx"></telerik:RadWindow> |
<Telerik:RadWindow id="RadWindow2" Modal="true" Runat="server" Width="900" Height="500" Title="Dialog" |
NavigateUrl="customersall.aspx"></telerik:RadWindow> |
</windows> |
</Telerik:RadWindowManager> |
I think my problem is at the details link as it doesnt recognise that the value has been changed!
Thanxs :)
Indeed, the parameters in the details link onclick event are static. In order to achieve your goal, you need to change them dynamically. I suggest that in the DropDownList SelectedIndexChanged event you set the onclick attribute of the link so that the first parameter passed corresponds to the selected item.
Regards,
Iana
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.
I am quessing i should first access the dropdownlist inside the radgrid. How do i set the onclick attribute of the link based on the selected index?
Protected Sub customerdrop_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) |
Dim editedItem As GridEditableItem = CType(CType(sender, DropDownList).NamingContainer, GridEditableItem) |
Dim comboBox As DropDownList = DirectCast(sender, DropDownList) |
Dim dataItem As GridEditableItem = DirectCast(comboBox.NamingContainer, GridEditableItem) |
Dim combobox2 As DropDownList = DirectCast(dataItem.FindControl("customerdrop"), DropDownList) |
Thanxs Again
I can confirm your code for getting the DropDownList and the current edited item is proper. What is left is to set the runat property of the link control to server, assign it id and find it in the grid item with FindControl() method. If it is hard for you to work with this link on the server, replace it with a LinkButton.
Best wishes,
Iana
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.
Should i copy paste the code somewhere else? (
<a href="#" runat="server" id="detailscustomer"> |
Details</a> |
Protected Sub customerdrop_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) |
Dim editedItem As GridEditableItem = CType(CType(sender, DropDownList).NamingContainer, GridEditableItem) |
Dim comboBox As DropDownList = DirectCast(sender, DropDownList) |
Dim dataItem As GridEditableItem = DirectCast(comboBox.NamingContainer, GridEditableItem) |
' To access the InsertFormItem |
Dim combobox2 As DropDownList = DirectCast(dataItem.FindControl("customerdrop"), DropDownList) |
Dim editLink As HtmlAnchor = DirectCast(dataItem.FindControl("detailscustomer"), HtmlAnchor) |
editLink.Attributes.Add("onClick", "return openRadWindow(" & combobox2.SelectedValue & " );") |
End Sub |
Thanxs!
You can leave the link definition as it was:
<a href="#" onclick="openRadWindow('<%#DataBinder.Eval(Container.DataItem,"Customernumber")%>'); return false;"> |
Details</a> |
Thus it would have onclick handler initially with the default value, and then the onclick handler would change in the SelectedIndexChanged event correspondingly.
Regards,
Iana
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.
<a href="#" runat="server" id="detailscustomer" onclick="openRadWindow('<%#DataBinder.Eval(Container.DataItem,"Customernumber")%>');return false">Details</a> |
I think that the problem is on the double quotes that close beofre Customernumber. Is there any sollution to this problem? I tried putting escape characters but still didnt work.
Thanxs
Panos
You can swap the quotes like this:
<a href="#" runat="server" id="detailscustomer" onclick='openRadWindow(\"<%#DataBinder.Eval(Container.DataItem,"Customernumber")%>\");return false;'>Details</a> |
If it does not work this way, you can try setting the onclick attribute in the ItemDataBound event of RadGrid for the initial load of the link.
Best wishes,
Iana
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.
<a href="#" runat="server" id="detailscustomer" >Details</a> |
Protected Sub ChequeDetailsGrid_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles ChequeDetailsGrid.ItemDataBound |
If TypeOf e.Item Is GridEditFormInsertItem AndAlso e.Item.IsInEditMode Then |
Dim combobox2 As DropDownList = DirectCast(TryCast(e.Item, GridEditFormInsertItem).FindControl("customerdrop"), DropDownList) |
Dim editLink As HtmlAnchor = DirectCast(TryCast(e.Item, GridEditFormInsertItem).FindControl("detailscustomer"), HtmlAnchor) |
editLink.Attributes.Add("onClick", "return openRadWindow(" & combobox2.SelectedValue & " );") |
End If |
Can you spot my mistake? The link dowesnt open radwidnow in the initial load.
thanxs
I'd downloaded the sample code of Iana posted on June 10. I was able to post back and update the value in the RadNumericTextBox inside the RadGrid control. However, when I click the Save button on the Insert command, the Required Field validator of the RadNumericTextBox is always failed eventhough the value is set (via set_value method on client side). I need to make sure the value in the RadNumericTextBox is > 0. Could you please add a validation control to your sample code to see if you have the same issue as I have? Thanks!
Below is my client side code. I am using RadControls Q1 2009 version.
function ShowUpdateQuantityWin(quantityTxtBxId, nbrPersTextBxId, quantityList) { |
window.radopen("UpdateQuantity.aspx?quantityList=" + quantityList + "&quanId=" + quantityTxtBxId + "&persId=" + nbrPersTextBxId, "quantityRadWindow"); |
var quantityTxtBx = $find(quantityTxtBxId); |
//quantityTxtBx.set_value(1); |
quantityTxtBx._textBoxElement.readOnly = false; |
return false; |
} |
function OnQuantityWindowClose(oWnd) { |
//get the transferred arguments |
var arg = oWnd.argument; |
if (arg) { |
// alert("arg info: " + arg.quantity + "-" + arg.nbrOfPers + " " + arg.quanId + " " + arg.nbrPersId); |
$get('<%=nbrOfPersonsHF.ClientID %>').value = arg.nbrOfPers; |
$get(arg.nbrPersId).innerHTML = arg.nbrOfPers; |
$get('<%=quantityHF.ClientID %>').value = arg.quantity; |
$get('<%=quantityListHF.ClientID %>').value = arg.quantityList; |
var quantityRadTxtBx = $find(arg.quanId); |
quantityRadTxtBx.set_value(arg.quantity); |
//quantityRadTxtBx.value = arg.quantity; |
quantityRadTxtBx.set_textBoxValue(arg.quantity); |
quantityRadTxtBx._textBoxElement.readOnly = true; |
} |