Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 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
 
Old March 25th, 2009, 11:36 PM
Authorized User
 
Join Date: Jan 2009
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
Default window.open syntax error

<asp:ButtonID="ViewComment"runat="server"onClientClick=<%# string.Format("window.open('ViewComment.aspx?Updat eID{0}',left=600,top=50,width=500,height=500,scrol lbars=1);", Eval("UpdateID")) %> Text="View Comment"/>
Does anyone knows what is wrong with the above code.
I would like to Open ViewComment.aspx determine by the UpdateID, but there's a syntax error in between.
 
Old March 26th, 2009, 02:19 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default Need Quotes?

I can't see the quotes surrounding the onClientClick code:

Code:
onClientClick="<%# string.Format("window.open('ViewComment.aspx?Updat eID{0}',left=600,top=50,width=500,height=500,scrol lbars=1);", Eval("UpdateID")) %>"
See the quotes in green? Don't worry, even though you may think it will end up actually putting the content in the quotes in, it will actually still be parsed by the runtime.
__________________
Rob
http://cantgrokwontgrok.blogspot.com
 
Old March 26th, 2009, 02:22 AM
Authorized User
 
Join Date: Jan 2009
Posts: 23
Thanks: 8
Thanked 0 Times in 0 Posts
Default

Hey. According to ur reply, i edited the code to the following:
onClientClick="<%# string.Format("window.open('ViewComment.aspx?Updat eID={0}',left=600,top=50,width=500,height=500,scro l lbars=1);", Eval("UpdateID")) %>"

But however, it still show the error below.

Parser Error Message: The server tag is not well formed.
 
Old March 26th, 2009, 02:35 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hmm.. I thought maybe it was the formatting on the forum, but I also note you do not have spaces between the attributes in the code:
Code:
<asp:Button ID="ViewComment" runat="server" onClientClick="<%# string.Format("window.open('ViewComment.aspx?Updat eID{0}',left=600,top=50,width=500,height=500,scrollbars=1);", Eval("UpdateID")) %>" Text="View Comment"/>
Note the spaces added between
  • "asp:Button" and "ID"
  • "ViewComment" and "runat"
  • "server" and "onClientClick"
  • Removal of the space between "scroll" and "bars"
  • Removal of the space between "Updat" and "eID"
Does that fix it? You need to be real careful embedding code in the ASPX, you get little compile time support, and it can cause major errors if unchecked at runtime.

Edit
You are also not appending your QueryString correctly in the window.open
Code:
string.Format("window.open('ViewComment.aspx?UpdateID={0}',left=600,top=50,width=500,height=500,scrollbars=1);", Eval("UpdateID"))
__________________
Rob
http://cantgrokwontgrok.blogspot.com

Last edited by robzyc; March 26th, 2009 at 02:39 AM..
The Following User Says Thank You to robzyc For This Useful Post:
julius (March 27th, 2009)
 
Old March 26th, 2009, 06:06 AM
Friend of Wrox
Points: 894, Level: 11
Points: 894, Level: 11 Points: 894, Level: 11 Points: 894, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: London, , United Kingdom.
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default

The main issue with this is that you have double quotes embedded within the OnClientClick attribute, which means asp.net cannot parse it (which " ends the attribute?).
You have to put the OnClientClick in single quotes then use "" to escape the quotes round the target url - yes it's quite confusing.
In terms of the javascript you need to make the changes that Rob has suggested but also:
- add a window ID argument after the url argument
- put quotes (again "") round the whole chain window options - they are all one argument to the function.
- I also added a "return false;" to the javascript and set "UseSubmitBhaviour=false" on teh button so that it does not do a postback.

If you manage to decipher all that, this is what you should end up with:

Code:
<asp:Button ID="ViewComment" runat="server" OnClientClick='<%# String.Format("window.open(""ViewComment.aspx?UpdateID={0}"", ""Update"", ""left=600,top=50,width=500,height=500,scrollbars=1"");return false;", Container.DataItem) %>'
   Text="View Comment" UseSubmitBehavior="false"
/>
HTH
Phil

Last edited by philip_cole; March 26th, 2009 at 06:08 AM.. Reason: highlighting code
The Following User Says Thank You to philip_cole For This Useful Post:
julius (March 27th, 2009)




Similar Threads
Thread Thread Starter Forum Replies Last Post
window.open() ckrajeshvarma ASP.NET 2.0 Professional 5 August 16th, 2006 09:13 AM
Open New Window b_camp Classic ASP Basics 2 May 12th, 2005 01:19 AM
problem with objRS.Open syntax thisistoday Classic ASP Basics 1 August 5th, 2003 09:17 PM





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