We help IT Professionals succeed at work.

Opening a window using javascript

AnneSKS
AnneSKS asked
on
285 Views
Last Modified: 2015-06-21
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

Comment
Watch Question

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

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!
CERTIFIED EXPERT

Commented:
>>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.

Author

Commented:
Understand, it's rendered after the button is clicked.
Thanks.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.