I'm popping up a RadWindow on the click of a button, which I have working fine in 2 different ways:-
Method 1, aspx page
function ShowAddUserPopup() { |
var oWnd = $find("<%=AddUserPopup.ClientID%>"); |
oWnd.setUrl('addUser.aspx'); |
oWnd.show(); |
} <
telerik:RadWindowManager ID="RadWindowManager1" runat="server">
<Windows>
<telerik:RadWindow ID="AddUserPopup" runat="server" Behavior="Close" Modal="True" Width="700px" Height="650px" VisibleStatusbar="False" OnClientClose="OnClientClose">
</telerik:RadWindow>
</Windows>
</telerik:RadWindowManager>
<
button onclick="ShowAddUserPopup();return false;" type="button">Add User</button>
|
Method 2, CS page
AddUserPopup.OpenerElementID = btnAddUser.ClientID; |
AddUserPopup.NavigateUrl = "addUser.aspx"; |
Both work fine but what I need to do is, when a user clicks the button, check the users' permission stored in the database first and if they have the relevant permission for accessing the section then it will pop up the radWindow
So it would need to be in an if else statement.
I tried the following in the if else
lblMessage.Text = "<script>ShowAddUserPopup()</script>"; |
function ShowEditUserPopup() { |
var oWnd = radopen('editUser.aspx', "EditUserPopup"); |
} |
Any help would be appreciated.
11 Answers, 1 is accepted
Hi Paul,
The controls in the RadControls for ASP.NET AJAX suite are built upon the MS AJAX framework and the framework itself creates its controls (including RadWindowManager) in the Sys.Application.add_init() method.
Here is how the client events are fired in the page life cycle:
window.onload -> Sys.Application.init -> Sys.Application.load
You can see that the client object representation of MS AJAX controls are created just as the last code on the page in the Sys.Application.init event, which is raised after the window.onload event.
That is why when you call your code in window.onload by registering the client script, the RadWindowManager will still not be created on the page and you will get an error. To avoid this problem, you can either execute your code with a small timeout, or use the Sys.Application.add_load method.
I also suggets to use the ScriptManager to execute teh script because the label approach is not very good and does not work in some AJAX scenarios. This being said, modify your code in the following manner:
ScriptManager.RegisterStartupScript(this, this.GetType(), "radwnd", "Sys.Application.add_load(ShowAddUserPopup);", true); |
Sincerely yours,
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.
:-)
Do I need to remove it after it has been used as the window is now popping up each time the page refreshes?
Also I'm getting a popup from Internet Explorer saying that it must resubmit the information, Would i like to continue etc.etc.?
You could use the following approach:
function f() |
{ |
//code |
Sys.Application.remove_load(f); |
} |
Sys.Application.add_load(f); |
I hope this helps. You could find more information about calling client functions from server in this blog post: Executing JavaScript function from server-side code
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.
It still pops up multiple times.
here's the scenario. I have a button for deleting a contact entry from the database. Firts it checks to see if this person has permission to do so and if they haven't it pops up an alert window using the following code from earlier
ScriptManager.RegisterStartupScript(this, this.GetType(), "radwnd", "Sys.Application.add_load(showPermissionDeniedAlert);", true); |
The problem is, if the user clicks the button again the popup shows twice in succession. If they continue top click the number of times it pops up is incremented each time so with a stubborn user it could end up popping 100 times with a single click.
I've tried the following to remove it the instant that it has been used but it doesn't change anything
ScriptManager.RegisterStartupScript(this, this.GetType(), "radwnd", "Sys.Application.add_load(showPermissionDeniedAlert);", true); |
ScriptManager.RegisterStartupScript(this, this.GetType(), "radwnd", "Sys.Application.remove_load(showPermissionDeniedAlert);", true); |
I am new to asp.net so I appologise for what may an obvious thing to you guys.
Thx for the input though.
ScriptManager.RegisterStartupScript(this, this.GetType(), "radwnd", "Sys.Application.remove_load(showPermissionDeniedAlert);", true); |
I'm still having issues with this. Here's the sceanrio:
I have multiple buttons that popup several different RadWindow popus. using the above add_load script works and the window pops up but each button click causea a page reload which not only removes any dynamic information that I have added but looks absolutely awful and toatally unprofessional.
To stop the reload i can use either an upadte panel or an ajax manager, this has the desired result but it leaves the injected script in place and i end up with multiple popups on a single button click.
In your scenario I recommend you to use the following approach :
- in the button_click event register the JavaSript by using the ScriptManager.RegisterStartupScript() function. For example :
ScriptManager.RegisterStartupScript(this, this.GetType(), "radwnd", "Sys.Application.add_load(showPermissionDeniedAlert);", true);
- then you need to detach the showPermissionDeniedAlert() function as follows :
function showPermissionDeniedAlert() { // ..... Sys.Application.remove_load(showPermissionDeniedAlert); }
I hope this helps.
Greetings,
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.
Im having the same problem, but i havent understand your solution Fiko ... do you have any other example?
thanks
I've understood the solution ... i just have placed this code before the funciont that fires so many times the Modal Alert:
ScriptManager.RegisterStartupScript(this, this.GetType(), "showAlert", "Sys.Application.remove_load(showAlert);", true); |