Error while selecting text with single quotes

10 posts, 2 answers
  1. divyalok suman
    divyalok suman avatar
    9 posts
    Member since:
    May 2010

    Posted 20 Aug 2012 Link to this post

    Hi,

    I am binding AutoCompleteBox  with my DB. In my table there are names like( xyz's company,robin's house etc.).
    When i type x it shows me the name list but when i select the xyz's company i just got error because of single quotes.

    Please help!!!!!!!!

    Thanks in Advance.


     
  2. Answer
    Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 20 Aug 2012 Link to this post

    Hi divyalok suman,

    The issue that you describe is quite strange.
    I tried to reproduce it with RadAutoCompleteBox populated with data from the Northwind database (the Products table) - but without success - please take a look at this demonstration video.
    Please download the sample that I have attached here and give it a try.

    All the best,
    Kalina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. divyalok suman
    divyalok suman avatar
    9 posts
    Member since:
    May 2010

    Posted 21 Aug 2012 Link to this post

    Hi Kalina,

    Thanks for your quick response.

    The problem again occurs when i add OnEntryAdded="SetValue" this event. and try to call the server side method to set text value(s). 
    Is there any other way that i can set the text value(s) to server side variable? Actually i was trying to fill other autocompletebox depending on the text in first one.
    Like One organisation have 2 employee and other organisation have 4 employee. so if both selected in 1st drop down then all the 6 contact should display.


    Thanks alot!!!!!!

    Regards,
    DLS
  5. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 21 Aug 2012 Link to this post

    Hello divyalok suman,

    I am not sure that I understand what you mean by "call the server side method to set text value(s)".
    Maybe you want to add an initially selected entry(entries) in the second RadAutoCompleteBox?
    You can make this by simply adding these entries in the control Entries collection:
    <telerik:RadAutoCompleteBox runat="server"
        ID="RadAutoComplete1" Width="300"
        DropDownWidth="300"
        DataSourceID="SqlDataSource1"
        DataTextField="CategoryName"
        DataValueField="CategoryID">
    </telerik:RadAutoCompleteBox>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString1 %>"
        SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]">
    </asp:SqlDataSource>

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            this.RadAutoComplete1.Entries.Add(new Telerik.Web.UI.AutoCompleteBoxEntry("Condiments", "2"));
    }


    Regards,
    Kalina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. divyalok suman
    divyalok suman avatar
    9 posts
    Member since:
    May 2010

    Posted 21 Aug 2012 Link to this post

    Hi Kalina,

    Actually my scenario is there are two controls i.e. RadAutoCompleteBox1 and RadAutoCompleteBox2.  I load the company name in first control and i want all the employee related to that company in second control i.e. ( when i try to write name it should display the related employee name).
    so for that when i added the server side event   OnEntryAdded="SetValue"  and  when i select any text like "xyz's company" then it give me an error.

    So, plz suggest how can i achieve this goal.

    Thanks in advance..

    Regards,
    DLS
     

  7. divyalok suman
    divyalok suman avatar
    9 posts
    Member since:
    May 2010

    Posted 21 Aug 2012 Link to this post

    Hi ,


    Please help!!!!!!!!!.

    Thanks in ADV.

    DLS
  8. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 22 Aug 2012 Link to this post

    Hi divyalok suman,

    The sample code provided below only illustrated the approach that you can use.

    As I understand – your scenario is more specific.
    Please provide us more details about your implementation and paste here some working code to illustrate it.
    Thank you in advance.

    Regards,
    Kalina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  9. divyalok suman
    divyalok suman avatar
    9 posts
    Member since:
    May 2010

    Posted 23 Aug 2012 Link to this post

    Hi Kalina,

    Thanks for your reply.

    I have pasted  the sample code below. Please have look. Just select any value having apostrophe sign and then you will see error.

    Code for ASPX page

    <div>
            <asp:ScriptManager ID="Manager" runat="server">
            </asp:ScriptManager>
            <telerik:RadAutoCompleteBox runat="server" ID="RadAutoCompleteBox1" Width="300" DataSourceID="SqlDataSource1"
                DataTextField="LastName" DataValueField="EmployeeID" OnEntryAdded="RadAutoCompleteBox1_EntryAdded">
            </telerik:RadAutoCompleteBox>

            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                SelectCommand="SELECT * FROM [Employees]"></asp:SqlDataSource>

                 <br />
                 <asp:Label ID="Label1" runat="server" />
        </div>

    For Code Behind

     protected void RadAutoCompleteBox1_EntryAdded(object sender, AutoCompleteEntryEventArgs e)
            {
                Label1.Text = e.Entry.Text + " was added.";
            }

    Please suggest solution.

    Thanks in advance.

    Regards,

    Divyalok Suman.
  10. divyalok suman
    divyalok suman avatar
    9 posts
    Member since:
    May 2010

    Posted 27 Aug 2012 Link to this post

    Hi,

    Please suggest the solution for this problem.



    Thanks in advance..

    DLS
  11. Answer
    Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 28 Aug 2012 Link to this post

    Hello divyalok suman,

    I managed to reproduce the issue.
    Let me suggest you handle the OnClientEntryAdding event in this way:

    <head runat="server">
    <title></title>
    <script type="text/javascript">
         
    function OnClientEntryAdding(sender, eventArgs) {
        var text = eventArgs.get_entry().get_text().replace("'", "&#39");
        eventArgs.get_entry().set_text(text);
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <telerik:RadAutoCompleteBox runat="server" ID="RadAutoCompleteBox1" Width="300"
            DataSourceID="SqlDataSource1"  OnClientEntryAdding="OnClientEntryAdding"
            DataTextField="LastName" DataValueField="EmployeeID"
            OnEntryAdded="RadAutoCompleteBox1_EntryAdded">
        </telerik:RadAutoCompleteBox>
    </div>
    <asp:Label ID="Label1" runat="server" />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString1 %>"
        ProviderName="<%$ ConnectionStrings:NorthwindConnectionString1.ProviderName %>"
        SelectCommand="SELECT *  FROM [Employees]"
        >
     
    </asp:SqlDataSource>
    </form>
    </body>


    All the best,
    Kalina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017