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

RadGrid EditLink click gives Microsoft JScript runtime error: Object expected

3 Answers 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
irtazaali
Top achievements
Rank 1
irtazaali asked on 03 Jul 2011, 12:45 AM
I have a user control that contains a RadGrid with the EditLink column,

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Prospects.ascx.cs" Inherits="Prospects" %>  
    <telerik:RadCodeBlock ID="radcodeProspects" runat="server">
        <script type="text/javascript">
            function ShowEditForm(id, rowIndex) {
                alert(id);
                window.radopen("EditContact.aspx?ContactID=" + id, "UserListDialog");
                return false;
            }
            function ShowInsertForm() {
                window.radopen("EditContact.aspx", "UserListDialog");
                return false;
            }
            function refreshGrid(arg) {
                if (!arg) {
                    $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");
                }
                else {
                    $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindAndNavigate");
                }
            }
  
        </script>
    </telerik:RadCodeBlock>
     <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="prospectGrid" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="prospectGrid">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="prospectGrid" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
  
    <telerik:RadGrid AllowSorting="true" BackColor="#393939"
        ID="prospectGrid" runat="server" AllowPaging="true" PageSize="15" 
        Width="980px" CssClass="productsGrid" 
        OnPreRender="prospectGrid_PreRender"  OnItemCreated="prospectGrid_ItemCreated"
        OnNeedDataSource="prospectGrid_NeedDataSource" style="outline:0">
        <MasterTableView AutoGenerateColumns="false" PagerStyle-Mode="NextPrevAndNumeric" AllowFilteringByColumn="false"
                         DataKeyNames="OrderID" ClientDataKeyNames="OrderID" TableLayout="Fixed">
            <Columns>
                <telerik:GridBoundColumn DataField="OrderID" HeaderText="ProspectID" AutoPostBackOnFilter="true" ShowFilterIcon="false" HeaderStyle-Width="70px"  FilterControlWidth="35px">
                </telerik:GridBoundColumn>
                <telerik:GridNumericColumn DataField="Freight" HeaderText="Freight" DataFormatString="{0:c}" HeaderStyle-Width="110px" FilterControlWidth="60px">
                </telerik:GridNumericColumn>
                <telerik:GridBoundColumn DataField="ShipName" HeaderText="Prospect Name" HeaderStyle-Width="300px" FilterControlWidth="260px">
                </telerik:GridBoundColumn>      
                <telerik:GridBoundColumn DataField="ShipCountry" HeaderText="Country" FilterControlWidth="70px">
                </telerik:GridBoundColumn>
                <telerik:GridDateTimeColumn DataField="OrderDate" HeaderText="Order Date" DataFormatString="{0:d}" FilterControlWidth="95px">
                </telerik:GridDateTimeColumn>
                <telerik:GridDateTimeColumn DataField="ShippedDate" HeaderText="Shipping Date" DataFormatString="{0:d}" FilterControlWidth="95px">
                </telerik:GridDateTimeColumn>
                <telerik:GridTemplateColumn UniqueName="TemplateEditColumn">
                    <ItemTemplate>
                        <asp:HyperLink ID="EditLink" runat="server" Text="Edit"></asp:HyperLink>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings AllowDragToGroup="false" EnableRowHoverStyle="true">
            <Selecting AllowRowSelect="true" />
            <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="360px" />
        </ClientSettings>
    </telerik:RadGrid>
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true">
            <Windows>
                <telerik:RadWindow ID="UserListDialog" runat="server" Title="Editing record" Height="320px"
                    Width="310px" Left="150px" ReloadOnShow="true" ShowContentDuringLoad="false"
                    Modal="true" />
            </Windows>
    </telerik:RadWindowManager>
  
    <telerik:RadAjaxLoadingPanel ID="ProductsLoadingPanel" runat="server"></telerik:RadAjaxLoadingPanel>

and the onClick code is generated in the code-behind file,

protected void prospectGrid_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            HyperLink editLink = (HyperLink)e.Item.FindControl("EditLink");
            editLink.Attributes["href"] = "#";
            editLink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["OrderID"], e.Item.ItemIndex);
        }
    }
  
    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument == "Rebind")
        {
            prospectGrid.MasterTableView.SortExpressions.Clear();
            prospectGrid.MasterTableView.GroupByExpressions.Clear();
            prospectGrid.Rebind();
        }
        else if (e.Argument == "RebindAndNavigate")
        {
            prospectGrid.MasterTableView.SortExpressions.Clear();
            prospectGrid.MasterTableView.GroupByExpressions.Clear();
            prospectGrid.MasterTableView.CurrentPageIndex = prospectGrid.MasterTableView.PageCount - 1;
            prospectGrid.Rebind();
        }
    }

but whenever I click on the EditLink hyperlink I get the Microsoft JScript runtime error: Object expected exception.

My default.aspx RadScriptManager code,

<telerik:RadScriptManager runat="server" ID="RadScriptManager1">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Path="~/Scripts/jquery.maphilight.min.js" />
            <asp:ScriptReference Path="~/Scripts/maphilight.js" />
        </Scripts>
    </telerik:RadScriptManager>



any help will be appreciated.

3 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 06 Jul 2011, 02:34 PM
Hello Syed,

I looked through your code and I cannot see an obvious reason for the described issue. You can see how the same code works in the Edit Dialog for RadGrid demo.
If the problem persists, please open a formal support ticket and send us a small working project, demonstrating your full setup and showing the unwanted behavior.
We will debug it locally and get back to you.

Thank you in advance for the cooperation.

Greetings,
Mira
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
irtazaali
Top achievements
Rank 1
answered on 06 Jul 2011, 04:07 PM
Ok you are right. I had a javascript issue and it was resolved.

Now I am having another issue and will be glad if you could guide to any article or link that explains this implementation. I want to use the RadWindow (asp.net ajax) as a wizard. Right now if I click on any button Previous, Next, or Cancel the window closes and applies a postback on the parent page. I have tried 'return false;' for the OnClientClick event but it does not work.
0
Mira
Telerik team
answered on 08 Jul 2011, 03:57 PM
Hello Irtazaali,

Please examine the following demos to see how the desired functionality can be implemented:
Wizard
E-mail System

I hope this helps.

All the best,
Mira
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
irtazaali
Top achievements
Rank 1
Answers by
Mira
Telerik team
irtazaali
Top achievements
Rank 1
Share this question
or