I have a RadWindow that is used to update values. When the button is clicked and the event is finished the whole page reloads. I would like to apply some Ajax to the RadWindow so that the whole page doesn't reload when the update is complete, just the RadWindow closes. Below is the code I have so far:
ASP.NET
C#
ASP.NET
<
telerik:RadAjaxLoadingPanel
ID
=
"LocationsLoadingPanel"
runat
=
"server"
Transparency
=
"30"
Skin
=
"Vista"
></
telerik:RadAjaxLoadingPanel
>
<
telerik:RadAjaxPanel
ID
=
"LocationsPanel"
runat
=
"server"
LoadingPanelID
=
"LocationsLoadingPanel"
>
<
telerik:RadTreeView
ID
=
"LocationsTreeView"
runat
=
"server"
EnableDragAndDrop
=
"true"
MultipleSelect
=
"true"
EnableDragAndDropBetweenNodes
=
"true"
AllowNodeEditing
=
"true"
OnContextMenuItemClick
=
"LocationsTreeView_ContextMenuItemClick"
OnClientContextMenuItemClicking
=
"onClientContextMenuItemClicking"
OnClientContextMenuShowing
=
"onClientContextMenuShowing"
OnNodeEdit
=
"LocationsTreeView_NodeEdit"
OnNodeDrop
=
"LocationsTreeView_NodeDrop"
OnClientNodeDropping
=
"onNodeDropping"
OnClientNodeDragging
=
"onNodeDragging"
>
<
ContextMenus
>
<
telerik:RadTreeViewContextMenu
ID
=
"MainContextMenu"
runat
=
"server"
>
<
Items
>
<
telerik:RadMenuItem
Value
=
"Rename"
Text
=
"Rename ..."
Enabled
=
"true"
ImageUrl
=
"images/icons/edit_48.png"
PostBack
=
"false"
>
</
telerik:RadMenuItem
>
<
telerik:RadMenuItem
IsSeparator
=
"true"
>
</
telerik:RadMenuItem
>
<
telerik:RadMenuItem
Value
=
"addLocation"
Text
=
"Add Location"
ImageUrl
=
"images/icons/add_16.png"
>
</
telerik:RadMenuItem
>
<
telerik:RadMenuItem
Value
=
"editDetails"
Text
=
"Edit Details"
PostBack
=
"true"
/>
</
Items
>
<
CollapseAnimation
Type
=
"none"
/>
</
telerik:RadTreeViewContextMenu
>
</
ContextMenus
>
</
telerik:RadTreeView
>
<
telerik:RadFormDecorator
ID
=
"RadFormDecorator1"
runat
=
"server"
Skin
=
"Vista"
DecoratedControls
=
"All"
/>
<
telerik:RadWindow
ID
=
"editDetails_RadWindow"
runat
=
"server"
Modal
=
"true"
Behaviors
=
"Close"
Width
=
"300px"
Height
=
"150px"
DestroyOnClose
=
"true"
VisibleStatusbar
=
"false"
>
<
ContentTemplate
>
<
table
>
<
tr
>
<
td
><
asp:Label
ID
=
"editDetailsIDlbl"
Text
=
"ID: "
runat
=
"server"
/></
td
>
<
td
><
telerik:RadTextBox
ID
=
"editDetailsIDtxt"
runat
=
"server"
Enabled
=
"false"
/>
<
asp:Label
ID
=
"InjectScript"
runat
=
"server"
/></
td
>
</
tr
>
<
tr
>
<
td
><
asp:Label
ID
=
"editDetailsCostCtrLbl"
Text
=
"Cost Center:"
runat
=
"server"
/></
td
>
<
td
><
telerik:RadTextBox
ID
=
"editDetailsCostCtrTxt"
runat
=
"server"
EmptyMessage
=
"Enter Cost Center"
/>
</
td
>
</
tr
>
<
tr
>
<
td
><
asp:Label
ID
=
"editDetailsAuxLocLbl"
Text
=
"Aux Location: "
runat
=
"server"
/></
td
>
<
td
><
telerik:RadTextBox
ID
=
"editDetailsAuxLocTxt"
runat
=
"server"
EmptyMessage
=
"Enter Aux Location"
/></
td
>
</
tr
>
<
tr
>
<
td
colspan
=
"2"
><
telerik:RadButton
ID
=
"editDetailsUpdateBtn"
runat
=
"server"
Text
=
"Update"
CommandArgument
=
"LocationID"
OnClick
=
"editDetailsUpdateBtn_Click"
/></
td
>
</
tr
>
</
table
>
</
ContentTemplate
>
</
telerik:RadWindow
>
<
telerik:RadWindowManager
ID
=
"locationRadWindow"
runat
=
"server"
/>
</
telerik:RadAjaxPanel
>
C#
protected
void
LocationsTreeView_ContextMenuItemClick(
object
sender, RadTreeViewContextMenuEventArgs e)
{
RadTreeNode clickedNode = e.Node;
switch
(e.MenuItem.Value)
{
case
"addLocation"
:
RadTreeNode newLocation =
new
RadTreeNode(
string
.Format(
"New Location"
));
newLocation.Selected =
true
;
newLocation.ImageUrl = clickedNode.ImageUrl;
clickedNode.Nodes.Add(newLocation);
clickedNode.Expanded =
true
;
//update the number in the brackets
if
(Regex.IsMatch(clickedNode.Text, unreadPattern))
clickedNode.Text = Regex.Replace(clickedNode.Text, unreadPattern,
"("
+ clickedNode.Nodes.Count.ToString() +
")"
);
clickedNode.Font.Bold =
true
;
//set node's value so we can find it in startNodeInEditMode
// Add Location Record to Database
string
ParentID = clickedNode.Value;
Guid ID = Guid.NewGuid();
string
LocationID = ID.ToString();
// Used for naming the node after adding it
newLocation.Value = LocationID;
startNodeInEditMode(newLocation.Value);
string
Name = newLocation.Text;
LocationsTreeView_AddLocation(ParentID, LocationID, Name);
break
;
case
"editDetails"
:
// Get the location of the item were editing
string
LocID = clickedNode.Value;
string
CostCtr =
""
;
string
AuxLoc =
""
;
// Get Cost Center and Aux Location if it exists
SqlCommand locationDetailsCmd =
new
SqlCommand(
"SELECT CostCenter, AuxLocationID FROM dbo.Locations WHERE ID='"
+ LocID +
"'"
, connection);
connection.Open();
SqlDataReader rdr = locationDetailsCmd.ExecuteReader();
while
(rdr.Read())
{
if
(!rdr.IsDBNull(0))
CostCtr = rdr.GetString(0).ToString();
if
(!rdr.IsDBNull(1))
AuxLoc = rdr.GetString(1).ToString();
}
connection.Close();
editDetails_RadWindow.VisibleOnPageLoad =
true
;
// Set the RadWindow TextBox Values
editDetailsCostCtrTxt.Text = CostCtr;
editDetailsAuxLocTxt.Text = AuxLoc;
editDetailsIDtxt.Text = LocID;
locationRadWindow.Windows.Add(editDetails_RadWindow);
break
;
}
}
protected
void
editDetailsUpdateBtn_Click(
object
sender, EventArgs e)
{
string
AuxLocation = editDetailsAuxLocTxt.Text;
string
CostCenter = editDetailsCostCtrTxt.Text;
string
LocationID = editDetailsIDtxt.Text;
SqlCommand editDetailsUpdateCmd =
new
SqlCommand(
"UPDATE dbo.locations SET CostCenter='"
+ CostCenter +
"', AuxLocationID='"
+ AuxLocation +
"' WHERE ID ='"
+ LocationID +
"'"
, connection);
connection.Open();
editDetailsUpdateCmd.ExecuteNonQuery();
connection.Close();
}