Hi,
I had a radgrid in a pageview within a multipageview with some javascript to allow a windowt o open when a row in the grid is clicked. This worked fine until I changed the Multipageview so that the pageviews would load on demand (on tabclick) which I implemented by creating a user control for each pageview and moving the existing radgrid into this control.
Now when the pageview is loaded I get a javascript error on the page "Error: 'RowSelected' is undefined" and when I view the source the RowSelected function does not seem to exist. I have tried adding the javascript programatically using RegisterClientScriptBlock whithin the .ascx.cs file in the Page_Load method but this does not seem to help and I'm not sure about how to deal with the radcodeblock tags. I don't have alot of experience with javascript or user controls so it's bound to be something simple I'm missing.
Any help would be much appreciated, I can supply more code if required.
User Control:
When trying to add the javascript programatically:
I had a radgrid in a pageview within a multipageview with some javascript to allow a windowt o open when a row in the grid is clicked. This worked fine until I changed the Multipageview so that the pageviews would load on demand (on tabclick) which I implemented by creating a user control for each pageview and moving the existing radgrid into this control.
Now when the pageview is loaded I get a javascript error on the page "Error: 'RowSelected' is undefined" and when I view the source the RowSelected function does not seem to exist. I have tried adding the javascript programatically using RegisterClientScriptBlock whithin the .ascx.cs file in the Page_Load method but this does not seem to help and I'm not sure about how to deal with the radcodeblock tags. I don't have alot of experience with javascript or user controls so it's bound to be something simple I'm missing.
Any help would be much appreciated, I can supply more code if required.
User Control:
| <%@ Control Language="C#" AutoEventWireup="true" CodeFile="PhoneDir.ascx.cs" Inherits="PhoneDir" %> |
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <telerik:RadCodeBlock ID="rcb1" runat="server"> |
| <script type="javascript"> |
| function RowSelected(sender, args) |
| { |
| var firstDataItem = $find("<%=rgPhoneDir.ClientID %>").get_masterTableView().get_dataItems()[0]; |
| var uname = args.getDataKeyValue("username") ; |
| window.radopen("userinfo.aspx?id=" + uname,"RadWindow1"); |
| } |
| </script> |
| </telerik:RadCodeBlock> |
| <telerik:RadGrid ID="rgPhoneDir" runat="server" AllowSorting="True" GridLines="None" |
| Height="100%" Skin="Office2007" DataSourceID="SqlDataSource1" |
| onitemcommand="rgPhoneDir_ItemCommand"> |
| <MasterTableView CellSpacing="-1" ClientDataKeyNames="username" AutoGenerateColumns="False" |
| DataKeyNames="username" DataSourceID="SqlDataSource1"> |
| <Columns> |
| <telerik:GridBoundColumn DataField="username" HeaderText="username" ReadOnly="True" |
| SortExpression="username" UniqueName="username" Visible="False"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Internal Phone" HeaderText="Internal Phone" SortExpression="Internal Phone" |
| UniqueName="Internal Phone"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Surname" HeaderText="Surname" SortExpression="Surname" |
| UniqueName="Surname"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="First Name" HeaderText="First Name" SortExpression="First Name" |
| UniqueName="First Name"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Branch" HeaderText="Branch" SortExpression="Branch" |
| UniqueName="Branch"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Department" HeaderText="Department" SortExpression="Department" |
| UniqueName="Department"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Mobile" HeaderText="Mobile" SortExpression="Mobile" |
| UniqueName="Mobile"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| <EditFormSettings> |
| <EditColumn UniqueName="EditCommandColumn1"> |
| </EditColumn> |
| </EditFormSettings> |
| </MasterTableView> |
| <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" EnablePostBackOnRowClick="True"> |
| <Selecting AllowRowSelect="True" /> |
| <ClientEvents OnRowSelected="RowSelected" OnRowClick="RowSelected" /> |
| </ClientSettings> |
| </telerik:RadGrid> |
| <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:sql %>" |
| SelectCommand="SELECT username,phoneinternal AS 'Internal Phone',sname AS 'Surname',fname AS 'First Name',office AS 'Branch',department AS 'Department',mobile AS 'Mobile' FROM Phone_Dir WHERE phoneinternal IS NOT NULL AND phoneinternal <> '' ORDER BY office,sname"> |
| </asp:SqlDataSource> |
| <telerik:RadWindowManager ID="RadWindowManager1" runat="server"> |
| </telerik:RadWindowManager> |
| <telerik:RadWindow ID="RadWindow1" runat="server"> |
| </telerik:RadWindow> |
When trying to add the javascript programatically:
| protected void Page_Load(object sender, EventArgs e) |
| { |
| string javascript = "<script type=\"text/javascript\">"; |
| javascript += "function RowSelected(sender, args){var firstDataItem = $find(\"<%=rgPhoneDir.ClientID %>\").get_masterTableView().get_dataItems()[0];var uname = args.getDataKeyValue(\"username\") ;window.radopen(\"userinfo.aspx?id=\" + uname,\"RadWindow1\");}"; |
| javascript += "</script>"; |
| this.Page.ClientScript.RegisterClientScriptBlock(typeof(Page),"ClientScript", javascript); |
| } |