I'm in a fix with JQuery and ASP.Net!
This is my script code. I have used autocomplete to list names of courses from a database. I have a web form named Courses.aspx which has a master page.

<link rel="stylesheet" href="css/jquery-ui.css" />

    <script src="js/jquery-1.8.3.js" type="text/javascript" language="javascript"></script>

    <script src="js/jquery-ui.js" type="text/javascript" language="javascript"></script>

    <script type="text/javascript" language="javascript">
        function LoadList() {
            var ds = null;
            ds = <%=listFilter %>
            source: ds

Now the problem:
If I don't add the master page, the autocomplete works like a charm.
But it doesn't work with a master page.
The main reason (I think) is that I'm unable to to load the function LoadList() on the body tag. So I used other methods like window.onload=function
and I even made a user control so I can easily add the body tag which i can't generally in a master page.

Please help me find a solution.

3 Years
Discussion Span
Last Post by momal

First, consider being patient as this isnt a live session.

With regards to your issue, keep in mind that asp.net is server side and jQuery is client side. When your browser attempts to execute the javascript on the page, it has no idea that the markup and code its looking at was generated by asp.net.

Because you have a master page, it could be that you have your scripts being rendered on a portion of the page that you arent expecting and the functions are not ready to be run.

You can start by opening the page with your browser, right click view source, inspect the HTML that is rendered. Also, use your browser's javascript console to see if any client side errors are being reported.


First, I'm sorry for not being patient.

Secondly, I tried what you said and it gave only this warning which I googled and found that it isn't actually a problem.

event.returnValue is deprecated. Please use the standard event.preventDefault() instead.

Thirdly, I tried puting the script inside the ContentPlaceHolder and put an alert in that function just to check, and that fires the script, the alert pops up but the autocomplete doesn't.


Ok, the event.returnValue deprecated is fine. dont worry about that.

one other thing you should check is that you are referring to the element by ID: $("#txtName3"). I suspect that if you view source and search for that ID, you wont find it. ASP.NET will render its own dynamic ID for controls.

If you want to make sure that the ID is "static", you need to add the ClientIDMode property to the textbox control.

for example.. <asp:TextBox ID="txtName3" ClientIDMode="Static" ... />

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.