Avatar of AnneSKS
AnneSKS
 asked on

Opening a window using javascript

Hi,
I have a radwindow that I want to open when I click on a button in a listview.
I also have parameters to send to the window using a querystring.
I am calling a javascript function to open the radwindow, from the code behind, where I send a parameter to construct the query string.

So far, I have everything working except that the rad window is only opening on the second click.

Thank you for your help

This is the page with the list view and the button to open the radwindow:
The button to open the radwindow is called: btnUpload, and call the btnUpload_OnCommand function to trigger the javascript function ShoweditForm:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="RadWindow.aspx.cs" Inherits="TESTING.RadWindow" %>

<%@ Register tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI"%>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

<telerik:RadCodeBlock ID="RadCodeBlock2" runat="server">
    <script type="text/javascript">
        function ShowEditForm(id) {
            window.radopen("FileUpload.aspx?ID=" + id, "UserListDialog");
            return false;
        }

        function refreshGrid() {
                $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");
        }
    </script>
</telerik:RadCodeBlock>

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
    <ajaxsettings>
        <telerik:ajaxsetting ajaxcontrolid="RadAjaxManager1"/>
    </ajaxsettings>
</telerik:RadAjaxManager>

<telerik:RadAjaxLoadingPanel runat="server" ID="gridLoadingPanel"/>

<telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true"  Height="500px" Width="520px" Title="Attach/Remove file(s)" VisibleStatusbar="false"  Modal="true" />

<telerik:RadListView ID="LV" runat="server"  DataKeyNames="ID" OnNeedDataSource="LV_NeedDataSource" >
    <ItemTemplate>
        <fieldset style="border: none;" >
            <table cellpadding="0" cellspacing="0"   >
                <tr>
                    <td>
                        <asp:Label ID="lblID" runat="Server" Text='<%# Eval("ID") %>' />
                        <asp:TextBox ID="txtMCDesc" runat="Server" Text='<%# Eval("MCDesc") %>' />
                        <telerik:RadButton ID="btnUpload"  Text="Attach/remove file(s)" runat="server" Skin="Metro" Width="130px"  AutoPostBack="true" OnClick="btnUpload_OnCommand"/>        

                    </td>
                </tr>
            </table>
        </fieldset>
    </ItemTemplate>                                               
</telerik:RadListView>
</asp:Content>

Open in new window


The C# code, that sends the parameter and call the javascript function is:
        protected void btnUpload_OnCommand(object sender, EventArgs e)
        {
            RadButton btnUpload = (RadButton)sender;
            RadListViewDataItem Item = (RadListViewDataItem)((RadButton)sender).NamingContainer;
            int ID = int.Parse(((Label)Item.FindControl("lblID")).Text.ToString());
            btnUpload.Attributes["href"] = "javascript:void(0);";
            btnUpload.Attributes["Onclick"] = String.Format("return ShowEditForm('{0}');", ID);
        }

Open in new window

JavaScriptASP.NETC#

Avatar of undefined
Last Comment
AnneSKS

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
AnneSKS

ASKER
Hi,
Thank you very much. It's working now.
Just one question to understand how it works, as I am very new to javascript.
The code is in the ItemDataBound because it is loading the response to the click event, so when the user click the button whatever has been set in the ItemDataBound is delivered.

when I was putting it in the Click event of the button I thought when the click event was fired the code was calling the javascript to open the form. When in fact it was sending the information, so the second time the button was clicked then the javascript was run,

I don't know if it makes sense...

Thanks again!
Ryan Chong

>>when I was putting it in the Click event of the button I thought when the click event was fired the code was calling the javascript to open the form. When in fact it was sending the information, so the second time the button was clicked then the javascript was run,

Do you mean for your original code? I guess it's because the javascript to open the window is only rendered after the btnUpload button is clicked and processed at server side, in which initially you put the btnUpload.Attributes["Onclick"] in  btnUpload_OnCommand event. Since then, the open window script ShowEditForm will only be ready after this button was clicked.

Hope this is clear.
AnneSKS

ASKER
Understand, it's rendered after the button is clicked.
Thanks.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23