Arikkan
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.RegisterStar tupScript( )" 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?
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
Now it does " ScriptManager.RegisterStar
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
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.
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.
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,stat us=yes,too lbar=no,me nubar=no,l ocation=no ,scrollbar s=yes,resi zable=yes, titlebar=n o');
}
</script>
and used this code at backend:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -
-- Try 1
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -
Protected Sub tvwAccountDetails_Selected NodeChange d(ByVal sender As Object, ByVal e As System.EventArgs) Handles tvwAccountDetails.Selected NodeChange d
Dim url As String = "http://www.google.com"
Dim winFeatures As String = "toolbar=no,status=no,menu bar=no,loc ation=cent er,scrollb ars=yes,re sizable=no ,height=65 0,width=82 5"
ScriptManager.RegisterStar tupScript(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_Selected NodeChange d(ByVal sender As Object, ByVal e As System.EventArgs) Handles tvwAccountDetails.Selected NodeChange d
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.RegisterStar tupScript( Me, GetType(String), "WINDOW_OPEN", sb.ToString(), True)
End Sub
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -
None of these worked :-(
<script type="text/javascript" language="javascript">
function openpopup(url)
{
window.open(url, '_blank', 'height=500,width=800,stat
}
</script>
and used this code at backend:
--------------------------
-- Try 1
--------------------------
Protected Sub tvwAccountDetails_Selected
Dim url As String = "http://www.google.com"
Dim winFeatures As String = "toolbar=no,status=no,menu
ScriptManager.RegisterStar
End Sub
--------------------------
--------------------------
-- Try 2
--------------------------
Protected Sub tvwAccountDetails_Selected
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.RegisterStar
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+
Let me know if any of those work for you.
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>
Let me know if any of those work for you.
ASKER
ok. Let me try.
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_Selected NodeChange d(ByVal sender As Object, ByVal e As System.EventArgs)
....
....
End Sub
Any way to solve this?
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_Selected
....
....
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>
something like:
<script type="text/javascript">
//change to do your popup here.
function clientClick(theParam) {
window.Navigate('page.aspx
}
</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>
ASKER
ok. I will try it.
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.
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:
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.
}
ASKER
:-)
I ended up doing the same yesterday.
I passed the values in the Query string and moved the code to the reports page.
I ended up doing the same yesterday.
I passed the values in the Query string and moved the code to the reports page.
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.Selected Node.Value
Dim ValuePath As String = tvwAccountDetails.Selected Node.Value Path
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
ASPX page
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
<asp:TreeView ID="tvwAccountDetails" runat="server" OnTreeNodePopulate="tvwAcc ountDetail s_TreeNode Populate" EnableClientScript="true" PopulateNodesFromClient="t rue" OnClick="openReport(this); ">
<Nodes>
<asp:TreeNode Text="Account History" SelectAction="Expand" PopulateOnDemand="true"></ asp:TreeNo de>
</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/FormationRepor tsViewer.a spx?Report Id=" + ReportId + "&ValuePath=" + ValuePath + "&";
window.open(url);
}
</script>
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.Selected
Dim ValuePath As String = tvwAccountDetails.Selected
--------------------------
ASPX page
--------------------------
<asp:TreeView ID="tvwAccountDetails" runat="server" OnTreeNodePopulate="tvwAcc
<Nodes>
<asp:TreeNode Text="Account History" SelectAction="Expand" PopulateOnDemand="true"></
</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/FormationRepor
window.open(url);
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.