Page 1 of 3 123 LastLast
Results 1 to 40 of 82

Thread: [RESOLVED] How to Use Ajaxcontroltoolki autocomplete with database data

  1. #1

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Resolved [RESOLVED] How to Use Ajaxcontroltoolki autocomplete with database data

    Hi Guys,

    I want to populate a textbox using the ajax control toolkit autocomplete with data from a mysql datatbase. please show me the best way, and get me started. thanks

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Hey,

    I am assuming that you have had a look here:

    http://www.asp.net/AJAX/AjaxControlT...oComplete.aspx

    The fact that the information is coming from a MySQL database really don't make any difference, you just need to still create a method to pull back the completion list.

    Are you using the MySQL Connector .Net, if not, have a look at the link in my signature.

    Gary

  3. #3

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    thanks Gary. I am looking at the currently. I never created a web service before, so I posted it here. However, I am giving the web service a show. It does give me an opportunity to learn new stuff. Will let you know how it goes

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    It's expecting -

    ServicePath="AutoComplete.asmx"
    and
    ServiceMethod="GetCompletionList"

    It doesn't need to be a web service path, it can be a method on the page too, but remember to decorate it with [WebMethod] in either case so that it can be called as a web service from the javascript code that AJAX generates. Remember that the method must accept a 'prefix text' argument, and must return an array of strings. So something like this:

    Code:
    [WebMethod]
    public string[] GetNames(string prefix)
    {
    //
    }

    It'll be cleaner if you make it an ASMX though. You could make a WCF service too, but then remember to add

    Code:
    [ServiceContract(Namespace = "")]
    
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

  5. #5

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    thanks for that mendhak. Please check my function and let me know if it is correct.

    Code:
     <WebMethod()> _
        Public Function GetOccupations(ByVal prefixText As String) As String()
            Dim OccList As New List(Of String)
            Using con As New MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("constr").ConnectionString)
                Dim OccReader As MySqlDataReader
                Dim occCmd As New MySqlCommand("SELECT occupationid,descr FROM occupations WHERE lcase(descr) like ?descr;", con)
                occCmd.Parameters.AddWithValue("?descr", prefixText & "%")
    
                con.Open()
    
                OccReader = occCmd.ExecuteReader
    
                While (OccReader.Read)
    
                    If Not OccReader.IsDBNull(1) Then
    
                        OccList.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(OccReader.GetString(1), OccReader.GetUInt32(0)))
                    End If
                End While
    
                con.Close()
                OccReader.Close()
            End Using
            Return OccList.ToArray
    
        End Function
    I am returning key/value pairs because I will need to write the selected items id to the database.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Does it work?

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Wait, what's this about?

    Code:
     OccList.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(OccReader.GetString(1), OccReader.GetUInt32(0)))
    You only need to deal with what's coming back from the database. While datareader.Read, add the items to an ArrayList or List(Of String). When it's time to return, return listName.ToArray().

  8. #8

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Hi mendhak,

    i got that from this link:

    http://blogs.msdn.com/phaniraj/archi...eextender.aspx

    it's exactly what I need. Haven't got to the part where I get the id value. Not usre how to add a handler for that event

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    That looks... just weird. I'd still stick to a list of strings. That's all you're returning anyways. But whatever works.

    What id value?

  10. #10

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    What id value?
    I need the occupationid so I can save that primary key value to my guardians table occupationid field. When the user selects an item from the autocomplete textbox I need its corresponding id

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Oh, you'd need the AutoCompleteItem after all then

    What's your code so far?

  12. #12

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    heres my aspx code:

    Code:
    <&#37;@ Page Language="VB" MasterPageFile="~/update.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="MySql.Data.MySqlClient" %> 
        
    
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"   >         
             <asp:ScriptManager ID="ScriptManager1" runat="server">
             <Services>
             <asp:ServiceReference Path="~/ClService.asmx" />  
             </Services> 
                    </asp:ScriptManager>
            <div class="container">
            <div class="header">
    			<img class="top-left" src="images/top-left.gif" />
    			<div>Guardian Information Update</div>
    			<img class="top-right" src="images/top-right.gif" />
    		</div>
            <div class="content" >
            <asp:Repeater ID="GuardianRepeater"  
                runat="server">
                <HeaderTemplate>
                <table>
                </HeaderTemplate> 
                <ItemTemplate>
                    <asp:TextBox ID="Gid" CssClass="hidden" runat="server" Text='<%#Container.DataItem("GuardianID")%>'></asp:TextBox>
                    <tr>
                    <td>Surname:</td><td><asp:TextBox ID="Surname" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Surname")%>' ></asp:TextBox></td><td></td>
                    <td>First Names:</td><td><asp:TextBox ID="Firstnames" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("firstnames")%>' ></asp:TextBox></td> <td></td><td></td>
                    </tr>
                    
                    <tr>
                    <td>ID Number:</td><td><asp:TextBox ID="idnumber" runat="server" CssClass="surnametextbox"  Text='<%#Container.DataItem("IDNumber")%>' ></asp:TextBox></td> <td></td>
                    <td>Cell:</td><td><asp:TextBox ID="cellphone" runat="server" CssClass="surnametextbox"  Text='<%#Container.DataItem("cell")%>' ></asp:TextBox></td> <td></td><td></td>
                    </tr>
                    
                    <tr>
                    <td>Tel(Work):</td><td><asp:TextBox ID="telwork" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Tel_Work")%>' ></asp:TextBox></td><td><cc1:MaskedEditValidator ID="MaskedEditValidator1" ControlExtender="MaskedEditExtender1" ControlToValidate="telwork" TooltipMessage="Enter a Number in this format: (999)9999999" runat="server"></cc1:MaskedEditValidator></td>
                    <td>Tel(Home):</td><td><asp:TextBox ID="telhome" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Tel_Home")%>' ></asp:TextBox></td> <td></td><td></td>
                    </tr>
                    
                    <tr>
                    <td>Fax(Work):</td><td><asp:TextBox ID="faxwork" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Fax_Work")%>' ></asp:TextBox></td><td></td>
                    <td>Fax(Home):</td><td><asp:TextBox ID="faxhome" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Fax_Home")%>' ></asp:TextBox></td> <td></td>
                    </tr>
                     
                    <tr>
                    <td>Occupation:</td><td>
                        <asp:TextBox ID="occupation" CssClass="autocompletetextbox" runat="server" Text='<%#Container.DataItem("occupation")%>'></asp:TextBox></td>
                    </tr>
                    
                    <tr>
                    <td>Work E-Mail:</td><td><asp:TextBox ID="email" runat="server" CssClass="emailtextbox" Text='<%#Container.DataItem("email")%>' ></asp:TextBox></td><td><asp:CheckBox ID="chkCanEmail" Checked='<%#Container.DataItem("CanEmail")%>' runat="server" />Receive E-mail Correspondence on this Address</td> 
                    </tr>
                    
                    <td>Home E-Mail:</td><td><asp:TextBox ID="HomeEmail" runat="server" CssClass="emailtextbox" Text='<%#Container.DataItem("HomeEmail")%>'></asp:TextBox></td><td><asp:CheckBox ID="chkCanEmailHome" Checked='<%#Container.DataItem("CanEmailHome")%>' runat="server" />Receive E-mail Correspondence on this Address</td><tr>
                    
                   
                    </tr>
                    
                    
                   
                     <cc1:MaskedEditExtender ID="MaskedEditExtender1" TargetControlID="telwork" Mask="(999)9999999" MessageValidatorTip="true" MaskType="Number"   ErrorTooltipEnabled="true" runat="server"  ></cc1:MaskedEditExtender> 
                     <cc1:MaskedEditExtender ID="MaskedEditExtender2" TargetControlID="telhome" Mask="(999)9999999" MessageValidatorTip="true" MaskType="Number" ErrorTooltipEnabled="true" runat="server"></cc1:MaskedEditExtender>         
                    <cc1:AutoCompleteExtender ID="OccAutoCompleteExtender" TargetControlID="occupation" ServicePath="ClService.asmx" ServiceMethod="GetOccupations" MinimumPrefixLength="2" CompletionInterval="1000" OnClientItemSelected="IAmSelected"  runat="server">
                    </cc1:AutoCompleteExtender>
                   <%-- <asp:RequiredFieldValidator ID="RfEmail" ControlToValidate="email" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>--%>
                    <asp:RegularExpressionValidator ID="RevEmail" ControlToValidate="email" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" runat="server" ErrorMessage="*Email must be in the format of [email protected]" Display="Dynamic" ></asp:RegularExpressionValidator>
                </ItemTemplate> 
                <SeparatorTemplate>
                <tr>
                <td colspan="6" >
                <hr />
                </td>
                </tr>
                </SeparatorTemplate> 
                
                <FooterTemplate>
                </table> 
                </FooterTemplate> 
            </asp:Repeater>
             <div >
            <asp:Button ID="btnSave" runat="server" Text="Save" onclick="SaveInfo"/>
            </div>
            </div>
            
            
    <div class="footer">
    			<img class="top-left" src="images/bottom-left.gif" />
    			<img class="top-right" src="images/bottom-right.gif" />
    		</div>
    		</div>
        
    		
    </asp:Content>
    and heres my javascript function that gets called when the autocomplete item is selected:

    Code:
    <script language="javascript" type="text/javascript">
        function IAmSelected( source, eventArgs ) {
    
            alert( " Key : "+ eventArgs.get_text() +"  Value :  "+eventArgs.get_value()); 
    
            //Do something to reset the ID Field
    
            }
    
    
        </script>
    it works great. But i was thinking of saving the key value in a hidden textbox and when it comes to saving to the database I would use that value. Can you think of a better way
    Last edited by Nitesh; Aug 12th, 2009 at 08:52 AM.

  13. #13

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    please help me someone. I'm stuck

  14. #14
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    No, that sounds good - save the key to a hidden field. How else are you going to do it?

    To set a hidden field value,

    Code:
    document.getElementById('hiddenfieldid').value = eventArgs.get_value();

  15. #15

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    thanks mendhak.will give it a shot tomorrow

  16. #16

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Hi mendhak,

    http://encosia.com/2007/08/08/robust...in-javascript/

    i used your code:

    Code:
    document.getElementById(hdntest).value = eventArgs.get_value();
    I get an error saying : document.getelementbyid(...) is null or not an object.

    heres my aspx code:

    Code:
     <asp:HiddenField ID="hdntest" runat="server" />
    looking at the above link, getting this fields value is a problem, since it is in a repeater and I have more than 1 control called hdntest. Please tell me how to get around this. Thanks

  17. #17
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Hey,

    Have you pasted the error message into the forum?

    If so, you do not have the correct case in the getElementById method, remember that JavaScript is case sensitive.

    Also, you do not have apostrophe's in the code you are using.

    It should be:

    Code:
    document.getElementById('hdntest').value = eventArgs.get_value();
    Assuming that hdntest is the id of the hidden field you are using.

    Gary

  18. #18

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Hi again,

    I do have apostrophes in my code. I don't know why it got stripped out in the post.

  19. #19
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Hmmm, strange.

    Is the case of getElementById correct?

    Also, you might want to do a View Source of the page to check that it has rendered correctly on the client. Also, are there any JavaScripts errors on the page?

    Gary

  20. #20

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    hi,

    this one instance of the hidden field:

    Code:
     <input type="hidden" name="ctl00$ContentPlaceHolder1$GuardianRepeater$ctl03$hdntest" id="ctl00_ContentPlaceHolder1_GuardianRepeater_ctl03_hdntest" />
    as far as i know the case is correct for getelementbyid.

    that error saying is null.... is a javascript error

  21. #21
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Hey,

    Well this is why it isn't working.

    You are looking for this:

    Code:
    document.getElementById('hdntest').value = eventArgs.get_value();
    when you should be looking for this:

    Code:
    document.getElementById('ctl00_ContentPlaceHolder1_GuardianRepeater_ctl03_hdntest').value = eventArgs.get_value();
    This is similar to you other post regarding the ClientID of the controls that you have on the page.

    One quick way to get this working would be to do this:

    Code:
    document.getElementById('<&#37;= hdntest.ClientID %>').value = eventArgs.get_value();
    shudder, shudder, shudder

    Gary

  22. #22

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    thanks gep,

    I tried this:

    Code:
    If Not (ClientScript.IsClientScriptBlockRegistered("MyScript")) Then
                    ClientScript.RegisterClientScriptBlock(Me.GetType, "MyScript", "function IAmSelected( source, eventArgs ) { document.getElementById('<%= hdntest.ClientID %>').value = eventArgs.get_value(); }", True)
                End If
    the javascript function gets added to the page but i still get the same error

  23. #23
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Hey,

    How does that get rendered on the page?

    Can you do a view Source and paste a relevant section?

    Gary

  24. #24

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    this is it currently:

    Code:
    <script type="text/javascript">
    //<![CDATA[
    function IAmSelected( source, eventArgs ) { document.getElementById('<%= hdntest.ClientID %>').value = eventArgs.get_value(); }//]]>
    </script>
    if I just do an alert(eventArgs.get_value() it workd fine. the getElementById is failing.

  25. #25
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Hey,

    That is the source of the page?

    If so, it is failing because the inline server tag hasn't worked, it hasn't got the information from the server. I suspect that that is due to the CDATA tag around the script.

    Since you are doing this the way you are, try this:

    Code:
    If Not (ClientScript.IsClientScriptBlockRegistered("MyScript")) Then
                    ClientScript.RegisterClientScriptBlock(Me.GetType, "MyScript", "function IAmSelected( source, eventArgs ) { document.getElementById('" & hdnTest.ClientID & "').value = eventArgs.get_value(); }", True)
                End If
    And see if that works.

    Gary

  26. #26

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    no luck

  27. #27
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Did the code I give you compile and run?

    If so, what was the source on the page?

    Gary

  28. #28

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    nope. my codebehind doesn't like this :
    Code:
    '" & hdnTest.ClientID & "'
    it underlines hdntest and says its not declared

  29. #29
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Okay, let me try and break down what I am trying to do here, to make sure we are on the same page.

    You are currently writing on the JavaScript that you want to run on the client, and what I am trying to do is concatenate the ClientID of the hidden input field into that JavaScript.

    You have:

    Code:
    <asp:HiddenField ID="hdntest" runat="server" />
    Which means that the server side code should be able to see that control, so I don't see why it couldn't see it.

    Can you post all the code that you are currently using regarding this issue, so we can see it in situ?

    Gary

  30. #30

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    ok maybe it can't see it because it's in a reapeater.

    trying something like this:
    Code:
    GuardianRepeater.FindControl("hdntest").ClientID
    which i expected to work, but I get an error saying object reference not set to an instance of an object. probablt the javascript is trying to get the value b4 the control is rendered

  31. #31
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Can you show the ASPX for the repeater that you are using?

    Gary

  32. #32

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    its quite alot of code: i have highighted the mail areas: removed some code because it was too long

    Code:
    <%@ Page Language="VB" MasterPageFile="~/update.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="MySql.Data.MySqlClient" %> 
        
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"   >         
             <asp:ScriptManager ID="ScriptManager1" runat="server">
             <Services>
             <asp:ServiceReference Path="~/ClService.asmx" />  
             </Services> 
                    </asp:ScriptManager>
            <div class="container">
            <div class="header">
    			<img class="top-left" src="images/top-left.gif" />
    			<div>Guardian Information Update</div>
    			<img class="top-right" src="images/top-right.gif" />
    		</div>
            <div class="content" >
            <asp:Repeater ID="GuardianRepeater"  
                runat="server">
                <HeaderTemplate>
                <table>
                </HeaderTemplate> 
                <ItemTemplate>
                    <asp:TextBox ID="Gid" CssClass="hidden" runat="server" Text='<%#Container.DataItem("GuardianID")%>'></asp:TextBox>
                    <tr>
                    <td>Surname:</td><td><asp:TextBox ID="Surname" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Surname")%>' ></asp:TextBox></td><td></td>
                    <td>First Names:</td><td><asp:TextBox ID="Firstnames" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("firstnames")%>' ></asp:TextBox></td> <td></td><td></td>
                    </tr>
                    
                    <tr>
                    <td>ID Number:</td><td><asp:TextBox ID="idnumber" runat="server" CssClass="surnametextbox"  Text='<%#Container.DataItem("IDNumber")%>' ></asp:TextBox></td> <td></td>
                    <td>Cell:</td><td><asp:TextBox ID="cellphone" runat="server" CssClass="surnametextbox"  Text='<%#Container.DataItem("cell")%>' ></asp:TextBox></td> <td></td><td></td>
                    </tr>
                    
                    <tr>
                    <td>Tel(Work):</td><td><asp:TextBox ID="telwork" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Tel_Work")%>' ></asp:TextBox></td><td><cc1:MaskedEditValidator ID="MaskedEditValidator1" ControlExtender="MaskedEditExtender1" ControlToValidate="telwork" TooltipMessage="Enter a Number in this format: (999)9999999" runat="server"></cc1:MaskedEditValidator></td>
                    <td>Tel(Home):</td><td><asp:TextBox ID="telhome" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Tel_Home")%>' ></asp:TextBox></td> <td></td><td></td>
                    </tr>
                    
                    <tr>
                    <td>Fax(Work):</td><td><asp:TextBox ID="faxwork" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Fax_Work")%>' ></asp:TextBox></td><td></td>
                    <td>Fax(Home):</td><td><asp:TextBox ID="faxhome" CssClass="surnametextbox" runat="server" Text='<%#Container.DataItem("Fax_Home")%>' ></asp:TextBox></td> <td></td>
                    </tr>
                     
                    <tr>
                    <td>Occupation:</td><td>
                        <asp:TextBox ID="occupation" CssClass="autocompletetextbox" runat="server" Text='<%#Container.DataItem("occupation")%>'></asp:TextBox></td>
                        <td><div><asp:ImageButton ID="occhelp" ImageUrl="~/Images/help-browser.png" OnClientClick="return false;" runat="server" /></div></td>
                            <td><div id="flyout" class="wireFrame"></div>
            
       <!-- Info panel to be displayed as a flyout when the button is clicked -->
       <div id="info" style="display: none; width: 250px; z-index: 2; opacity: 0; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); font-size: 12px; border: solid 1px #CCCCCC; background-color: #FFFFFF; padding: 5px;">
          <div id="btnCloseParent" style="float: right; opacity: 100; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100);">
             <asp:LinkButton id="btnClose" runat="server" 
                             OnClientClick="return false;" 
                             Text="X" ToolTip="Close"
                             Style="background-color: #666666; color: #FFFFFF; text-align: center; font-weight: bold; text-decoration: none; border: outset thin #FFFFFF; padding: 5px;" />
          </div>
          Options will come up once you begin typing. Please select an option from the list.    
        </div></td>
                    </tr>
                    
                    <tr>
                    <td>Work E-Mail:</td><td><asp:TextBox ID="email" runat="server" CssClass="emailtextbox" Text='<%#Container.DataItem("email")%>' ></asp:TextBox></td><td><asp:CheckBox ID="chkCanEmail" Checked='<%#Container.DataItem("CanEmail")%>' runat="server" />Receive E-mail Correspondence on this Address</td> 
                    </tr>
                    
                    <td>Home E-Mail:</td><td><asp:TextBox ID="HomeEmail" runat="server" CssClass="emailtextbox" Text='<%#Container.DataItem("HomeEmail")%>'></asp:TextBox></td><td><asp:CheckBox ID="chkCanEmailHome" Checked='<%#Container.DataItem("CanEmailHome")%>' runat="server" />Receive E-mail Correspondence on this Address</td><tr>
                    
                   
                    </tr>
                    
                    
                   
                     <cc1:MaskedEditExtender ID="MaskedEditExtender1" TargetControlID="telwork" Mask="(999)9999999" MessageValidatorTip="true" MaskType="Number"   ErrorTooltipEnabled="true" runat="server"  ></cc1:MaskedEditExtender> 
                     <cc1:MaskedEditExtender ID="MaskedEditExtender2" TargetControlID="telhome" Mask="(999)9999999" MessageValidatorTip="true" MaskType="Number" ErrorTooltipEnabled="true" runat="server"></cc1:MaskedEditExtender>         
                    
                    <cc1:AutoCompleteExtender ID="OccAutoCompleteExtender" TargetControlID="occupation" ServicePath="ClService.asmx" ServiceMethod="GetOccupations" MinimumPrefixLength="2" CompletionInterval="1000" OnClientItemSelected="IAmSelected" 
                     CompletionListCssClass="autocomplete_list" CompletionListItemCssClass="autocomplete_listItem" CompletionListHighlightedItemCssClass="autocomplete_highlighted_listitem" runat="server">
                    </cc1:AutoCompleteExtender>
                    
                    <asp:HiddenField ID="hdntest"  runat="server" />
                      
    
                   <%-- <asp:RequiredFieldValidator ID="RfEmail" ControlToValidate="email" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>--%>
                    <asp:RegularExpressionValidator ID="RevEmail" ControlToValidate="email" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" runat="server" ErrorMessage="*Email must be in the format of [email protected]" Display="Dynamic" ></asp:RegularExpressionValidator>
                </ItemTemplate> 
                <SeparatorTemplate>
                <tr>
                <td colspan="6" >
                <hr />
                </td>
                </tr>
                </SeparatorTemplate> 
                
                <FooterTemplate>
                </table> 
                </FooterTemplate> 
            </asp:Repeater>
             <div >
            <asp:Button ID="btnSave" runat="server" Text="Save" onclick="SaveInfo"/>
            </div>
            </div>
            
            
    <div class="footer">
    			<img class="top-left" src="images/bottom-left.gif" />
    			<img class="top-right" src="images/bottom-right.gif" />
    		</div>
    		</div>
        
    		
    </asp:Content>

  33. #33
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Ok, try this:

    Code:
    GuardianRepeater.FindControl("hdntest")
    Make sure that this actually returns something, i.e:

    Code:
    Dim myControl As Control = GuardianRepeater.FindControl("hdntest")
    Does this work?

    If it does, Cast the Control as type HiddenField, and then grab the ClientID from there.

    Gary

  34. #34

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    ok thanks. we are getting somewhere now.

    I tried this:
    Code:
    Dim itema As RepeaterItem
    
    
     If Not (ClientScript.IsClientScriptBlockRegistered("MyScript")) Then
                    For Each itema In GuardianRepeater.Items
    
                        ClientScript.RegisterClientScriptBlock(Me.GetType, "MyScript", "function IAmSelected( source, eventArgs ) { document.getElementById('" & itema.FindControl("hdntest").ClientID & "').value = eventArgs.get_value();alert(document.getElementById('" & itema.FindControl("hdntest").ClientID & "').value); }", True)
                    Next
                End If
    not sure if this is correct to add the script multiple times though. I get the alert with the value when I select an item.

    but when I loop through the repeater items to save, i only get the value of the first hiddenfield.

    Code:
     For Each item In GuardianRepeater.Items
    
                    Using con As New MySqlConnection(strConn)
        
                        Dim OccId As String = ""
    
                        'get fields to update
                        OccId = CType(item.FindControl("hdntest"), HiddenField).Value
    Last edited by Nitesh; Aug 14th, 2009 at 05:56 AM. Reason: changes

  35. #35

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    please help me someone

  36. #36
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Going back to post 12 for a moment.

    When the user fills in a textbox using autocomplete and fills out the rest of the form, then clicks submit - can't you just read straight from the textbox inside the repeater?

    It's as if the user were typing normally (which is what they're doing anyways, you're only providing a visual cue). User clicks submit, you loop through the repeater, get each occupation textbox, read the value. I see no reason for the javascript.

  37. #37

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Hi mendhank,

    I can get the textbox text like this:

    Code:
    OccId = CType(item.FindControl("occupation"), TextBox).Text
    but how do I get the value

  38. #38
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    Okay, so now I am completely lost

    What is the Value that you speak of?!? Is it the value in the HiddenField? If so, then you would use exactly the same technique.

    Gary

  39. #39

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    hi gary,

    when i return a string array for the autocomplete i do this:

    Code:
                        OccList.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(OccReader.GetString(1), OccReader.GetUInt32(0)))
    i need a way to get that value. I can get it in javascript as i've posted in above posts. But that causes issues. using your suggestion, how can i assign values to the hiddenfields, considering there are 2 or more hiddenfields on tha page

  40. #40

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to Use Ajaxcontroltoolki autocomplete with database data

    please help me find a solution someone. I've searched and searched the web and still haven't found anything

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width