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

How to open radwindow from codebehind

5 Answers 266 Views
Window
This is a migrated thread and some comments may be shown as answers.
eric
Top achievements
Rank 1
eric asked on 05 Apr 2010, 11:49 PM
I am struggling to figure out how to open a radwindow from my vb codebehind... I was able to get my window to open correctly by setting up an onclientclick event for a hyperlink but this is not what I want to do.  I want to handle the serverside onclick event for a link button so that I can do some server side validation and then if the validation passes I will open the popup.  Currently the code below is generating a jscript error "Object doesn't support this property or method".  The weird thing is that this exact same javascript executed successfully when it was called from a hyperlink onclientclick event and that is why I am confused?  Any thoughts?

    Protected Sub lbSchedApt_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles lbSchedApt.Click 
 
        Dim jScript As String = [String].Format("openNewWindow('{0}', '{1}');", schedQID, ddlEvaluators.SelectedValue) 
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "ClientScript", jScript, True
 
    End Sub 


        function openNewWindow(schedQueueID, evaluatorID) { 
            window.radopen("ScheduleAppointment.aspx?ScheduleQueueID=" + schedQueueID + "&EvaluatorID=" + evaluatorID, "SchedAppt"); 
            return false
        } 


<asp:linkbutton ID="lbSchedApt" runat="server">Make Appointment</asp:linkbutton> 




This is the  oldcode that executed succesfully... essentially calling the same jscript function from a hyperlink client onclick as opposed to a serverside linkbutton click...

            hlSchedApt.Attributes("href") = "#" 
 
            hlSchedApt.Attributes("onclick") = [String].Format("return openNewWindow('{0}', '{1}');", datarow.Row.ItemArray(8).ToString(), ddlEvaluators.SelectedValue) 
 

5 Answers, 1 is accepted

Sort by
0
VIRUX
Top achievements
Rank 1
answered on 06 Apr 2010, 07:06 AM
Hi,

Am not expert, just to help..

This link explain well,

for your code and error is I think  because of the script manager and, "Sys.add load / remove load " should work .
'Trigger this code from server
function f()   
{   
    //Your code  

    Sys.Application.remove_load(f);   
}   
Sys.Application.add_load(f);  
 
Should fire this script from server
Sys.Application.add_load( 
    openNewWindow('xx''xx'); 
    Sys.Application.remove_load(openNewWindow('xx''xx'); 
    ); 


It's my working script just for reference.. , but I found injecting to (style display none) label is easier and faster than other way :D
'Client Handlers 
    Private Sub RunRADAlert(ByVal message2Show As StringByVal width As StringByVal height As String
 
        Dim radalertscript As String = String.Format("<script language='javascript'>function f(){{radalert('{0}',{1},{2});Sys.Application.remove_load(f);}}; Sys.Application.add_load(f);</script>", message2Show, width, height)
        Dim radalertSimpleScript As String = String.Format("radalert('{0}',{1},{2}); ", message2Show, width, height) 
 
        Dim reqAjaxMgr As RadAjaxManager = RadAjaxManager.GetCurrent(Page) 
        Dim reqRadScriptMgr As RadScriptManager = RadScriptManager.GetCurrent(Page) 
        Dim reqAspScriptMgr As Web.UI.ScriptManager = ScriptManager.GetCurrent(Page) 
 
        'Ajax   Manager Response 
        If reqAjaxMgr IsNot Nothing And reqAjaxMgr.IsAjaxRequest Then 
            reqAjaxMgr.ResponseScripts.Add(radalertSimpleScript) 
 
            'RadScript Manager Response 
        ElseIf reqRadScriptMgr IsNot Nothing And reqRadScriptMgr.IsInAsyncPostBack Then 
            RadScriptManager.RegisterClientScriptBlock(Me.Page, Me.[GetType](), "radalert", radalertscript, False
 
            'AspScript Manager Response 
        ElseIf reqAspScriptMgr IsNot Nothing And reqAspScriptMgr.IsInAsyncPostBack Then 
            ScriptManager.RegisterClientScriptBlock(Me.Page, Me.[GetType](), "radalert", radalertscript, False
 
            'Page   script startup  register 
        Else 
            Page.ClientScript.RegisterStartupScript(Me.[GetType](), "radalert", radalertscript) 
        End If 
 
    End Sub 
0
Georgi Tunev
Telerik team
answered on 06 Apr 2010, 08:26 AM
Hi Eric,

The reason for the error is that the code is executed too early - before the RadWindowManager is fully rendered on the page. More information on the subject and solutions is available in the following blog post:

http://blogs.telerik.com/supportdept/posts/09-05-05/executing_javascript_function_from_server-side_code.aspx

By the way, you could also open the RadWindow directly from the server by setting its VisibleOnPageLoad property to true.


All the best,
Georgi Tunev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Rohan
Top achievements
Rank 1
answered on 07 Sep 2012, 10:45 AM
Hi all ,

 

I have following scenario  One radwindow for upload the file – after the user select the file to upload ,user click to upload button – after the  user click to upload button I want to close the file upload radwindow  and open the new radwindow with different information, I not able to open the second radwindow  from code behind .

please provide any document for any example or any tip
thanks in advance....
0
Marin Bratanov
Telerik team
answered on 07 Sep 2012, 12:19 PM
Hello Rohan,

I would suggest that you prepare a JavaScript function in the RadWindow's content page (where I assume the upload and the button reside). This function will get a reference to the current RadWindow, open the next as described in this help article and then call the close() method of the current one. How to call the JavaScript function from the server (the Click handler of the button) is explained in this help article.

For your convenience I am attaching here a small sample that illustrates the approach. Note that I do not need to use the Sys.Application.Load event in this case because I will not be using any script controls in the JavaScript function.


Kind regards,
Marin Bratanov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Rohan
Top achievements
Rank 1
answered on 07 Sep 2012, 12:55 PM
Thank you very much Marin Bratanov ........ problem solved
Tags
Window
Asked by
eric
Top achievements
Rank 1
Answers by
VIRUX
Top achievements
Rank 1
Georgi Tunev
Telerik team
Rohan
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or