Hello all,
I am using rad window as follows,
i.e., from the code base in a grid row command event.
Telerik.Web.UI.RadWindow objEditOffer = new Telerik.Web.UI.RadWindow();
objEditOffer.VisibleOnPageLoad = true;
objEditOffer.NavigateUrl = "~/OfferManagement/CreateEditOffer.aspx?OfferId=" + _commandArg;
double heightEditOffer = 400;
double widthEditOffer = 900;
objEditOffer.Height = new Unit(heightEditOffer);
objEditOffer.Width = new Unit(widthEditOffer);
pnlrad.Controls.Add(objEditOffer);
I want to close that window and I want to refresh the parent page.I did used the following script,
function CloseOnReload() {
//alert("Dialog is about to close itself");
GetRadWindow().close();
RefreshParentPage();
}
function RefreshParentPage() {
//alert("Dialog is about to reload parent page");
GetRadWindow().BrowserWindow.location.reload();
}
function GetRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function Close() {
var oWindow = GetRadWindow();
oWindow.argument = null;
oWindow.close();
window.location = location.href;
return false;
}
The script did worked for me but with a problem that is, it is refreshing the page and reopening the rad window again. Please give me a solution ASAP.
I am using rad window as follows,
i.e., from the code base in a grid row command event.
Telerik.Web.UI.RadWindow objEditOffer = new Telerik.Web.UI.RadWindow();
objEditOffer.VisibleOnPageLoad = true;
objEditOffer.NavigateUrl = "~/OfferManagement/CreateEditOffer.aspx?OfferId=" + _commandArg;
double heightEditOffer = 400;
double widthEditOffer = 900;
objEditOffer.Height = new Unit(heightEditOffer);
objEditOffer.Width = new Unit(widthEditOffer);
pnlrad.Controls.Add(objEditOffer);
I want to close that window and I want to refresh the parent page.I did used the following script,
function CloseOnReload() {
//alert("Dialog is about to close itself");
GetRadWindow().close();
RefreshParentPage();
}
function RefreshParentPage() {
//alert("Dialog is about to reload parent page");
GetRadWindow().BrowserWindow.location.reload();
}
function GetRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function Close() {
var oWindow = GetRadWindow();
oWindow.argument = null;
oWindow.close();
window.location = location.href;
return false;
}
The script did worked for me but with a problem that is, it is refreshing the page and reopening the rad window again. Please give me a solution ASAP.
7 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 21 Jun 2012, 06:16 AM
Hi Rama,
After inspecting your code I can find that you are setting VisibleOnPageLoad property of RadWindow to true, which causes the RadWindow to appear in each postback. One suggestion is you can open the RadWindow from clientside. Please check this demo for more information.
Thanks,
Princy.
After inspecting your code I can find that you are setting VisibleOnPageLoad property of RadWindow to true, which causes the RadWindow to appear in each postback. One suggestion is you can open the RadWindow from clientside. Please check this demo for more information.
Thanks,
Princy.
0
Rama
Top achievements
Rank 1
answered on 21 Jun 2012, 10:48 AM
Hello Princy,
That was too good example. But for me the script
is not working. I have tried the same. I already registered telerik assembly. Please help to get out.
That was too good example. But for me the script
window.radopen("EditFormCS.aspx?EmployeeID=" + id, "UserListDialog");
is not working. I have tried the same. I already registered telerik assembly. Please help to get out.
0
Princy
Top achievements
Rank 2
answered on 22 Jun 2012, 04:01 AM
Hi Rama,
Unfortunately I couldn't replicate your problem. Following is the sample code that I tried and is working as expected at my end.
Grid.aspx
ASPX:
JS:
C#:
EditWindow.aspx
ASPX:
JS:
C#:
Hope this helps.
Thanks,
Princy.
Unfortunately I couldn't replicate your problem. Following is the sample code that I tried and is working as expected at my end.
Grid.aspx
ASPX:
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
OnAjaxRequest
=
"RadAjaxManager1_AjaxRequest"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadAjaxManager1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGrid1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowPaging
=
"true"
DataSourceID
=
"SqlDataSource1"
onitemcreated
=
"RadGrid1_ItemCreated"
>
<
PagerStyle
Mode
=
"NumericPages"
/>
<
MasterTableView
AutoGenerateColumns
=
"false"
DataKeyNames
=
"EmployeeID"
ClientDataKeyNames
=
"EmployeeID"
Width
=
"100%"
CommandItemDisplay
=
"Top"
PageSize
=
"5"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"EmployeeID"
HeaderText
=
"EmployeeID"
ReadOnly
=
"True"
SortExpression
=
"EmployeeID"
UniqueName
=
"EmployeeID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"FirstName"
HeaderText
=
"FirstName"
SortExpression
=
"FirstName"
UniqueName
=
"FirstName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"LastName"
HeaderText
=
"LastName"
SortExpression
=
"LastName"
UniqueName
=
"LastName"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Title"
HeaderText
=
"Title"
SortExpression
=
"Title"
UniqueName
=
"Title"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"TemplateEditColumn"
>
<
ItemTemplate
>
<
asp:HyperLink
ID
=
"EditLink"
runat
=
"server"
Text
=
"Edit"
></
asp:HyperLink
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
<
CommandItemTemplate
>
<
a
href
=
"#"
onclick
=
"return ShowInsertForm();"
>Add New Record</
a
>
</
CommandItemTemplate
>
</
MasterTableView
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"true"
/>
<
ClientEvents
OnRowDblClick
=
"RowDblClick"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
<
telerik:RadWindowManager
ID
=
"RadWindowManager1"
runat
=
"server"
EnableShadow
=
"true"
>
<
Windows
>
<
telerik:RadWindow
ID
=
"UserListDialog"
runat
=
"server"
Title
=
"Editing record"
Height
=
"320px"
Width
=
"310px"
Left
=
"150px"
ReloadOnShow
=
"true"
ShowContentDuringLoad
=
"false"
Modal
=
"true"
/>
</
Windows
>
</
telerik:RadWindowManager
>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT * FROM [Employees]"></
asp:SqlDataSource
>
JS:
<script type=
"text/javascript"
>
function
ShowEditForm(id, rowIndex) {
var
grid = $find(
"<%= RadGrid1.ClientID %>"
);
var
rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();
grid.get_masterTableView().selectItem(rowControl,
true
);
window.radopen(
"EditWindow.aspx?EmployeeID="
+ id,
"UserListDialog"
);
return
false
;
}
function
ShowInsertForm() {
window.radopen(
"EditWindow.aspx"
,
"UserListDialog"
);
return
false
;
}
function
refreshGrid(arg) {
debugger;
if
(!arg) {
$find(
"<%= RadAjaxManager1.ClientID %>"
).ajaxRequest(
"Rebind"
);
}
else
{
$find(
"<%= RadAjaxManager1.ClientID %>"
).ajaxRequest(
"RebindAndNavigate"
);
}
}
function
RowDblClick(sender, eventArgs) {
window.radopen(
"EditWindow.aspx?EmployeeID="
+ eventArgs.getDataKeyValue(
"EmployeeID"
),
"UserListDialog"
);
}
</script>
C#:
protected
void
RadAjaxManager1_AjaxRequest(
object
sender, Telerik.Web.UI.AjaxRequestEventArgs e)
{
if
(e.Argument ==
"Rebind"
)
{
RadGrid1.MasterTableView.SortExpressions.Clear();
RadGrid1.MasterTableView.GroupByExpressions.Clear();
RadGrid1.Rebind();
}
else
if
(e.Argument ==
"RebindAndNavigate"
)
{
RadGrid1.MasterTableView.SortExpressions.Clear();
RadGrid1.MasterTableView.GroupByExpressions.Clear();
RadGrid1.MasterTableView.CurrentPageIndex = RadGrid1.MasterTableView.PageCount - 1;
RadGrid1.Rebind();
}
}
protected
void
RadGrid1_ItemCreated(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
HyperLink editLink = (HyperLink)e.Item.FindControl(
"EditLink"
);
editLink.Attributes[
"href"
] =
"#"
;
editLink.Attributes[
"onclick"
] = String.Format(
"return ShowEditForm('{0}','{1}');"
, e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][
"EmployeeID"
], e.Item.ItemIndex);
}
}
EditWindow.aspx
ASPX:
<
asp:DetailsView
ID
=
"DetailsView1"
DataKeyNames
=
"EmployeeID"
runat
=
"server"
AutoGenerateRows
=
"False"
DataSourceID
=
"SqlDataSource1"
Height
=
"50px"
Width
=
"125px"
OnItemCommand
=
"DetailsView1_ItemCommand"
BorderWidth
=
"0"
CellPadding
=
"0"
CellSpacing
=
"7"
GridLines
=
"None"
OnItemUpdating
=
"DetailsView1_ItemUpdating"
>
<
Fields
>
<
asp:BoundField
DataField
=
"EmployeeID"
HeaderText
=
"EmployeeID"
SortExpression
=
"EmployeeID"
/>
<
asp:BoundField
DataField
=
"FirstName"
HeaderText
=
"FirstName"
SortExpression
=
"FirstName"
/>
<
asp:BoundField
DataField
=
"LastName"
HeaderText
=
"LastName"
SortExpression
=
"LastName"
/>
<
asp:BoundField
DataField
=
"Title"
HeaderText
=
"Title"
SortExpression
=
"Title"
/>
<
asp:CommandField
ShowEditButton
=
"True"
ButtonType
=
"Button"
/>
<
asp:CommandField
ShowInsertButton
=
"True"
ButtonType
=
"Button"
/>
</
Fields
>
</
asp:DetailsView
>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
InsertCommand="INSERT INTO [Employees] ([EmployeeID], [LastName], [FirstName], [Title]) VALUES (@EmployeeID, @LastName, @FirstName, @Title)"
SelectCommand="SELECT [EmployeeID], [FirstName], [LastName], [Title] FROM [Employees] WHERE ([EmployeeID] = @EmployeeID)"
UpdateCommand="UPDATE [Employees] SET [LastName] = @LastName, [FirstName] = @FirstName, [Title] = @Title WHERE [EmployeeID] = @EmployeeID">
<
InsertParameters
>
<
asp:Parameter
Name
=
"EmployeeID"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"LastName"
Type
=
"String"
DefaultValue
=
""
ConvertEmptyStringToNull
=
"false"
/>
<
asp:Parameter
Name
=
"FirstName"
Type
=
"String"
DefaultValue
=
""
ConvertEmptyStringToNull
=
"false"
/>
<
asp:Parameter
Name
=
"Title"
Type
=
"String"
/>
</
InsertParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"LastName"
Type
=
"String"
DefaultValue
=
""
ConvertEmptyStringToNull
=
"false"
/>
<
asp:Parameter
Name
=
"FirstName"
Type
=
"String"
DefaultValue
=
""
ConvertEmptyStringToNull
=
"false"
/>
<
asp:Parameter
Name
=
"Title"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"EmployeeID"
Type
=
"Int32"
/>
</
UpdateParameters
>
<
SelectParameters
>
<
asp:QueryStringParameter
Name
=
"EmployeeID"
QueryStringField
=
"EmployeeID"
Type
=
"Int32"
/>
</
SelectParameters
>
</
asp:SqlDataSource
>
JS:
<script type=
"text/javascript"
>
function
CloseAndRebind(args) {
GetRadWindow().BrowserWindow.refreshGrid(args);
GetRadWindow().close();
}
function
GetRadWindow() {
var
oWindow =
null
;
if
(window.radWindow) oWindow = window.radWindow;
//Will work in Moz in all cases, including clasic dialog
else
if
(window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
//IE (and Moz as well)
return
oWindow;
}
function
CancelEdit() {
GetRadWindow().close();
}
function
CloseWindow()
{
GetRadWindow().close();
}
</script>
C#:
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(Request.QueryString[
"employeeid"
] ==
null
)
{
DetailsView1.DefaultMode = DetailsViewMode.Insert;
}
else
{
DetailsView1.DefaultMode = DetailsViewMode.Edit;
}
this
.Page.Title =
"Editing record"
;
}
protected
void
DetailsView1_ItemCommand(
object
sender, DetailsViewCommandEventArgs e)
{
if
(e.CommandName ==
"Update"
)
{
string
script =
"<script language='javascript'>function f(){CloseAndRebind(); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>"
;
Page.ClientScript.RegisterStartupScript(
this
.GetType(),
"Pass"
, script);
}
else
if
(e.CommandName ==
"Insert"
)
{
string
script =
"<script language='javascript'>function f(){CloseAndRebind(); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>"
;
Page.ClientScript.RegisterStartupScript(
this
.GetType(),
"Pass"
, script);
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(),
"mykey"
,
"CancelEdit();"
,
true
);
}
}
protected
void
DetailsView1_ItemUpdating(
object
sender, DetailsViewUpdateEventArgs e)
{
for
(
int
i = 1; i < 4; i++)
{
string
val = e.NewValues[i - 1].ToString();
int
maxLength = i * 10;
if
(val.Length > maxLength) e.NewValues[i - 1] = val.Substring(0, maxLength);
}
}
Hope this helps.
Thanks,
Princy.
0
Rama
Top achievements
Rank 1
answered on 22 Jun 2012, 12:01 PM
Hello Princy,
your code and the script is absolutely fine. But,what is that "
Thanks
Rama.M
your code and the script is absolutely fine. But,what is that "
window.radopen(
"EditWindow.aspx?EmployeeID="
+ id,
"UserListDialog"
);
" . Do I include that script also? I am using asp.net grid view not the rad grid . Can you help me get out ? I am bit confused with that radopen function in the script.Thanks
Rama.M
0
Princy
Top achievements
Rank 2
answered on 25 Jun 2012, 07:47 AM
Hi Rama,
One suggestion is you can access the linkbutton in gridview and open the radwindow using the following code.
C#:
JS:
In order to open the window using radopen, make sure that you have RadWindowManager on the page.
Hope this helps.
Thanks,
Princy.
One suggestion is you can access the linkbutton in gridview and open the radwindow using the following code.
C#:
protected
void
GridView1_RowDataBound(
object
sender, GridViewRowEventArgs e)
{
if
(e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton link = (LinkButton)e.Row.FindControl(
"LinkButton1"
);
link.Attributes.Add(
"onclick"
,
"ShowEditForm();return false;"
);
}
}
function
ShowEditForm(id) {
window.radopen(
"Editform.aspx?EmployeeID="
+id ,
"UserListDialog"
);
return
false
;
}
In order to open the window using radopen, make sure that you have RadWindowManager on the page.
Hope this helps.
Thanks,
Princy.
0
Rama
Top achievements
Rank 1
answered on 26 Jun 2012, 10:32 AM
Hello Princy,
Thanks for your answer .
and
ScriptManager.RegisterStartupScript(this, this.GetType(), "CloseWindow","CloseAndRebind", true);
this is my radwindow:
<telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true" >
<Windows>
<telerik:RadWindow ID="UserListDialog" runat="server" Left="150px" ReloadOnShow="false" ShowContentDuringLoad="false" Modal="true" VisibleOnPageLoad="false" ></telerik:RadWindow>
</Windows>
</telerik:RadWindowManager>
I tried these two,but no use. Can you give any other suggestions to refresh the page . If I use _postback('','') to refresh ,the page loading radwindow which is not flexible way . Please help me.
Thanks and Regards
Rama.M
Thanks for your answer .
I am able to open the rad window now,but unable to refresh the page. I am unable to call this Java script from behind. I tried even script manager.
Page.ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind('navigateToInserted');",
and
ScriptManager.RegisterStartupScript(this, this.GetType(), "CloseWindow","CloseAndRebind", true);
this is my radwindow:
<telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true" >
<Windows>
<telerik:RadWindow ID="UserListDialog" runat="server" Left="150px" ReloadOnShow="false" ShowContentDuringLoad="false" Modal="true" VisibleOnPageLoad="false" ></telerik:RadWindow>
</Windows>
</telerik:RadWindowManager>
I tried these two,but no use. Can you give any other suggestions to refresh the page . If I use _postback('','') to refresh ,the page loading radwindow which is not flexible way . Please help me.
Thanks and Regards
Rama.M
0
Rama
Top achievements
Rank 1
answered on 28 Jun 2012, 07:05 AM
Hello Princy,
I am waiting for your response . Can you please update me something on my post.
Thanks and Regards
Rama.M
I am waiting for your response . Can you please update me something on my post.
Thanks and Regards
Rama.M