Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i've a "SearchText" Textbox in master page. I used the Script code for search suggestion
my code is
JavaScript
<script type="text/javascript">
            $(document).ready(function () {

                $('#<%=SearchText.ClientID%>').autocomplete({
                    source: function (request, response) {
                        $.ajax({
                            url: "SearchSuggestions.asmx/GetSuggestions",
                            data: "{ 'searchValue': '" + request.term + "' }",
                            type: "POST",
                            dataType: "json",
                            contentType: "application/json;charset=utf-8",
                            success: function (result) {
                                response(result.d);
                            },
                            error: function (result) {
                                alert('There is a problem processing your request');
                            }

                        });
                    }
                });
            });

it works fine on Default.aspx. but on other content pages this code does not seems working.
Posted
Comments
ganesh_kanc 13-Dec-14 10:06am    
where is the script code (master page or content page)? when you are working with that text box from the content page try to debug the script the code by using firebug. Then you can find why the code is not working. May be the text box not finding from the content page or its return null value. When you try to debug the code from firebug at least you will come to know whether the script code is calling from content page. If your code works fine in master page that should work perfectly in content page also.

1 solution

change
HTML
'#<%=SearchText.ClientID%>'

to
HTML
'#<%=((TextBox)Master.FindControl("SearchText")).ClientID %>'

also check below tip for alternative approach of finding control on master page from content pages
Finding Controls in a Master Page with jQuery[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900