Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 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 May 3rd, 2010, 03:58 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default Function in onselectedindexchanged not found

This is driving me nuts! I get this error:

"Error 2 'EnableLoad' is not a member of 'ASP.frmquestionselection_aspx'. D:\Projects\2008\Interview Questionnaire\frmQuestionSelection.aspx 28":

From this HTML line:

<asp:DropDownListID="ddIQList"runat="server"OnSelectedIndexChanged="EnableLoad()">

Yet this works:

<asp:DropDownListID="ddIQList"runat="server"onclick="EnableLoad()">

Here's the script in BOTH instances:

<scriptlanguage='VBScript'type='text/vbscript'>
<!--
EnableLoad()


sub EnableLoad()
if frmQuestionSelection.ddIQList.SelectedIndex > -1 then
frmQuestionSelection.btnLoad.disabled=false
else
frmQuestionSelection.btnLoad.disabled=true
endif
endsub

Intelisense says onselectedindexchanged is a valid event for a select. So, why is the EnableLoad() script found by the onclick event but NOT by the onselectedindexchanged event?


 
Old May 3rd, 2010, 04:16 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

OnClick is not a server side event of the DDL, and thus the *client side VB script* method EnableLoad can be used *at the client* when the control is clicked. The compiler does not try to look for a server method.

OnSelectedIndexChanged on the other hand is a server side event. As such, the compiler looks for a server side method implemented in C# or VB in the page that contains the controls declaration.

Does this help?

Imar
---------------------------------------------------------------------------------------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter.

Everyone is unique, except for me.
Author of Beginning ASP.NET 4 : in C# and VB, Beginning ASP.NET 3.5 : in C# and VB, and ASP.NET 2.0 Instant Results.
While typing this post, I was listening to: What Your Soul Sings by Massive Attack (Track 2 from the album: 100th Window) What's This?
 
Old May 3rd, 2010, 04:19 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
If you have nothing to offer except a lecture on the superiority of Javascript, do not waste your time or mine. I am in an all IE world where I can use VBScript to my heart's content. I choose to use VBScript over Javascript because Javascript is horrendously frustrating to me due to inconsistencies in naming standards and and unnecessary case sensitivity. I would rather not receive assistance than have to read one more sanctimonious lecture about what an idiot I am for using VBScript, OK???
Absolutely OK. But that doesn't mean it's OK to start using VB Script for server side event handlers. There are limits, you know.... ;-)

Cheers,

Imar
---------------------------------------------------------------------------------------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter.

Everyone is unique, except for me.
Author of Beginning ASP.NET 4 : in C# and VB, Beginning ASP.NET 3.5 : in C# and VB, and ASP.NET 2.0 Instant Results.
While typing this post, I was listening to: Pray for Rain by Massive Attack (From the album: Heligoland) What's This?
 
Old May 4th, 2010, 09:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

After wrestling with it for a couple of hours I decided to go with server side code (and not vbSCRIPT, of course!) I think the VS 2008 ought not list OnSelectedIndexChanged as a valid HTML attribute on the asp:button in intellisense if it won't compile with that event selected.


As to the sig, I only wanted a vbscript solution IF the intended solution was to be implemented client side, of course. I was hoping to avoid the round trip to the server with AJAX, but in retrospect, it doesn't really matter if a callback occurs in this instance. Ubiquitous support for JS leads some to supply a JS solution even though VS was specifically requested, and still others feel the strange need to lecture me about using it. The sig was intended to prevent responses that would not prove helpful and not as an insult to those who prefer JS.
 
Old May 4th, 2010, 09:23 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
I think the VS 2008 ought not list OnSelectedIndexChanged as a valid HTML attribute on the asp:button in intellisense if it won't compile with that event selected.

Either you didn't show the complete code, or it's not doing this. It shows OnSelectedIndexChanged for the DropDownList, which is a valid event for this control at the server.

From what I can see, both event handlers are valid, be it both in a different context.

If you wanted to, you could use simple <select /> items instead and use the client side onchange, optionally with a runat="server" attribute so the lists can be reached from server side code.

Quote:
As to the sig, I only wanted a vbscript solution IF the intended solution was to be implemented client side, of course. I was hoping to avoid the round trip to the server with AJAX, but in retrospect, it doesn't really matter if a callback occurs in this instance. Ubiquitous support for JS leads some to supply a JS solution even though VS was specifically requested, and still others feel the strange need to lecture me about using it. The sig was intended to prevent responses that would not prove helpful and not as an insult to those who prefer JS.
I know, and completely understand; hence the smiley in my reply ;-)


Cheers.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 6, OnSelectedIndexChanged roman BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 June 16th, 2008 05:02 PM
onSelectedIndexChanged event not firing??? MTLedari ASP.NET 2.0 Basics 5 December 19th, 2006 10:35 AM
OnSelectedIndexChanged event not firing ethertt77 ASP.NET 2.0 Basics 2 February 20th, 2006 07:34 PM
catching the OnSelectedIndexChanged event Aaron Edwards Classic ASP Professional 1 October 5th, 2005 02:51 PM
DropDownList - OnSelectedIndexChanged LarryH ASP.NET 1.0 and 1.1 Basics 1 February 2nd, 2005 12:51 AM





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