Solved

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

Posted on 2006-07-07
9
391 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.net Fit 3 divs on screen side by side 3 39
Creating a route in asp.net webforms 2 32
Need help with building query string 2 21
How to create an MVC5, Razor Widget 2 26
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

791 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