giovedì 13 marzo 2008

Fix for PostBack not working in Custom ASP.Net filebrowser

My custom filebrowser's postbacks were not working, the auto-generated JavaScript function __doPostBack was complaining that theForm was undefined. I tried many ways but settled with this:

Put the following code in the PreRender event of the custom filebrowsers page:

Me.ClientScript.RegisterClientScriptBlock(Me.GetType, "__doPostBack", _
"function __doPostBack(eventTarget, eventArgument) { " & _
" theForm = document.forms[0]; " & _
" if (!theForm.onsubmit (theForm.onsubmit() != false)) { " & _
" theForm.__EVENTTARGET.value = eventTarget; " & _
" theForm.__EVENTARGUMENT.value = eventArgument; " & _
" theForm.submit(); " & _
" } " & _
"} " _ , True

This line is the work-around: " theForm = document.forms[0]; " & _

Nessun commento: