Howdy all.
So, I have a RadMenu where the user clicks a button that opens a RadWindow. Then the user can click anywhere else but on the window itself and close said window. That works beautifully.
I now have a RadGrid with a GridTemplateColumn that has a LinkButton. LinkButton goes to the code behind, figures stuff out, and if all is good, redirects to another page in the project. If something is awry and it can't for some reason, it instead pops up a default RadAlert that says 'Something's wrong'. The RadAlert is Modal and appears over the RadWindow, not letting the user have any interaction on the page under it. THAT works.
Here's where I'm going cross-eyed: Once I hit Ok, I want the RadWindow with the grid to stay open, and the RadAlert to close. However, my code for 'Click Anywhere and close' is tripping, and I'm not sure how to let it know that the click on the RadAlert is ok.
This is also, adding shades of complexity, part on a master page, and part on the content page. I'll mark which bit is where.
Here's my code.
First, menu and window I want to stay up - this is on the Content page:
Now, the Menu specific Javascript, also on the Content page.
Now, the VB code behind of the Content page. First method is where the window is opened, and the second is where the RadAlert is generated.
Because this Javascript is used throughout the project on multiple pages, it's on the Master page.
And finally, the RadWindowManager on the Master. Not much too it, but it is there!
Any ideas? Thanks all!
So, I have a RadMenu where the user clicks a button that opens a RadWindow. Then the user can click anywhere else but on the window itself and close said window. That works beautifully.
I now have a RadGrid with a GridTemplateColumn that has a LinkButton. LinkButton goes to the code behind, figures stuff out, and if all is good, redirects to another page in the project. If something is awry and it can't for some reason, it instead pops up a default RadAlert that says 'Something's wrong'. The RadAlert is Modal and appears over the RadWindow, not letting the user have any interaction on the page under it. THAT works.
Here's where I'm going cross-eyed: Once I hit Ok, I want the RadWindow with the grid to stay open, and the RadAlert to close. However, my code for 'Click Anywhere and close' is tripping, and I'm not sure how to let it know that the click on the RadAlert is ok.
This is also, adding shades of complexity, part on a master page, and part on the content page. I'll mark which bit is where.
Here's my code.
First, menu and window I want to stay up - this is on the Content page:
<
telerik:RadMenu
id
=
"menuEmp"
ClientIDMode
=
"Static"
runat
=
"server"
flow
=
"Vertical"
OnClientItemClicked
=
"MenuOpenWindow"
Width
=
"100%"
BackColor
=
"#37495D"
>
<
Items
>
<
telerik:RadMenuItem
ImageUrl
=
"../Images/button1.png"
Value
=
"EmpProj"
/>
</
Items
>
</
telerik:RadMenu
>
<
telerik:RadWindow
id
=
"winEmpProj"
runat
=
"server"
Top
=
"0"
Left
=
"0"
Style
=
"z-index: 8000"
EnableEmbeddedSkins
=
"false"
OffsetElementID
=
"divEmpHeader"
ShowContentDuringLoad
=
"false"
VisibleStatusbar
=
"false"
VisibleTitlebar
=
"false"
AutoSize
=
"true"
>
<
ContentTemplate
>
<
div
id
=
"divProjListList"
runat
=
"server"
style
=
"width: 400px;"
>
<
div
>Projects</
div
>
<
div
style
=
"width: 400px"
>
<
telerik:RadGrid
ID
=
"grdEmp"
runat
=
"server"
AutoGenerateColumns
=
"False"
Skin
=
""
EnableLinqExpressions
=
"False"
CellSpacing
=
"0"
EnableViewState
=
"False"
>
<
ClientSettings
Selecting-AllowRowSelect
=
"false"
EnablePostBackOnRowClick
=
"true"
/>
<
MasterTableView
DataKeyNames
=
"KeyColumn"
ShowHeader
=
"true"
HeaderStyle-HorizontalAlign
=
"Center"
EnableViewState
=
"false"
>
<
Columns
>
<
telerik:GridTemplateColumn
UniqueName
=
"EmpNo"
HeaderText
=
"EmpNo"
ItemStyle-HorizontalAlign
=
"Left"
>
<
ItemTemplate
>
<
asp:LinkButton
ID
=
"btnEmpNo"
runat
=
"server"
OnClick
=
"LoadEmp"
><%# DataBinder.Eval(Container.DataItem, "EmpNo")%></
asp:LinkButton
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"Department"
/>
<
telerik:GridBoundColumn
DataField
=
"Project"
/>
<
telerik:GridBoundColumn
DataField
=
"Supervisor"
/>
</
telerik:GridBoundColumn
>
</
Columns
>
<
HeaderStyle
HorizontalAlign
=
"Center"
/>
</
MasterTableView
>
<
FilterMenu
EnableImageSprites
=
"False"
>
</
FilterMenu
>
</
telerik:RadGrid
>
</
div
>
</
div
>
</
ContentTemplate
>
</
telerik:RadWindow
>
Now, the Menu specific Javascript, also on the Content page.
<telerik:RadScriptBlock ID=
"RadScriptBlock1"
runat=
"server"
>
<script type=
"text/javascript"
>
function MenuOpenWindow(windowTitle) {
var oWindow;
var offsetElementBounds;
var menu = $find(
"<%=menu.ClientID%>"
);
var menuItem = menu.findItemByValue(windowTitle).get_element();
//Closes the last window opened
if (lastOpenedWindow) {
lastOpenedWindow.close();
lastOpenedWindow = null;
}
if (windowTitle ==
"EmpProj"
) {
if (lastWindowTitle !=
"EmpProj"
) {
oWindow = $find(
"<%=winEmpProj.ClientID%>"
);
oWindow.show();
if (oWindow.get_offsetElementID()) {
offsetElementBounds = $telerik.getBounds($get(oWindow.get_offsetElementID()));
var x = offsetElementBounds.x + (menuItem.offsetWidth / 3);
var y = menuItem.offsetTop + offsetElementBounds.y - (menuItem.offsetHeight / 3);
oWindow.moveTo(x, y);
}
lastOpenedWindow = oWindow;
lastWindowTitle =
"EmpProj"
;
return false;
} else {
lastWindowTitle = null;
}
}
}
</script>
</telerik:RadScriptBlock>
Now, the VB code behind of the Content page. First method is where the window is opened, and the second is where the RadAlert is generated.
Private
Sub
menuEmp_ItemClick(sender
As
Object
, e
As
Telerik.Web.UI.RadMenuEventArgs)
Handles
menuEmp.ItemClick
Select
Case
e.Item.Value
Case
"Endorsed"
grdEndorsed.DataSource =
Nothing
grdEndorsed.Rebind()
End
Select
Dim
scriptstring
As
String
=
"function f(){{MenuOpenWindow('"
& e.Item.Value &
"');;Sys.Application.remove_load(f);}};Sys.Application.add_load(f);"
ScriptManager.RegisterStartupScript(
Me
,
Me
.[
GetType
](),
"showWindow"
, scriptstring,
True
)
End
Sub
Private
Function
LoadEmp()
'Stuff done
If
{stuff true}
Then
'Do stuff
Else
Dim
winManger
As
RadWindowManager = Master.FindControl(
"RadWindowManager1"
)
winManger.RadAlert(
"Something's Wrong"
, 50, 100,
"Project"
,
"message"
)
Exit
Sub
End
If
End
Function
Because this Javascript is used throughout the project on multiple pages, it's on the Master page.
<telerik:RadScriptBlock ID=
"RadScriptBlock1"
runat=
"server"
>
<script type=
"text/javascript"
>
//Global Variables
var
lastOpenedWindow;
var
lastWindowTitle;
var
alertWindowUp;
function
message(args) {
//This is here to give RadWindow serverside a place to go.
if
(lastWindowTitle ==
"EmpProj"
&& args ==
true
) {
alertWindowUp =
true
;
}
}
function
pageLoad() {
$addHandler(document,
"click"
, onClickHandler);
}
function
onClickHandler(e) {
var
targedNodeName = e.target;
if
(lastOpenedWindow) {
// If the RadWindow is clicked then do nothing ;
if
($telerik.isMouseOverElementEx(lastOpenedWindow.get_popupElement(), e))
return
;
lastOpenedWindow.close();
lastOpenedWindow =
null
;
lastWindowTitle =
null
;
if
(alertWindowUp ==
true
) {
lastWindowTitle =
null
;
MenuOpenWindow(
"EmpProj"
);
alertWindowUp =
false
;
}
}
}
</script>
</telerik:RadScriptBlock>
And finally, the RadWindowManager on the Master. Not much too it, but it is there!
<
telerik:RadWindowManager
ID
=
"RadWindowManager1"
runat
=
"server"
Style
=
"z-index: 8000"
/>
Any ideas? Thanks all!