Solved

Pass The Value as a query string held in a session variable

Posted on 2006-07-07
9
388 Views
Last Modified: 2008-03-06
I'm trying to open a popUp window by using a hyperlink control

<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="Javascript:var w=window.open('ContactDetails.aspx?ContactID=' + <%= Session[NotifierID] %> + ','','width=980,height=660,resizable=yes');"> Details...</asp:HyperLink>


However instead of ContactID having a value of Session[NotifierID] it is being passed literally as a string ContactID="<%= Session[NotifierID] %>  "

meaning
instead of being passed a value ContactID='8138'
its being passed as ContactID="<%= Session[NotifierID] %>  "

Could you tell me what i'm doing wrong here

Collin
0
Comment
Question by:Collindsouza
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 7

Expert Comment

by:kGenius
ID: 17058441
try Session["NotifierID"]
0
 
LVL 7

Expert Comment

by:kGenius
ID: 17058444
sorry try: ContactID='<%= Session[NotifierID] %>'
0
 
LVL 5

Author Comment

by:Collindsouza
ID: 17058496
i tied ContactID='<%= Session[NotifierID] %>'

it doesnt work..

it still passes the value of contact id as ContactID=<%= Session[NotifierID] %>  
in my query string :((
0
 
LVL 1

Expert Comment

by:sguerra
ID: 17058506
Well the thing is that the <%  %> asp tags dont work with .net in aspx pages.
To do what you want (since you are using sessions) its better to use a call to the server using a "LinkButton" instead, then on the link's button "click" event you place something like this:

    Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
            Dim popWindow As String
            popWindow = " <script language='javascript'> "
            popWindow += " url = 'ContactDetails.aspx?ContactID="+Session("NotifierID")+"'; "
            popWindow += " newWindow = window.open(url,'WINDETAILS', 'width=980,height=660,resizable=yes,left=0,top=0'); "
            popWindow += " if (window.focus) {newWindow.focus()} "
            popWindow += " </script> "
            Page.RegisterStartupScript("PopupScript", popWindow)
    End Sub


0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 7

Expert Comment

by:kGenius
ID: 17058509
Again my excuses:
Try:
asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="Javascript:var w=window.open('ContactDetails.aspx?ContactID=' + <%= Session["NotifierID]" %> + ','','width=980,height=660,resizable=yes');"> Details...</asp:HyperLink>
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 17058519
Its not recommended to set the URL this way. Instead, set the URL parameters from code behind:

.ASPX.VB
-------------
Me.HyperLink2.Attributes.Add("target","_new")
Me.HyperLink2.NavigateURL = "'ContactDetails.aspx?ContactID=" &  Session[NotifierID]

-Nauman.
0
 
LVL 5

Author Comment

by:Collindsouza
ID: 17058597
Thanks nauman,

Your a true Ledgend....
0
 
LVL 5

Author Comment

by:Collindsouza
ID: 17058605
ok tell me.. in the same Attributes.Add how can i set the other properties like 'width=980,height=660,resizable=yes'
0
 
LVL 25

Accepted Solution

by:
nauman_ahmed earned 500 total points
ID: 17058766
The best approach is to write the JavaScript function in ASPX to open the window like the following. Benefit is you have more control over the function:

.ASPX
---------
<script language="javascript">
function OpenContactDetails(ContactID)
{
   window.open("ContactDetails.aspx?ContactID="+ContactID,"MyWindow","width=980,height=660,resizable=yes");
}

In the code behind:

.ASPX.VB
-------------
Me.HyperLink2.Attributes.Add("onclick","javascript: OpenContactDetails("&Session("NotifierID")&");")

Or you can also do like this:

Me.HyperLink2.Attributes.Add("onClick","javascript: window.open('ContactDetails.aspx?ContactID='"&Session("ContactID")&",'MyWindow','width=980,height=660')")
Me.HyperLink2.NavigateURL = "#"

-Nauman.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now