Question

I'm using a control from my company's shared User Control library that implements an AutoCompleteExtender.

I have placed this control inside an update panel.

The problem I am having is that the "OnClientItemSelected" property of the AutoCompleteExtender is being set dynamically on the initial page load. At this point the property sets without a problem as the dynamic code in the codebehind is executed in an if(!IsPostback) wrapper.

After a partial postback the autocompleteextender "forgets" what to do on an "OnClientItemSelected" event and stops working.

If I hard code one of the two options for which jScript function to execute OnClientItemSelected it does work, superficially but the ScriptResource.axd keeps chucking errors about invalid arguments, I assume because I'm trying to wire up something the page thinks is already wired up, even though it's not.

Either way if I force the setting of the OnClientItemSelected to happen regardless of whether there's a postback or not the control does work but the silent dropping of javascript errors is both ugly and worrying. Also I don't want to "break" a shared control if I can possibly avoid it.

So, how do I get the ScriptResource.axd to play nice with the autocompleteextender rebinding its OnClientClick on every partial postback?

Était-ce utile?

La solution

It turned out that the rebinding code just needed to go further down in the page_load. I discovered this whilst explaining the problem to one of my colleagues. He asked to see the error and got me to cut and paste the code out of the if(!IsPostback) wrapper like I had on Friday. I did this, but on Friday I moved the code up before the wrapper. He just pointed underneath the wrapper and, without thinking about it, I pasted it below the wrapper. The code then worked consistently with no errors.

Just goes to show... a problem shared is sometimes a problem resolved...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top