Help with RegisterPostBackControl

I have the code shown below.  This was suggested, and works, as a may to prevent an error message I was getting after doing a Response.WriteFile as a result of clicking the btnExcelExport.   However, this code is causing me another issue.  This code is on a main page which has an Add button that invokes javascript to display a modal popup.   If I cancel out of the modal popup, which is done using the bit of javascript shown below, some of the data that was displayed on my main page disappears.    Now, I was under the impression that the javascript "cancel" code I have below would only close the Add modal popup, and not impact the underlying main page.  However, Page.Init does get called.

So, two questions - 1) When the user clicks cancel on the modal popup, is there code I can add so that  Page.Init on the underlying page is not called?   2)  Why does RegisterPostBackControl cause other data on the page to disappear?  

Public Sub Page_Init() Handles Me.Init

      Dim sm As ScriptManager
      sm = CType(FindControlRecursively("ScriptManager1"), ScriptManager)

End Sub

function cancel() {
      window.returnValue = "cancel";
      return false;
Who is Participating?
HLRosenbergerConnect With a Mentor Author Commented:
I moved the code to Page.Load and this fixed the problem.
What is 'Cancel' button? Server control or html input?
HLRosenbergerAuthor Commented:
fixed the problem.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.