Solved

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

Posted on 2006-07-07
9
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

697 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