This is a migrated thread and some comments may be shown as answers.

Need help with window popup

11 Answers 249 Views
Window
This is a migrated thread and some comments may be shown as answers.
Paul Taylor
Top achievements
Rank 1
Paul Taylor asked on 13 May 2009, 02:02 PM
Hi guys, need a bit of help, here's the scenario

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>"
but it throws a runtime error stating that the oWnd window handle is null. I then tried the following in place of the code in the first section
function ShowEditUserPopup() {  
    var oWnd = radopen('editUser.aspx', "EditUserPopup");  
but it threw an error stating that RadWindowManager was null. RadWindowmanager is present as is shown in the first section of code.

Any help would be appreciated.

11 Answers, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 13 May 2009, 02:13 PM

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(thisthis.GetType(), "radwnd""Sys.Application.add_load(ShowAddUserPopup);"true);     
 
 



Sincerely yours,

Svetlina
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.
0
Paul Taylor
Top achievements
Rank 1
answered on 13 May 2009, 02:40 PM
Thnxs a million, works a treat, exactly what I needed
:-)
0
Paul Taylor
Top achievements
Rank 1
answered on 13 May 2009, 03:27 PM
I guess I spoke too soon.

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.?
0
Paul Taylor
Top achievements
Rank 1
answered on 14 May 2009, 12:19 PM
How do I remove the function from the app_load after it has been used. It pops up again if I use the reigster startup script for anything else afterwards
0
Georgi Tunev
Telerik team
answered on 14 May 2009, 01:26 PM
Hello Paul,

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.
0
Paul Taylor
Top achievements
Rank 1
answered on 15 May 2009, 02:25 PM
Not working I'm afraid.

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);  
thx in advance
0
Paul Taylor
Top achievements
Rank 1
answered on 15 May 2009, 02:44 PM
Ok, I figured it out, I had it in an update panel which was causing the multiple popups.

I am new to asp.net so I appologise for what may an obvious thing to you guys.

Thx for the input though.
0
Paul Taylor
Top achievements
Rank 1
answered on 20 May 2009, 03:54 PM
The following script doesn't work
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.
0
Fiko
Telerik team
answered on 21 May 2009, 04:55 AM
Hello Paul,

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); 
The second step avoids multiple calling the showPermissionDeniedAlert function.

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.
0
Denis
Top achievements
Rank 1
answered on 25 Jun 2009, 08:19 PM
Hello

Im having the same problem, but i havent understand your solution Fiko ... do you have any other example?

thanks



0
Denis
Top achievements
Rank 1
answered on 25 Jun 2009, 08:30 PM
Hello

I've understood the solution ... i just have placed this code before the funciont that fires so many times the Modal Alert:

 
ScriptManager.RegisterStartupScript(thisthis.GetType(), "showAlert""Sys.Application.remove_load(showAlert);"true);  

Tags
Window
Asked by
Paul Taylor
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Paul Taylor
Top achievements
Rank 1
Georgi Tunev
Telerik team
Fiko
Telerik team
Denis
Top achievements
Rank 1
Share this question
or