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

Rad Grid Edit Form Setting giving javascript error when i implement Ajax

8 Answers 330 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Padmaja
Top achievements
Rank 1
Padmaja asked on 23 Feb 2009, 08:06 AM
Hi All,

Am facing the problem with ajax implementation in Telerik Rad Grid.

In my page i implement RadAjaxmanager and RadAjaxPanel and RadGrid. Inside RadGrid. I want to edit details so am using EditFormSettings to edit details. In this EditFormSettings am calling a user control form.

My problem is, i dont want to allow unsafe script inside my edit form.
  1. So i turn on in web config file <%@ page Validate Request=True %>
  2.  If user enters unsafe script in any text box am catching exception in my Global application_error event and redirecting to another normal aspx page.
  3. if i use RadGrid and Update details i use  <EditFormSettings UserControlName="~/editform.ascx" EditFormType="WebUserControl" >. And i type any unsafe script message "<b>example</b>" inside the textbox.
    Error was capturing in Global.aspx file, But not redirecting to Error page and throwing a javasscript error


Codes am using

  1. My Web config code :
    <pages validateRequest="true"
    My Global File Code :
    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)  
            Dim ex As Exception = Server.GetLastError().GetBaseException()  
     
            If Not (ex.GetType Is GetType(HttpException)) Then  
                  
                If ex.Message.ToLower.Contains("a potentially dangerous request.form value was detected from the client") Then  
                    Try  
                        My.Log.WriteEntry("Global Error MESSAGE: " & ex.Message & "SOURCE: " & ex.Source & "STACKTRACE: " & ex.StackTrace, EventLogEntryType.Error)  
                    Catch ex1 As Exception  
                        My.Log.WriteEntry("Write event log got problem: " & ex1.Message, EventLogEntryType.Error)  
                    End Try  
                    Server.Transfer("~/UnsafeScriptErrorPage.aspx?returnURL=" & Server.UrlEncode(HttpContext.Current.Request.Url.ToString))  
                  
                ElseIf ex.Message.Trim.ToString <> "" Then  
                    Try  
                        My.Log.WriteEntry("Global Error MESSAGE: " & ex.Message & "SOURCE: " & ex.Source & "STACKTRACE: " & ex.StackTrace, EventLogEntryType.Error, False)  
                    Catch ex1 As Exception  
                        My.Log.WriteEntry("Write event log got problem: " & ex1.Message, EventLogEntryType.Error)  
                    End Try  
                    Server.Transfer("~/GenericErrorPage.aspx?errMsg=" & ex.Message & "&returnURL=" & Server.UrlEncode(HttpContext.Current.Request.Url.ToString), False)  
                End If  
                              
            End If  
              
            Server.ClearError()  
                End Sub 

    My First ASPX Code
  2. <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" 
        CodeFile="Inbox.aspx.vb" Inherits="Inbox" Title="Inbox" %> 
     
     
     
    <%@ Register assembly="RadAjax.Net2" namespace="Telerik.WebControls" tagprefix="radA" %> 
    <%@ Register src="../datagridControl.ascx" tagname="datagridControl" tagprefix="uc1" %> 
     
     
     
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">  
    <radA:RadAjaxPanel ID="RadAjaxPanelAppIn" runat="server" LoadingPanelID="AjaxLoadingPanelAppin" ClientEvents-OnRequestStart="pnlRequestStarted" 
            Width="100%">  
        <table border="0" cellpadding="0" cellspacing="0" class="HeaderBg" width="100%">  
            <tbody> 
                <tr> 
                    <td class="SideSpaceWidth">  
                    </td> 
                    <td class="SideSpaceHeight">  
                    <radA:AjaxLoadingPanel ID="AjaxLoadingPanelAppin" runat="server" IsSticky="True" 
                            MinDisplayTime="1000" Wrap="False">  
                            <asp:Image ID="Image1" runat="server" AlternateText="Loading..." ImageUrl="~/images/indicator.gif" /> 
                            <strong>Loading Content ...</strong></radA:AjaxLoadingPanel> 
                    </td> 
                    <td class="SideSpaceWidth">  
                    </td> 
                </tr> 
                <tr> 
                    <td > 
                    </td> 
                    <td> 
                        <uc1:datagridControl ID="DatagridControl1" runat="server" /> 
                    </td> 
                    <td> 
                    </td> 
                </tr> 
                <tr> 
                    <td> 
                    </td> 
                    <td class="SideSpaceHeight">  
                        &nbsp;</td> 
                    <td> 
                    </td> 
                </tr> 
                
            </tbody> 
        </table> 
        </radA:RadAjaxPanel> 
         
    </asp:Content> 
     
    Inside datagridControl.ascx down is the code for RadGrid
  3. <radG:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowFilteringByColumn="False" 
                    AllowMultiRowSelection="false" AllowPaging="True" AllowSorting="True" BackColor="Transparent" 
                    DataSourceID="GridDataSource" EnableAJAX="false" EnableAJAXLoadingTemplate="false" 
                    EnableViewState="true" GridLines="None" LoadingTemplateTransparency="50" ShowGroupPanel="True" 
                    ShowStatusBar="False" AutoGenerateColumns="true" OnUpdateCommand="RadGrid1_UpdateCommand" 
                    SkinID="myGrid" OnColumnCreated="ColumnCheck" OnPreRender="ReduceFilter" Width="100%" 
                    OnItemDataBound="ColDatabind">  
                    <MasterTableView DataSourceID="GridDataSource" GroupLoadMode="Client">  
                        <Columns> 
                            <radG:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="~/Images/edit.gif" 
                                UniqueName="EditCommandColumn1" Resizable="False" Reorderable="False">  
                                <HeaderStyle Width="15px" /> 
                            </radG:GridEditCommandColumn> 
                            <radG:GridTemplateColumn UniqueName="AssignUser" AllowFiltering="False" Reorderable="False" 
                                Groupable="False" Resizable="False" Visible="false">  
                                <HeaderStyle Width="20px" /> 
                                <HeaderTemplate /> 
                                <ItemTemplate> 
                                    <asp:ImageButton runat="Server" ID="ibtnAssignMsg" ImageUrl="~/images/Asgn.gif" CommandName="AssignMsgToUser" 
                                        ToolTip="Assign SMS to User" Visible="false" /> 
                                </ItemTemplate> 
                            </radG:GridTemplateColumn> 
                            <radG:GridTemplateColumn UniqueName="myselect" AllowFiltering="False" Reorderable="False" 
                                Groupable="False" Resizable="False">  
                                <HeaderStyle Width="20px" /> 
                                <HeaderTemplate> 
                                    <asp:CheckBox ID="selectall" runat="Server" OnLoad="SelectAll" /> 
                                </HeaderTemplate> 
                                <ItemTemplate> 
                                    <asp:CheckBox runat="Server" ID="myselect" OnLoad="ClearSAll" /> 
                                </ItemTemplate> 
                            </radG:GridTemplateColumn> 
                        </Columns> 
                        <EditFormSettings UserControlName="~/editform.ascx" EditFormType="WebUserControl" > 
                            <EditColumn UniqueName="EditCommandColumn">  
                            </EditColumn>                          
                        </EditFormSettings> 
                        <NoRecordsTemplate> 
                            <table width="100%">  
                                <tr> 
                                    <td align="center">  
                                        There are no items to display. Please check your selection criteria and retry.  
                                    </td> 
                                </tr> 
                            </table> 
                        </NoRecordsTemplate> 
                        <FooterStyle Height="0px" /> 
                        <ExpandCollapseColumn Visible="False">  
                            <HeaderStyle /> 
                        </ExpandCollapseColumn> 
                        <RowIndicatorColumn Visible="False">  
                            <HeaderStyle /> 
                        </RowIndicatorColumn> 
                    </MasterTableView>                 
                    <ClientSettings AllowGroupExpandCollapse="True" AllowDragToGroup="True" AllowColumnsReorder="True" 
                        ColumnsReorderMethod="Reorder" ApplyStylesOnClient="True">  
                        <Selecting AllowRowSelect="True" /> 
                        <Resizing AllowColumnResize="True" ResizeGridOnColumnResize="True" />                     
                    </ClientSettings> 
                </radG:RadGrid> 
    My Third EditForm User Control code
    <tr> 
                                    <td nowrap="nowrap">  
                                        <asp:Label ID="Label3" runat="server" meta:resourcekey="Label3Resource2" Text="Recipient(s)"></asp:Label></td>  
                                    <td> 
                                        <asp:Label ID="Label5" runat="server" CssClass="tips" meta:resourcekey="Label5Resource1" 
                                            Text="use ; to separate multiple numbers"></asp:Label> 
                                        <asp:TextBox ID="txtRecipient" runat="server" Visible="False"></asp:TextBox><asp:RequiredFieldValidator  
                                            ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtRecipient" 
                                            ErrorMessage="RequiredFieldValidator" meta:resourcekey="ContactTextRequiredResource1" 
                                            ToolTip="Mobile Number is required." ValidationGroup="SaveSMS">*</asp:RequiredFieldValidator> 
                                        <asp:RegularExpressionValidator  
                                                ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtRecipient" 
                                                ErrorMessage="Please enter numbers only" meta:resourcekey="contactValidatorResource1" 
                                                ValidationExpression="[0-9]+" ValidationGroup="SaveSMS"></asp:RegularExpressionValidator> 
                                        <asp:HiddenField ID="OutlogID" runat="server" /> 
                                    </td> 
                                </tr> 
    <tr> 
                                    <td> 
                                        <asp:Label ID="Label2" runat="server" meta:resourcekey="Label2Resource2" Text="SMS Text"></asp:Label></td>  
                                    <td> 
                                        <asp:TextBox ID="txtSMS" runat="server" Columns="50" Rows="5" TextMode="MultiLine"></asp:TextBox> 
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtSMS" 
                                            ErrorMessage="RequiredFieldValidator" meta:resourcekey="RequiredFieldValidator2Resource1" 
                                            ValidationGroup="QuickSMS">*</asp:RequiredFieldValidator></td>  
                                </tr> 
    When i type "<b>example</b> in text box. The unsafe script error was capturing in global and writting into event log but not redirecting top error display page and giving me always Javascript Error.
  4. am getting downside Javascript Error.


Microsoft JScript runtime error: Unexpected ajax response was received from the server.
This may be caused by one of the following reasons:

 - Server.Transfer.
 - Custom http handler.
- Incorrect loading of an "Ajaxified" user control

Verify that you don't get a server-side exception or any other undesired behavior, by setting the EnableAJAX property to false.



Any one Please help me in this issue. am waiting for your reply.

 

8 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 25 Feb 2009, 08:42 AM
Hello Padmaja,

As the error is saying you should not use Server.Transfer when in ajax request, but you should use for example Response.RedirectLocation instead. Please refer to this helps article for more information about the behavior in question.

Sincerely yours,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Padmaja
Top achievements
Rank 1
answered on 27 Feb 2009, 01:47 AM
Hi Telerik,

Thanks for your help...
According to your advice i use the response.redirectlocation, but its no use for me ..

Because when i use Response.RediretLocation , its not gettinf any javascript error. But the problem its not redirecting the page what i given in redirectlocation. Its always showing a blank empty page.

How can i get my redirect page?

Please help in this issue and am placing my code what i use in Global.asax file
 Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)  
         
        Dim ex As Exception = Server.GetLastError().GetBaseException()  
        If Not (ex.GetType Is GetType(HttpException)) Then  
              
            If ex.Message.ToLower.Contains("a potentially dangerous request.form value was detected from the client") Then  
                                 
                Context.ClearError()  
                 
                Response.RedirectLocation = "~/UnsafeScriptErrorPage.aspx?returnURL=" & Server.UrlEncode(HttpContext.Current.Request.Url.ToString))  
                Response.End()  
                  
            ElseIf ex.Message.Trim.ToString <> "" Then  
                 
                Context.ClearError()  
                  
                Response.RedirectLocation = "~/GenericErrorPage.aspx?errMsg=" & ex.Message & "&returnURL=" & Server.UrlEncode(HttpContext.Current.Request.Url.ToString)  
                Response.End()  
                  
            End If  
              
        End If  
         
    End Sub 
0
Rosen
Telerik team
answered on 04 Mar 2009, 10:36 AM
Hi Padmaja,

In order to use HttpResponse's RedirectLocation property  you should pass an absolute Uri, however you are passing an virtual url which is not supported. Please remove the ~/ part of the url and try it again.

All the best,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Anil Kumar Patra
Top achievements
Rank 2
answered on 29 Jan 2010, 11:13 AM
Hi Telerik,
                I am using Custom skin for radcombobox and all designs are appearing in my project,But in some page the Radinput colors are not appearing ,only the arrow keys are appearing with the given images but rcbinput class images are coming white only.So whats the problem with it ?pls help me.i m not getting any solution for this problem,I am also searching all forms but no one is providing the solution for this problem,so i send u this query ,pls pls pls help me.Thank you
0
Anil Kumar Patra
Top achievements
Rank 2
answered on 29 Jan 2010, 11:15 AM
Hi Telerik,
                I am using Custom skin for radcombobox and all designs are appearing in my project,But in some page the Radinput colors are not appearing ,only the arrow keys are appearing with the given images but rcbinput class images are coming white only.So whats the problem with it ?pls help me.i m not getting any solution for this problem,I am also searching all forms but no one is providing the solution for this problem,so i send u this query ,pls pls pls help me.Thank you
(I am sending u the snapshot of the radcombo,2nd one appearing perfectly but 1st one is not,Both have same skin file and same design)
0
Simon
Telerik team
answered on 03 Feb 2010, 03:12 PM
Hi Anil Kumar Patra,

Thank you for providing the screenshot.

It is possible that the two RadComboBox' read-only states differ as well as their corresponding styles.

Can you please send me your custom skin so that I verify this on my end?

Sincerely yours,
Simon
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Anil Kumar Patra
Top achievements
Rank 2
answered on 28 Jan 2011, 03:05 PM
Hi Telerik,
I need little help from you.i am using rad grid with data set.i want to bind the data from data set to radgrid.
when i am going to get the data from database to data set using sql data adapter object, at the time memory out of exception raises...
when i am using sqldatareader object then data is coming from database to datareader...and after when i am converting from datareader to dataset or generic list at that time memory out of exception raises.i need to some operation with dataset...i dont want to bind datareader to radgrid.
i am disposing all objects and after also i am using

Dim spname As String = "spGetLeafProductsForYahoo"
        Dim dr As SqlDataReader = SqlHelper.ExecuteReader(ConnectionString, CommandType.StoredProcedure, spname)
        Dim ds As New DataSet
        ds.RemotingFormat = SerializationFormat.Binary
        ds = convertDataReaderToDataSet(dr)

        'Dim dt As New DataTable
        'dt.Rows.Clear()
        'dt.Reset()
        'dt.BeginLoadData()
        'dt.Load(dr)
        'dt.EndLoadData()
        'ds.Tables.Add(dt)
        'ds.RemotingFormat = SerializationFormat.Binary
        'dt.RemotingFormat = SerializationFormat.Binary
        Return ds
    End Function

in this case its going to call load method of datatable at the time memory out of exception raises....
after that i am using property remoting format...even also exception is raised.
i have 2gb ram..and memory also there...but memory out of exception raising....
after that i am using
 Public Shared Function convertDataReaderToDataSet(ByVal reader As SqlDataReader) As DataSet
        Dim dataSet_Renamed As New DataSet()
        Do
            ' Create new data table

            Dim schemaTable As DataTable = reader.GetSchemaTable()
            Dim dataTable_Renamed As New DataTable()
            dataTable_Renamed.RemotingFormat = SerializationFormat.Binary
            If schemaTable IsNot Nothing Then
                ' A query returning records was executed

                For i As Integer = 0 To schemaTable.Rows.Count - 1
                    Dim dataRow_Renamed As DataRow = schemaTable.Rows(i)
                    ' Create a column name that is unique in the data table
                    Dim columnName As String = CStr(dataRow_Renamed("ColumnName")) '+ "<C" + i + "/>";
                    ' Add the column definition to the data table
                    Dim column As New DataColumn(columnName, CType(dataRow_Renamed("DataType"), Type))
                    dataTable_Renamed.Columns.Add(column)
                Next i

                dataSet_Renamed.Tables.Add(dataTable_Renamed)

                ' Fill the data table we just created

                Do While reader.Read()
                    Dim dataRow_Renamed As DataRow = dataTable_Renamed.NewRow()

                    For i As Integer = 0 To reader.FieldCount - 1
                        dataRow_Renamed(i) = reader.GetValue(i)
                    Next i

                    dataTable_Renamed.Rows.Add(dataRow_Renamed)
                Loop
            Else
                ' No records were returned

                Dim column As New DataColumn("RowsAffected")
                dataTable_Renamed.Columns.Add(column)
                dataSet_Renamed.Tables.Add(dataTable_Renamed)
                Dim dataRow_Renamed As DataRow = dataTable_Renamed.NewRow()
                dataRow_Renamed(0) = reader.RecordsAffected
                dataTable_Renamed.Rows.Add(dataRow_Renamed)
            End If
        Loop While reader.NextResult()
        Return dataSet_Renamed
    End Function


In this method also its going to raising the memory out of exception.
in my datareader have only 3000 records...not more then 3000.
so will u please some hints for solving this exception...i hanges two day onwards....
but i am unable to resolve...
pls help me...


Thanks
Anil
0
Veli
Telerik team
answered on 02 Feb 2011, 11:47 AM
Hello Anil,

This does not seem to be a RadGrid-related issue. Do you get the same exception trying to databind a standard ASP.NET GridView control?

Veli
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Padmaja
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Padmaja
Top achievements
Rank 1
Anil Kumar Patra
Top achievements
Rank 2
Simon
Telerik team
Veli
Telerik team
Share this question
or