This is a migrated thread and some comments may be shown as answers.

Set button event in code behind to open window

2 Answers 11 Views
Window
This is a migrated thread and some comments may be shown as answers.
Simon Channell
Top achievements
Rank 1
Simon Channell asked on 06 Aug 2014, 12:38 PM
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
next
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>            oWnd.center();<br>        }<br>    </script>


2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 07 Aug 2014, 07:54 AM
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.

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

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

VB:
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

Thanks,
Princy.
0
Simon Channell
Top achievements
Rank 1
answered on 07 Aug 2014, 09:56 AM
I have changed the code as per your recommendations and the window now opens when I click the image.
Tags
Window
Asked by
Simon Channell
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Simon Channell
Top achievements
Rank 1
Share this question
or