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

javascript from behind the code

3 Answers 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dingen
Top achievements
Rank 1
dingen asked on 17 Mar 2010, 07:24 AM
Hi

I am trying to trigger the ShowDialog function from behind the code?

reg

D

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %> 
 
<%@ Register Assembly="RadWindow.Net2" Namespace="Telerik.WebControls" TagPrefix="radW" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
<head id="Head1" runat="server"
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="Form1" method="post" runat="server"
    <p> 
        <b>Returning multiple Values From a Dialog</b> 
        <br /> 
    </p> 
    <script type="text/javascript"
        //Show the window 
        function ShowDialog() { 
            var oWnd = window.radopen(null, "DialogWindow"); 
            oWnd.SetUrl(oWnd.GetUrl()); 
            return oWnd; 
        } 
         
        //Called when a window is being shown. Good for setting an argument to the window  
        function OnClientShow(radWindow) { 
            //Create a new Object to be used as an argument to the radWindow 
            var arg = new Object(); 
            //Using an Object as a argument is convenient as it allows setting many properties. 
            arg.NameValue = document.getElementById("NameArea").value; 
            arg.ProfessionValue = document.getElementById("ProfessionArea").value; 
 
            //Set the argument object to the radWindow       
            radWindow.Argument = arg
        } 
 
        function CallBackFunction(radWindow, returnValue) { 
            if (returnValue.NameValue) document.getElementById("NameArea").value = returnValue.NameValue; 
            if (returnValue.NameValue) document.getElementById("ProfessionArea").value = returnValue.ProfessionValue; 
        } 
 
        // Called when a window is being closed. 
        function OnClientClose(radWindow) { 
            //Another option for passing a callback value 
            //Set the radWindow.Argument property in the dialog 
            //And read it here --> var oValue = radWindow.Argument;                                      
            //Do cleanup if necessary 
        }    
                             
    </script> 
    <asp:Label ID="InjectScript" runat="server" Width="410px"></asp:Label> 
    <p> 
        Text to be modified from the dialog: 
        <br /> 
        Name: 
        <textarea id="NameArea" rows="1" cols="20">John Smith</textarea> 
        <br /> 
        Profession:<textarea id="ProfessionArea" rows="5" cols="20">VB Developer</textarea> 
        <asp:Button ID="Button1" runat="server" Text="Button" /> 
        <br /> 
        <button class="Button" style="width: 250px" onclick="ShowDialog();return false;" 
            type="button"
            Show dialog (force dialog refresh)</button> 
    </p> 
    <p> 
        (Open by client script) 
        <br /> 
        <radW:RadWindowManager ID="Singleton" runat="server" OnClientClose="OnClientClose" 
            OnClientShow="OnClientShow" ClientCallBackFunction="CallBackFunction" VisibleOnPageLoad="false"
            <Windows> 
                <radW:RadWindow ID="DialogWindow" OffsetElementId="NameArea" Left="250px" Modal="true" 
                    runat="server" Width="370px" Height="310px" Title="User List Dialog" NavigateUrl="./Dialog.aspx"
                </radW:RadWindow> 
            </Windows> 
        </radW:RadWindowManager> 
    </p> 
    <p> 
        &nbsp;</p> 
    <div style="width: 456px; height: 260px; text-align: justify"
        <p> 
            The example is based on <strong>t</strong>elerik's demo <href="http://www.telerik.com/r.a.d.controls/Window/Examples/DialogReturnValue/DefaultCS.aspx" 
                target='_blank"'>Returning Values From A Dialog </a>and <strong>t</strong>elerik's 
            KB article <href="http://www.telerik.com/Default.aspx?PageId=2514&amp;b454K=xg8&amp;b454T=o8c" 
                target="_blank">(ID#664) Providing an argument to a dialog. Return value from a 
                dialog, assign and invoke callback function</a>
        </p> 
        <p> 
            The approach is the same as explained in the KB article above and the only difference 
            is that instead of only one, we are passing two values to and from the dialog. If 
            you need more values to be passed - the logic stays the same. 
        </p> 
        <p> 
            For more information, please check the comments in the code. 
        </p> 
    </div> 
    </form> 
</body> 
</html> 
 

Imports Telerik.WebControls 
 
Partial Class Default2 
    Inherits System.Web.UI.Page 
 
     
    Protected Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button1.Click 
        InjectScript.Text = "<script type='text/javascript'>ShowDialog()</" + "script>" 
    End Sub 
End Class 
 

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 18 Mar 2010, 10:44 AM
Hello dingen,

I'd suggest that you use the ScriptManager's RegisterStartUpScript() method to trigger the function in question:

if (ScriptManager.GetCurrent(base.Page).IsInAsyncPostBack)
    ScriptManager.RegisterStartupScript(this, this.GetType(), "DialogueScript" + this.ClientID.ToString(), "ShowDialogue()", false);
else
    this.Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, "ShowDialogue()");

I hope it helps.

Best wishes,
Tsvetoslav
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
dingen
Top achievements
Rank 1
answered on 22 Mar 2010, 10:39 AM
hi

i placed it in the buttonclick event and it does not work? can you post a more complete code sample?

thanks

D
0
Tsvetoslav
Telerik team
answered on 23 Mar 2010, 02:31 PM
Hello dingen,

A little correction to the previous code-snippet, sorry for that:
if (ScriptManager.GetCurrent(base.Page).IsInAsyncPostBack)
ScriptManager.RegisterStartupScript(this, this.GetType(), "DialogueScript" + this.ClientID.ToString(), "ShowDialogue();", true);
else
this.Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, "ShowDialogue();",true);

Attached is also a small sample.

All the best,
Tsvetoslav
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.
Tags
Grid
Asked by
dingen
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
dingen
Top achievements
Rank 1
Share this question
or