Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 9th, 2007, 04:05 PM
Authorized User
 
Join Date: Jun 2007
Location: Christchurch, , New Zealand.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to hericles
Default Selecting itme from drop down list in script

Hi,
I have a drop down list in my .aspx page. When clicked the last item in the list needs to open a new window and display an external website. I know I can't open a new window server side and need to use a script on the page but don't know how. Ideally the script would be an IF statement - if the last index of the list is selected then new window opens.
Any suggestions / help?
Thank you.

"I will prepare and one day my chance will come."
__________________
\"I will prepare and one day my chance will come.\"
  #2 (permalink)  
Old August 9th, 2007, 06:31 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You can open a new window server side, sort of.

Enable AutoPostBack on the ddl and in your event handler do this:

if(ddl.SelectedItem.Value == "someValue")
{
     string js = "<script language='javascript'>";
     js += "window.open();"
     js += "</scr" + "ipt>"; //the end tag must be formated like this
     Response.Write(js);
}

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET

Professional IIS 7 and ASP.NET Integrated Programming

================================================== =========
  #3 (permalink)  
Old August 10th, 2007, 04:28 AM
Friend of Wrox
 
Join Date: Feb 2006
Location: noida, UP, India.
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

you can also use javascript to open the new window. If you are looking for javascript solution, let me know.
  #4 (permalink)  
Old August 10th, 2007, 05:03 PM
Authorized User
 
Join Date: Jun 2007
Location: Christchurch, , New Zealand.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to hericles
Default

Thanks dparsons,
that worked. Much appreciated.

Steve

"I will prepare and one day my chance will come."
  #5 (permalink)  
Old August 14th, 2007, 05:31 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:js += "</scr" + "ipt>"; //the end tag must be formated like this
parsons, what's the significance of above?

Regards
Mike

Don't expect too much, too soon.
  #6 (permalink)  
Old August 14th, 2007, 07:26 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

For some reason if you try to write out the end tag as "</script>" you will get a Javascript syntax error error everytime it is wrote to the response stream, regardless of syntax validity.

The reason for this error has something to do with the javascript functions that the runtime adds to the page to enable postbacks and such, but I can not remember exactly why this problem occurs. In any event, this is the work around to that problem. ^^

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Professional Search Engine Optimization with ASP.NET

Professional IIS 7 and ASP.NET Integrated Programming

================================================== =========
  #7 (permalink)  
Old August 14th, 2007, 08:51 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

ok, thanx for the information parsons, I'll keep this in mind...

Regards
Mike

Don't expect too much, too soon.
  #8 (permalink)  
Old August 21st, 2007, 01:21 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:The reason for this error has something to do with the javascript functions that the runtime adds to the page to enable postbacks and such, but I can not remember exactly why this problem occurs. In any event, this is the work around to that problem.
Actually, it has to do with the server side scripts, and only with pages without code behind (and with classic ASP pages).

With a page with in-line code or a classic ASP page, all server side code is wrapped in a <script> element like tis:

<script runat="server">
  protected void Page_Load(object sender, EventArgs e)
  {

  }
</script>

Now, imagine you had your script without the split end tag. You'd end up with this:

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
  string js = "<script type=\"text/javascript\">";
  js += "alert('Something');";
  js += "</script>";
  Response.Write(js);
}
</script>

With color coding on, you immediately see what's going on. All the code is black, except for the *first* </script> tag which is seen as the closing tag for the *server side script element*, and not as a part of a string literal.

Splitting up the end tag like Doug suggested fixes the problem. The first closing script tag is now seen as a string literal, while the second one is used to close the actual <script> element.

AFAIK, you only need this in pages with in-line code or in classic ASP pages. Pages with code behind don't suffer from this problem as there's no <script> element anywhere....

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting from multiple drop-lists Earl Hickey SQL Language 4 July 9th, 2008 03:34 PM
Drop Down boxes in Cells and selecting ranges tbmbob Excel VBA 0 June 1st, 2006 09:12 AM
problem in selecting the item from drop down list swati_joshi ASP.NET 1.0 and 1.1 Basics 1 March 27th, 2006 01:24 AM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
Java script function on drop down list selection Sachin3k Javascript How-To 3 April 30th, 2005 11:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.