Sunday, March 11, 2012

Is it possible to force the container page to postback from within an updatepanel?

Could you share more details of what you're trying to do? I would expect this to work. If you set a breakpoint on OnSelect(), does it not get hit at all?


Hi,

To try to clarify what I'm doing a bit more - I've got a File Manager user control that is being used in a couple of places in my Cms application. It is used to add/edit/delete files and folders on the file system.

It works well but introducing an updatepanel wrapping it has created all sorts of problems.

I added a breakpoint on OnSelect and it did indeed get hit. The OnSelect event handler calls SelectFile (below) which I've also confirmed with a breakpoint. It seems that the clientscript isn't getting registered (an alert box with 'hello world' isn't appearing).

privatevoid SelectFile(string strPath)
{
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the client script is already registered.
if (!cs.IsClientScriptBlockRegistered(cstype, csSelectFile))
{
StringBuilder sbJs =newStringBuilder();
sbJs.Append("<script type=\"text/javascript\">");
sbJs.Append("alert('hello world');");
sbJs.Append("</script>");
cs.RegisterClientScriptBlock(cstype, csSelectFile, sbJs.ToString(),false);
}
}

It would be interesting to figure out the solution, but unfortunately I think I might have to forget about using an updatepanel because I've noticed another more serious problem. It seems like whenever I use the FileManager to delete a folder it corrupts the viewstate somehow and I get errors like "Validation of viewstate Mac failed". The only difference between using the FileManager to rename a file/folder and deleting one is that deleting seems to take quite a bit longer - perhaps this is somehow causing the viewstate corruption?

Anyway it would be useful to know why the ClientScript isn't working for future reference!

Cheers,

Ed


For the script block, you need to use ScriptManager.RegisterClientScriptBlock(...) instead.

Not sure about your viewstate corruption problem. :-(


Cool the ScriptManager did the trick.

I figured out what was causing those viewstate errors. A custom menu control I was using must have been hogging the viewstate. I disabled statefulness for the menu so it was dynamically generated every time the page loads and now I'm not getting any weird errors. For some reason this only became a problem when on the same page as an updatepanel (it's on plenty of other pages where the viewstate is heavily used).

Oh well - thanks for your help!

No comments:

Post a Comment