Opening a window using javascript

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");

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

<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" >
        <fieldset style="border: none;" >
            <table cellpadding="0" cellspacing="0"   >
                        <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"/>        


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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
I never using telerik controls before but I just want to provide you an idea how to do this... (I made similar scripts for gridview few years ago..)

You need to add the attribute info in RadListView's ItemDataBound event instead: Code:
<telerik:RadListView ID="LV" runat="server"  DataKeyNames="ID" OnNeedDataSource="LV_NeedDataSource" OnItemDataBound="LV_ItemDataBound" >

Code behind:
protected void LV_ItemDataBound(object sender, ListViewItemEventArgs e)
    ListViewDataItem dataItem = (ListViewDataItem)e.Item;

    if (e.Item.ItemType == ListViewItemType.DataItem)
        RadButton btnUpload = (RadButton)e.Item.FindControl("btnUpload");    
        Label lblID = (Label)e.Item.FindControl("lblID");
        if ((btnUpload != null) && (lblID != null)) {
                btnUpload.Attributes["href"] = "javascript:void(0);";
                btnUpload.Attributes["Onclick"] = String.Format("return ShowEditForm('{0}');", lblID.Text);



Hope this works

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AnneSKSAuthor Commented:
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 ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
>>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.
AnneSKSAuthor Commented:
Understand, it's rendered after the button is clicked.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.