Link to home
Start Free TrialLog in
Avatar of Arikkan
ArikkanFlag for United States of America

asked on

Popup Blocker issue in <Asp:Treeview....>

I am working on a solution where I have an element <Asp:Treeview....>

Now it does " ScriptManager.RegisterStartupScript()" at the back end when the Child node is selected for opening a new window. Even though this is a Client click (Direct User Action), the Popup window is still blocked. What am I missing here?

User generated image
I have a sample solution created for you as well.

View all files for Question ID: 28630908
https://filedb.experts-exchange.com/incoming/ee-stuff/8409-BypassPopupBlocker.zip

Direct link to your file
https://filedb.experts-exchange.com/incoming/ee-stuff/8409-BypassPopupBlocker.zip
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Silly question first . . . do you have a popup blocker on?  You can test this by holding down the Ctrl key and then clicking the button.  If that goes through then you have a popup blocker on.  

It doesn't matter whether it's a client click or not, the popup blocker will block any popup unless told not to do so for a site.
Avatar of Arikkan

ASKER

You know that is the issue. My company wants me to show the window even if the popup blocker is on.

Now as you can see (In my attached solution) that for the Button click, the popup opens even if popup blocker is ON.
I want the same functionality for the Treeview links.
Avatar of Arikkan

ASKER

I created a javascript function at front end:

    <script type="text/javascript" language="javascript">
        function openpopup(url)
        {
            window.open(url, '_blank', 'height=500,width=800,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,titlebar=no');
        }    
    </script>


and used this code at backend:
---------------------------------------------------------------------------------------------------------------------------------------------------
-- Try 1
---------------------------------------------------------------------------------------------------------------------------------------------------
   Protected Sub tvwAccountDetails_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tvwAccountDetails.SelectedNodeChanged
 
       Dim url As String = "http://www.google.com"
        Dim winFeatures As String = "toolbar=no,status=no,menubar=no,location=center,scrollbars=yes,resizable=no,height=650,width=825"
        ScriptManager.RegisterStartupScript(Me, GetType(String), "WINDOW_OPEN", String.Format("<script type='text/javascript'>var popup=window.open('{0}', 'yourWin', '{1}'); </script>", url, winFeatures), True)
    End Sub
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------
-- Try 2
---------------------------------------------------------------------------------------------------------------------------------------------------
  Protected Sub tvwAccountDetails_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tvwAccountDetails.SelectedNodeChanged
        Dim sb As StringBuilder = New StringBuilder()
        sb.Append("<script language='javascript' type='text/javascript'> ")
        sb.Append("openpopup('" + "http://www.google.com" + "')")
        sb.Append("</script>")

        ScriptManager.RegisterStartupScript(Me, GetType(String), "WINDOW_OPEN", sb.ToString(), True)
    End Sub
---------------------------------------------------------------------------------------------------------------------------------------------------

None of these worked :-(
This will work if you change the internet security zone.  You can use active directory to publish the change or try adding it to a trusted site.  I'm not positive but I *think* it would also work with the local intranet settings (again, based on the settings in the browser).

The whole point of a popup blocker is to block popups.  The only way to get around that is to make it known that you are "special" (eg: in a different zone) then the rest of the internet.  Otherwise we'd be back to the popup ads.

I'm assuming that this is for a local intranet site.

Even the user clicked the link . . . you're doing a postback which is then transferred to the server for control, so it's actually the server running the javascript.

If all you're trying to do is do a popup then you can use the onlick event on the treeview.
From: http://forums.asp.net/t/1557293.aspx?How+to+give+javascript+onclick+event+to+an+aspdotnet+treeview+parent+node+even+it+has+server+side+event+

<asp:TreeView ID="TreeView2" runat="server" ShowLines="true" onclick="clientClick();">
            <Nodes>
                <asp:TreeNode Text="123" Value="123" Selected="true" />
                <asp:TreeNode Text="qwe" Value="qwe" />
                <asp:TreeNode Text="asd" Value="asd" />
                <asp:TreeNode Text="zxc" Value="zxc" />
            </Nodes>
        </asp:TreeView>


        <script type="text/javascript">
            //change to do your popup here.
            function clientClick() {
                alert("client side clicked.");
            }


        </script>

Open in new window


Let me know if any of those work for you.
Avatar of Arikkan

ASKER

ok. Let me try.
Avatar of Arikkan

ASKER

ok sir.

So the "OnClick()" attribute seems to work even in case of popup blocker enabled.
But it will be a partial solution for me.
As this will set the same URL for the Entire <asp:TreeView....>

But, I need to open a different link for each of the <asp:Treeview...>   Nodes that I click. The value is read from the Node.
I definitely need to add something on the backend in the function:


 Protected Sub tvwAccountDetails_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs)
....
....
End Sub


Any way to solve this?
you can added a databinding to it with a parameter in your function:

something like:

 <script type="text/javascript">
            //change to do your popup here.
            function clientClick(theParam) {
               window.Navigate('page.aspx?Param=' + theParam );
            }
        </script>

<asp:TreeView ID="TreeView2" runat="server" ShowLines="true" onclick='clientClick(<%# Eval("MyDBFieldinDataTable") %>);'>
            <Nodes>
                <asp:TreeNode Text="123" Value="123" Selected="true" />
                <asp:TreeNode Text="qwe" Value="qwe" />
                <asp:TreeNode Text="asd" Value="asd" />
                <asp:TreeNode Text="zxc" Value="zxc" />
            </Nodes>
        </asp:TreeView>
Avatar of Arikkan

ASKER

ok. I will try it.
Avatar of Arikkan

ASKER

Out site has code to set session and other variables before the popup (Report) is opened.
But "Onclick" will do a client click and then server side code (set session and other variables ) will be run, giving me a blank form.

So this would not help me.

Also the Main page is using a user control with the Treeview in it.
That code can be moved to the report page.

You can only hold one value for the node itself . . . so presumably you're doing some kind of lookup, setting values in the session, and then redirecting to the form.

Instead, pass the value as described above in javascript, redirect to the page using your query string, redirect to the report page, and then in your report.aspx:
if (!Page.IsPostBack)
{
   //get the query string variable first, set your session variables the same way you did in the user control, and then continue on with the code.
}

Open in new window

Avatar of Arikkan

ASKER

:-)

I ended up doing the same yesterday.
I passed the values in the Query string and moved the code to the reports page.
Avatar of Arikkan

ASKER

Can you help me with few more things?

1. I want to check if the current node is a Child Node (With Value) and not an expandable node.
2. I want to pass only the selected node in the event "OnClick" on ASPX page.

Currently I hardcoded the ReportID and ValuePath variables to see if it is working.
But I need to get this from the Selected ChildNodes.

Can you guide me?


--------------------------------------------------------------------------------------------------------------------------------------------
Original Code behind - Values used in Session
--------------------------------------------------------------------------------------------------------------------------------------------
 Dim ReportId As String = tvwAccountDetails.SelectedNode.Value
 Dim ValuePath As String = tvwAccountDetails.SelectedNode.ValuePath


--------------------------------------------------------------------------------------------------------------------------------------------
ASPX page
--------------------------------------------------------------------------------------------------------------------------------------------
<asp:TreeView ID="tvwAccountDetails" runat="server" OnTreeNodePopulate="tvwAccountDetails_TreeNodePopulate" EnableClientScript="true" PopulateNodesFromClient="true" OnClick="openReport(this);">
    <Nodes>
        <asp:TreeNode Text="Account History" SelectAction="Expand" PopulateOnDemand="true"></asp:TreeNode>
    </Nodes>
</asp:TreeView>


--------------------------------------------------------------------------------------------------------------------------------------------
Javascript
--------------------------------------------------------------------------------------------------------------------------------------------
   <script language="javascript" type="text/javascript">
        function openReport(param) {
            debugger;
            if (param == undefined) { return; }
            if (param.childNodes == undefined) { return; }
            //if (param.childNodes.length > 0) {return;}
            ReportId = "600001316";
            ValuePath = "Account History/600001316";
            url = "../Reports/FormationReportsViewer.aspx?ReportId=" + ReportId + "&ValuePath=" + ValuePath + "&";
            window.open(url);
        }
    </script>
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial