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

Scripts are not working in RadGrid with Usercontrol

6 Answers 277 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sridhar Reddy Bommireddy
Top achievements
Rank 1
Sridhar Reddy Bommireddy asked on 25 Jan 2010, 12:32 PM
I am unable to access scripts from button click event.
I am getting error in viewstate of a page.

Note: My script is in RadScriptBlock.

Help me....

Thank U.

6 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 25 Jan 2010, 02:00 PM
Hello Sridhar,

Could you please specify what is the error you received? You can also send the problematic code, in the form of a small working project, for further investigation.

Greetings,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Yoong Hui Chia
Top achievements
Rank 1
answered on 25 Jan 2010, 05:34 PM
Hi,

I have the same problem.

If you refer to this example, everything is working perfectly until you added the javascript inside.

<

 

telerik:RadTextBox ID="txtFirstName" runat="server" Width="180px" >

 

 

<ClientEvents OnBlur="function1" />

 

 

</telerik:RadTextBox>

Event if function1 is defined within <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

You will hit function1 is not defined error,

Can you please help on this ?

Thanks,

 

0
Yoong Hui Chia
Top achievements
Rank 1
answered on 25 Jan 2010, 05:47 PM
Hi everyone,

I found the solution !!!!

Please use RadScriptBlock instead of the codeblock, it works perfectly !!!


http://www.telerik.com/help/aspnet-ajax/ajxradscriptblockradcodeblock.html
0
Sridhar Reddy Bommireddy
Top achievements
Rank 1
answered on 27 Jan 2010, 09:35 AM
Default.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" 
    CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"
 <telerik:RadAjaxLoadingPanel runat="server" ID="LoadingPanel1"
    </telerik:RadAjaxLoadingPanel> 
    <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadTabStrip1"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadTabStrip1" /> 
                    <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="LoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
     
    <telerik:radtabstrip id="RadTabStrip1" OnTabClick="RadTabStrip1_TabClick" multipageid="RadMultiPage1" runat="server"
        <Tabs> 
            <telerik:RadTab Text="Tab1" Value="D"
            </telerik:RadTab> 
            <telerik:RadTab Text="Tab2" Value="AD" > 
            </telerik:RadTab> 
            <telerik:RadTab Text="Tab3" Value="F" > 
            </telerik:RadTab> 
            <telerik:RadTab Text="Tab4" Value="AP"
            </telerik:RadTab> 
            <telerik:RadTab Text="Tab5" Value="I" > 
            </telerik:RadTab> 
        </Tabs> 
    </telerik:radtabstrip> 
    <telerik:radmultipage id="RadMultiPage1" runat="server" renderselectedpageonly="true" 
        selectedindex="0" width="100%"
        <telerik:RadPageView ID="rpv_Tab1" BorderStyle="Groove" runat="server" Width="100%"
            Tab1 
        </telerik:RadPageView> 
        <telerik:RadPageView ID="rpv1_Tab2" BorderStyle="Groove" runat="server" Width="100%"
            Tab2 
        </telerik:RadPageView> 
        <telerik:RadPageView ID="rpv_Tab3" BorderStyle="Groove" runat="server" Width="100%"
        Tab3 
        </telerik:RadPageView> 
        <telerik:RadPageView ID="rpv_Tab4" BorderStyle="Groove" runat="server" Width="100%"
        Tab4 
        </telerik:RadPageView> 
        <telerik:RadPageView ID="rpv_Tab5" BorderStyle="Groove" runat="server" Width="100%"
            Tab5 
             
            <telerik:RadGrid ID="rgrid_Sample" AllowAutomaticInserts="false" AllowAutomaticUpdates="false" 
                                        Width="100%" ShowStatusBar="true" AutoGenerateColumns="false"  
                                         
                                         OnNeedDataSource = "rgrid_Sample_NeedDataSource" 
                                         runat="server"
                                        <MasterTableView AllowAutomaticInserts="false" AllowAutomaticUpdates="false" CommandItemDisplay="Top" 
                                            EditMode="PopUp" CommandItemSettings-AddNewRecordText="Add " 
                                             GridLines="Both" TableLayout="Fixed"
                                            <Columns> 
                                                <telerik:GridBoundColumn HeaderText="ProductID"  DataField="ProductID"
                                                </telerik:GridBoundColumn> 
                                                <telerik:GridBoundColumn HeaderText="ProductName" DataField="ProductName" 
                                                    HeaderStyle-Width="70%"
                                                </telerik:GridBoundColumn> 
                                                
                                                <telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-Width="5%" HeaderText="Edit"
                                                </telerik:GridEditCommandColumn> 
                                               <%-- <telerik:GridButtonColumn CommandName="Delete" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" 
                                                    HeaderStyle-Width="10%" HeaderText="Delete" ConfirmText="Are you sure you want to delete?" 
                                                    ButtonType="ImageButton" Text="Delete" UniqueName="DeleteColumn" ConfirmDialogHeight="50px"
                                                </telerik:GridButtonColumn>--%> 
                                            </Columns> 
                                            <NoRecordsTemplate> 
                                                <div style="height: 80px;"
                                                    No Records Exists..... 
                                                </div> 
                                            </NoRecordsTemplate> 
                                             
                                            <EditFormSettings CaptionFormatString="Update " 
                                                InsertCaption="Select " EditFormType="WebUserControl" PopUpSettings-Modal="true" 
                                                UserControlName="Controls/WebUserControl.ascx"
                                                <FormTemplate> 
                                                </FormTemplate> 
                                                <PopUpSettings Modal="True" Width="57%" ZIndex="150" /> 
                                            </EditFormSettings> 
                                        </MasterTableView> 
                                        <AlternatingItemStyle BackColor="#A0D9FA" /> 
                                    </telerik:RadGrid> 
        </telerik:RadPageView> 
    </telerik:radmultipage> 
</asp:Content> 
 

Default.aspx.cs

using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 
using Telerik.Web.UI; 
using System.Collections.Generic; 
 
public partial class _Default : System.Web.UI.Page 
    protected void Page_Load(object sender, EventArgs e) 
    { 
 
    } 
    protected void RadTabStrip1_TabClick(object sender, RadTabStripEventArgs e) 
    { 
 
    } 
    protected void rgrid_Sample_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        List<Product> obj = new List<Product>(); 
        obj.Add(new Product("1","Prod1","Cat1")); 
         obj.Add(new Product("2","Prod2","Cat2")); 
        rgrid_Sample.DataSource = obj; 
    } 
 

Controls/WebUserControl.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" 
    Inherits="Controls_WebUserControl" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"
    <script type="text/javascript" language="javascript"
    function fnValidate() 
    { 
    // Added Code Here.  
    return false; 
    } 
     
    </script> 
    </telerik:RadScriptBlock> 
     
<table width="100%"
    <tr> 
        <td> 
            Product ID 
        </td> 
        <td> 
            <asp:TextBox ID="txtProductID" runat="server"></asp:TextBox> 
        </td> 
    </tr> 
     <tr> 
        <td> 
            Product Name 
        </td> 
        <td> 
            <asp:TextBox ID="txtProdName" runat="server"></asp:TextBox> 
        </td> 
    </tr> 
     <tr> 
        <td> 
            Product Category 
        </td> 
        <td> 
            <asp:TextBox ID="txtProdCategory" runat="server"></asp:TextBox> 
        </td> 
    </tr> 
     <tr> 
        <td colspan="2"
            <asp:Button ID="btnsubmit" runat="server" OnClientClick="javascript:return fnValidate();"  CommandName="PerformInsert" Text="Save" /> 
        </td> 
    </tr> 
</table> 
 

Controls/WebUserControl.ascx.cs

using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 
 
public partial class Controls_WebUserControl : System.Web.UI.UserControl 
    protected void Page_Load(object sender, EventArgs e) 
    { 
 
    } 
 


Steps to reproduce the issue

1. Run the Website with a start page of Default.aspx.
2. Click on 5th tab.
3. Click on Add button which is on the top of RadGrid.
4. Click on save button. You will get the 'Object Expected' Error. 

Note: I checked with the RadScirptBlock & RadCodeBlock. But, i am unable to  find the solution .


Thank U

Sridhar





0
Accepted
Pavlina
Telerik team
answered on 29 Jan 2010, 12:39 PM
Hi Sridhar,

Please try to change the AjaxSettings as shown bellow in order to avoid the error you received.
ASPX:
<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadTabStrip1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadTabStrip1" />
                <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="LoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting AjaxControlID="RadMultiPage1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="LoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>


Give this it a try and see if it helps.

Greetings,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Sridhar Reddy Bommireddy
Top achievements
Rank 1
answered on 30 Jan 2010, 01:12 PM
Hi Pavlina,

It works for me.But, it causing the all tabs to load for single partial-postback from any tab.So, slightly we modified the Code.Finally, we fulfilled the requirement with a below code snippet .

<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1"
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="RadTabStrip1"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="RadTabStrip1" /> 
                <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" LoadingPanelID="LoadingPanel1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
        <telerik:AjaxSetting AjaxControlID="rgrid_Sample"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="rgrid_Sample" LoadingPanelID="LoadingPanel1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManager> 

    GREAT SUPPORT........    Telerik Team...

Thanks,

Sridhar
Tags
Grid
Asked by
Sridhar Reddy Bommireddy
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Yoong Hui Chia
Top achievements
Rank 1
Sridhar Reddy Bommireddy
Top achievements
Rank 1
Share this question
or