Popup and .Net (Update)


Regarding my post on my issue with client side scripting and .Net, Jesse help me a lot on the subject. I still have to test his answer but this is what he suggest:

a better handler in the popup would look like this:

void MySubmitButton_Click(object sender, EventArgs e)
{
// Do Some Processing

Page.RegisterStartupScript("__close", String.Format("<script>window.opener.{0}({1},{2}); window.close();</script>", Request["Handler"], Request["ControlID"], someValue));
}

So, what happens is a user clicks a button in your popup (for example, a "Save" button). You do some processing on the data, like saving it to a database. After you have done this, you send a javascript to the browser that fires calls a function on the parent window, and then closes the popup. The function on the parent window is responsible for making sure that the page refreshes. There are a million ways to do this. You could just use DOM with DHTML to update the page automatically, without a refresh. Or, you could use the __doPostBack function to initiate a postback event. Or, you could do something like "window.location = window.location". To simulate a page refresh. Personally, I like using DHTML to dynamically update the page best, but some times that is not an option and firing a custom __doPostBack event is best for those cases.

The only comment I would like to add is that I don't have any button in the popup window. I have no idea if and when the user will close the window, so I will probably include the code on a on load event (Javascript).
I will try this code and let you know if it's working. I'm sure it is, coming from Jesse, it surely is ;-)
Any comments?

3 Comments

  • my only concern would be that doing anything via querystring drops the security level down a bit. This can be overcome, of course.

  • Putting the name of a javascript function that a person could view source on your files to find and merely causes a page refresh is hardly dropping security down a level.





    I think I might have misunderstood a little bit though, looking back on your comments, the vote is taking place in the main window, not the popup, right? If this is the case, the problem you see is that the child window launches, then the results are saved. So, that is an even easier fix. Instead of having an &quot;onClick&quot; attribute on your vote button that opens the window, just add a Page.RegisterStartupScript directive with the window opening script to the end of your server side event that saves the results to the DB. What will happen then is that the page will post back, save the results, then popup the window.





    Or maybe I had it right the first time... One of these two should fix the problem, depending on what exactly you are trying to do.

  • Jesse I think you're right. The second solution seems to be the one I was looking for.


    I forgot that I can generate the server side script after saving the data. I am going to try that.

Comments have been disabled for this content.