avoid popup blockers via an input button instead of a asp button

Even though some people disagree, there are certain occasions where popups are the way to go, at least that is my opinion. On that note I need help with the following problem.

I found that if I use an input button (not an asp button) with an attached onclick javascript function to “window.open” a page in a new window, most popup blockers will allow the page to open. That includes IE, Safari, Chrome, FireFox. On the other hand  Opera will advise that a pop was blocked which is good enough.

This is the problem, if I pass a URL as a string to the window.open function in javascript, it will work but I need to procees in codebehind the selections made via checkboxes and create the string on demand. To get the function in codebehind to work I create a  __doPostBack to the specific function and transfer the string that results from the selection to a hidden variable on the aspx to be able to access the info on javascript and feed it to the window.open function.
The result from the codebehind processing works but does not get back to the javascript on time. If I press the button again then it does work. So basically I end up with two new windows, one bad and one good.

If there is a different solution that will give me the same results I will accept that. Please, if posible provide the solution in vb.net.
Thank  you for your help.

aspx
====
<head>
<script type="text/javascript" language ="javascript" >
function myPopup() 
{
  var jsVar ='';  
  __doPostBack('GetMapURL', jsVar);
  var jsVar2 = document.form1.hiddenURL.value; 
  /*also tried jsVar2 = '<%=mapcoordinate%>'; by placing the info on a public variable */
 /*in both cases only after hitting the button for a second time does jsVar2 fillup*/
  var jsVar1 = 'http:\/\/www.bing.com/maps/?v=';
  window.open(jsVar+jsVar2.toString());
}

</script>
</head>
<body>

<asp:HiddenField ID="hiddenURL"  runat="server"  />

<asp checkbox> many of them

<input id="getmapbutton" type="button" onclick="myPopup()" value="POP!"/>

Codebehind
==========
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  If IsPostBack Then
    Me.ClientScript.GetPostBackEventReference(Me, "arg")
    Dim eventTarget As String = Me.Request("__EVENTTARGET")
    Dim eventArgument As String = Me.Request("__EVENTARGUMENT")
    If eventTarget <> String.Empty AndAlso eventTarget = "GetMapURL" Then
       GetMapFunction()
    End If
  End If

'continues the processing

'in the same file
Public Sub GetMapFunction()
'processing
   hiddenURL.Value = .....
End Sub

Open in new window

IvicarpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IvicarpAuthor Commented:
In the java script it reads
window.open(jsVar+jsVar2.toString());

it should read
window.open(jsVar1+jsVar2.toString());
sorry
0
rajapandian_81Commented:
From my understanding you like to open popup based on some server side calculation.

To open popup you can use below server side code.

Dim strURL As String
strURL = "URL HERE"

Page.ClientScript.RegisterStartupScript(Page.GetType(), "popup", "<script language=JavaScript>window.open('" + strURL + "');</script>")

Open in new window

0
IvicarpAuthor Commented:
Rajapandian 81: Yes, you are correct with your statement but the solution proposed gets blocked, now also IE and firefox show a message but Chrome and Safari dont even say anything and just refresh the page.
I have tried a lot of things, what apparently work is when the window.open is called by a ref or input button as javascript in the aspx file (client processing) if you refence it or any other way or place, that I found so far, it gets blocked.
The problem the way I see it is that the __doPostBack('GetMapURL', jsVar); gets the process started in the code behind but does not wait to get the codebehind finished to move to the next line in the javascript. (which makes sense) and that is why probably I need to press the button twice and end up getting two windows.
Is there a way from the input button (not aspx button) to start via client javascript a function in code behind that after processing the checkboxes will return a value which I can then feed it to the window.open in the client script?
I may have changed the question, I apologize if I did that, but the interaction is what makes me make better questions.
Thanks again
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

rajapandian_81Commented:
May I know what type of calculation you are donig in server side.

You can do everything in client side. If you want to connect databse you can use XMLHTTP.
0
IvicarpAuthor Commented:
rajapandian 81: I verify 4 checkboxes, if marked any of them, I take the associated string to each checkbox plus a string from a textbox and create a url that includes a set of addresses to get a bing.com/maps. Theoretically I could probably verify the checkboxes on the client side and get the string from the textbox and do the creation of the final string on the client side with javascript and then call window.open. Making sure I never have a postback. Currently I have the creation of the string in code behind. As soon as I have somewhere a postback the window.open gets blocked by the popup blocker which I want to avoid. Safari does not even warn that your window is been blocked. The user has no idea of what is going on. A real pain.
0
rajapandian_81Commented:
Ivicarp:

To get TextBox value:
---------------------------
var txtValue = document.getElementById('<%= TextBox1.ClientID %>').value;

To get CheckBox text:
----------------------------
var chkboxValue;
var chkbox = document.getElementById('<%= CheckBox1.ClientID %>');
var lbl = chkbox.nextSibling;
while(lbl.nodeName.toLowerCase()!='label')  
       lbl = lbl.nextSibling;
chkboxValue = lbl.innerHTML;

To check CheckBox checked or not (return true false):
--------------------------------------------------------------------
var chkbox = document.getElementById('<%= CheckBox1.ClientID %>');
var chkboxchecked = chkbox.checked;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IvicarpAuthor Commented:
rajapandian 81:
Yup, i had to convert the entire function to client side javascript but it works the way I wanted.
Thanks for your patience and help.
0
rajapandian_81Commented:
Glad to help. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.