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

AnneSKSAsked:
Who is Participating?
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 ChongCommented:
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:

Asp.net 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);
        }
     
    }

}

Ref:
http://docs.telerik.com/devtools/aspnet-ajax/controls/listview/server-side-programming/overview
http://www.telerik.com/forums/radlistview-itemdatabound-firing-every-other-item

Hope this works
0

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:
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!
0
Ryan ChongCommented:
>>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.
0
AnneSKSAuthor Commented:
Understand, it's rendered after the button is clicked.
Thanks.
0
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
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.