Why does my user control pageLoad function not fire on some of my ASP.net pages?
I'm working on an ASP.net application.
I had a problem with a user control I'd designed called LocationSelector
. It worked great, but I couldn't use it within an ASP:UpdatePanel. I learned, by browsing SO, that I needed to put my in-line javascript in an external file and register it with ScriptManager
so that there are no Response.Write
calls in the Javascript.
Next, I discovered that the control worked at first, but when I enclosed it within the ASP:UpdatePanel, it would stop functioning after the first AJAX postback. I read that to fix that, I开发者_C百科 needed to replace my $(document).ready
call with function pageLoad()
which is automatically executed with each ASP.net page load.
Several of my pages in my ASP.net application work fine (and I was really impressed with how well the framework seemed to drive the application). However, to my dismay, I discovered that my LocationSelector
control no longer works at all on three of my pages. The HTML renders, but the pageLoad (which uses jQuery to bind events on control elements) does not fire.
I verified this but putting alert('pageLoad');
as the first line of my pageLoad
function. On the pages that work, I see the alert. On the pages that don't work, I never see the alert, even on the initial page load.
What kind of problem could be causing the pageLoad
function on my user control LocationSelector
to execute on some pages, but not others?
I've found the problem, but I still don't know what the solution is.
My user control Location Selector
is in the relative directory ~/Controls
. I register the scripts using the following code:
ScriptManager.RegisterClientScriptInclude(this, typeof(LocationSelector), Guid.NewGuid().ToString(), "Controls/LocationSelector.js");
The problem is with the relative path to the JavaScript file Controls/LocationSelector.js.
The pages that work with this code are all in the root directory of the ASP.net application. The pages that don't work are in subdirectories.
精彩评论