Popup and .Net
Did you ever played with popup windows with .Net ?
Well I did and this is my not so successful experience.
OK, here is the scenario:
- One master page with different controls. The one I am going to talk about is a Poll control, you know where you ask the user an opinion on something and when he click on Vote, you show the results for every question.
- Due to design requirements, the result page must be render in a popup window.
The Poll results window is not really the issue here, it's just reading the data and create few bar charts to show the pecentage of votes.
To open a popup window from a click on the vote button, I attached an attribute from my code, to open the window.
The idea is that I need also to save the vote by incrementing the right field in the database.
What I discovered very quickly, is that the window open before the event is fired.
So indeed the vote is not save and the results show the wrong value.
This is what solutions I tried before the last one which I reckon is far to be perfect, but it works.
- View state is of course not an option here because I go to a separate window, so I tried to pass to a querystring the value the user click.
No success, the window opened and the querystring was not there. - Using Session object, I was thinking that this will let me keeping the value, having the window open, read the Session object, and record the Vote from the popup before displaying the Results.
No because .Net is probably too fast ! No seriously what's seem to happen is that the Session object is created from the main page after the popup open. At this stage I was really startting to give up. - Final assault on the code, and what I did is quite simple. I add to my datatable a new field, kind of flage.
I store the Vote from the Main page, and of course the client side script open the window before the SaveThisVote subroutine start.
But when I save the vote I set the boolean flag to True, and in my popup code, I execute a loop with Response.redirect until I have a flag set to True.
It works fine on my local machine, but I don't think its' the right thing to do. I am worrying that the wp process freeze, because what I am doing there is indeed a very unmanaged thread.
The other option I am working on is to see if I can modify programmatically the attribute I link to the Vote button.
Doing this I hope to be able to include the querystring I need for the vote.
I should probably doing that from a simple client side script link to each radio buttons.