Set button event in code behind to open window

3 posts, 0 answers
  1. Simon Channell
    Simon Channell avatar
    25 posts
    Member since:
    Mar 2004

    Posted 06 Aug 2014 Link to this post

    I need to define a button in code to open a window
    This is the code I'm using
    Dim img As ImageButton

    For x = 0 To weekcolour.GetUpperBound(0)

    columnname = "ColumnITask" + (x + 1).ToString
    imagename = "btnEx" + (x + 1).ToString
    ​ If Not (img Is Nothing) Then
    img.ImageUrl = "/private/images/" + weekcolour(x) + "_light_ilp.png"
                 If weekcolour(x).Contains("green") Then
                        img.OnClientClick = "openRadWindow('<%# DataBinder.Eval(Container.DataItem,'" + student_id + "') %>'); return false; > """
                 End If
    End If
    The code updates the image url correctly but does not add the onClientCick event
    It still does not work if I remove the "if" statement
    This is my open window script
    <script type="text/javascript"><br><br>        function openRadWindow(StudentID) {<br>            var oWnd = radopen("task_update.aspx?StudentID=" + StudentID, "RadWindow1");<br>  ;<br>        }<br>    </script>

  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Aug 2014 in reply to Simon Channell Link to this post

    Hi Simon Channell,

    The provided information is not enough to find out the issue. Please have a look into the sample code snippet which works fine at my end. Please provide your full code for further help.

    <telerik:RadListBox ID="RadListBox1" runat="server" DataTextField="OrderID" DataSourceID="sqldsOrders"
            <asp:Label ID="Label1" runat="server" Text='<%# Eval("OrderID") %>'>
            <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/plus.gif" />
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server">

    function openRadWindow(StudentID) {
        var oWnd = radopen("Default.aspx?StudentID=" + StudentID, "RadWindow1");;

    Protected Sub RadListBox1_ItemDataBound(sender As Object, e As Telerik.Web.UI.RadListBoxItemEventArgs)
        Dim imgButton As ImageButton = TryCast(e.Item.FindControl("ImageButton1"), ImageButton)
        Dim lblText As Label = TryCast(e.Item.FindControl("Label1"), Label)
        imgButton .OnClientClick = "openRadWindow('" + lblText .Text + "'); return false;"
    End Sub

  3. Simon Channell
    Simon Channell avatar
    25 posts
    Member since:
    Mar 2004

    Posted 07 Aug 2014 in reply to Princy Link to this post

    I have changed the code as per your recommendations and the window now opens when I click the image.
Back to Top