473,569 Members | 2,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to get DropDownList to fire a Javascript function

Hi all...

I am trying to do a simple thing and maybe am missing something elementary.
I have created a Javascript function at the top of a page which is meant to
enable editing of an HTML input textbox when the user makes a selection from
the DropDownList control. Since there is no OnClick event I have tried using
OnSelectedIndex Changed or OnTextChanged such as OnTextChanged ="ckCat()"
with ckCat being the javascript function name. I have purposely set
AutoPostback="f alse" to make sure that wasn't the problem. I have also
tried using the syntax OnTextChanged ="javascript:ck Cat()" to no avail.
It's pretty easy to do in classic ASP, but I am trying to get accustomed to
the .NET way of doing things.

Does anyone know what I am missing? I am thinking there must be a way to
enable clientside handling of a DropDownList event, especially with
AutoPostback turned off. I'm just drawing a blank right now.

Thanks to all for any input...

Apr 27 '07 #1
3 12243
John,
You could add this to your Page_Load event on your codebehind:
cboList.Attribu tes.Add("onchan ge", "ckCat();") ;
--
Page Brooks
www.explosivedog.com
"John Kotuby" <jo***@powerlis t.comwrote in message
news:OF******** *****@TK2MSFTNG P06.phx.gbl...
Hi all...

I am trying to do a simple thing and maybe am missing something
elementary. I have created a Javascript function at the top of a page
which is meant to enable editing of an HTML input textbox when the user
makes a selection from the DropDownList control. Since there is no OnClick
event I have tried using OnSelectedIndex Changed or OnTextChanged such as
OnTextChanged ="ckCat()" with ckCat being the javascript function name. I
have purposely set AutoPostback="f alse" to make sure that wasn't the
problem. I have also tried using the syntax OnTextChanged
="javascript:ck Cat()" to no avail. It's pretty easy to do in classic ASP,
but I am trying to get accustomed to the .NET way of doing things.

Does anyone know what I am missing? I am thinking there must be a way to
enable clientside handling of a DropDownList event, especially with
AutoPostback turned off. I'm just drawing a blank right now.

Thanks to all for any input...

Apr 27 '07 #2
Thanks Page,

I was trying to figure out a way to add onclick event but the onchange is
what I really want. How does one determine which events/attributes are
"allowed" for a particular ASP control and that the control will respond as
expected? I an guessing that because the onchange attribute is allowed for
the HTML <selecttag which accomplishes the same action it would be
allowed.

Of course (light bulb just went on) the DropDownList control must render as
an HTML <selectand therefore the OnChange event would be perfectly legal
at the browser. Yes I was missing an important but simple concept. Sometimes
I get so focused on the Server side processing of Server Controls I lose
site of the fact that they are simply rendered as standard HTML.

I would love to find a chart to post by my desk "<Server Control-- renders
as -- <HTML Tags>". Almost as important a reminder as the Page Event life
cycle on the server side.

Thanks again Page for making this task easier...
"Page Brooks" <NO************ **@gmail.comwro te in message
news:eX******** ******@TK2MSFTN GP04.phx.gbl...
John,
You could add this to your Page_Load event on your codebehind:
cboList.Attribu tes.Add("onchan ge", "ckCat();") ;
--
Page Brooks
www.explosivedog.com
"John Kotuby" <jo***@powerlis t.comwrote in message
news:OF******** *****@TK2MSFTNG P06.phx.gbl...
>Hi all...

I am trying to do a simple thing and maybe am missing something
elementary. I have created a Javascript function at the top of a page
which is meant to enable editing of an HTML input textbox when the user
makes a selection from the DropDownList control. Since there is no
OnClick event I have tried using OnSelectedIndex Changed or OnTextChanged
such as OnTextChanged ="ckCat()" with ckCat being the javascript function
name. I have purposely set AutoPostback="f alse" to make sure that wasn't
the problem. I have also tried using the syntax OnTextChanged
="javascript:c kCat()" to no avail. It's pretty easy to do in classic
ASP, but I am trying to get accustomed to the .NET way of doing things.

Does anyone know what I am missing? I am thinking there must be a way to
enable clientside handling of a DropDownList event, especially with
AutoPostback turned off. I'm just drawing a blank right now.

Thanks to all for any input...




Apr 28 '07 #3
John,
No problem. You are right, each Server Control ultimately renders as one
ore more client-side HTML controls. Just give it some time to sink in,
after working with the controls for a while you shouldn't have any trouble
remembering them. Just keep in mind, that some controls may render
differently depending on which properties are selected on the server-side.
Take the TextBox control for example. Changing the TextMode property of the
TextBox Server control to multiline will cause ASP.NET to render the control
as a TEXTAREA control rather than an <INPUT type="text" ...control.

--
Page Brooks
www.explosivedog.com
"John Kotuby" <jo***@powerlis t.comwrote in message
news:Og******** ********@TK2MSF TNGP06.phx.gbl. ..
Thanks Page,

I was trying to figure out a way to add onclick event but the onchange is
what I really want. How does one determine which events/attributes are
"allowed" for a particular ASP control and that the control will respond
as expected? I an guessing that because the onchange attribute is allowed
for the HTML <selecttag which accomplishes the same action it would be
allowed.

Of course (light bulb just went on) the DropDownList control must render
as an HTML <selectand therefore the OnChange event would be perfectly
legal at the browser. Yes I was missing an important but simple concept.
Sometimes I get so focused on the Server side processing of Server
Controls I lose site of the fact that they are simply rendered as standard
HTML.

I would love to find a chart to post by my desk "<Server Control--
renders as -- <HTML Tags>". Almost as important a reminder as the Page
Event life cycle on the server side.

Thanks again Page for making this task easier...
"Page Brooks" <NO************ **@gmail.comwro te in message
news:eX******** ******@TK2MSFTN GP04.phx.gbl...
>John,
You could add this to your Page_Load event on your codebehind:
cboList.Attrib utes.Add("oncha nge", "ckCat();") ;
--
Page Brooks
www.explosivedog.com
"John Kotuby" <jo***@powerlis t.comwrote in message
news:OF******* ******@TK2MSFTN GP06.phx.gbl...
>>Hi all...

I am trying to do a simple thing and maybe am missing something
elementary. I have created a Javascript function at the top of a page
which is meant to enable editing of an HTML input textbox when the user
makes a selection from the DropDownList control. Since there is no
OnClick event I have tried using OnSelectedIndex Changed or OnTextChanged
such as OnTextChanged ="ckCat()" with ckCat being the javascript
function name. I have purposely set AutoPostback="f alse" to make sure
that wasn't the problem. I have also tried using the syntax
OnTextChang ed ="javascript:ck Cat()" to no avail. It's pretty easy to do
in classic ASP, but I am trying to get accustomed to the .NET way of
doing things.

Does anyone know what I am missing? I am thinking there must be a way to
enable clientside handling of a DropDownList event, especially with
AutoPostbac k turned off. I'm just drawing a blank right now.

Thanks to all for any input...





Apr 30 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3404
by: Brennon Arnold | last post by:
I have a problem that I figured would be relatively common, but have been unable to find any information on it as of yet. I have a page that contains two DropDownList controls, with the second being dependent on the value of the first. My DropDownList control definitions look like this: <asp:dropdownlist id="ddlLocCty" runat="server"...
2
3910
by: jm | last post by:
I have datagrid. On this datagrid there is a button and a dropdownlist. When I press the button, I want the selectedIndex of the dropdownlist. There is a button and a dropdownlist for each datagrid row that is populated from the database. Example, five rows returned, five buttons, and five dropdownlists. I know I am supposed to use...
2
5067
by: MBhat | last post by:
Hello, I have a dropdownlist server control.On selectedIndexChange I do some functionality. In addtion to this I need to check for something else. To do this I have to use javascript function to display confirmation alert. How can I use the javascript confirmation alert in code behind? any help? Thanks
7
6173
by: Daniel | last post by:
Is there any other way can override this event, like javascript onchange added to the attribute of this dropdownlist? Thanks
6
5516
by: Julius Fenata | last post by:
Dear all, I have created client-side scripting to trigger event onChange from code-behind, like this: DropDownList1.Attributes = "GenerateArticleID()"; At the script on Windows Form, I added this function to have the value of DropDownList1
4
1936
by: David | last post by:
Hi all, I am doing this in a web page... I have a dropdownlist that autopostback. This sets me a filter criteria for items to display in a datalist. In the datalist, I have edit capabilities, which opens a text box. When I click Update for the datalist (edit), then for some reason, the
3
5273
by: Iain | last post by:
Hi All I have 2 DropDownList boxes on a page. The first (id= "Operation") is populated on PageLoad with the contents of a database table. The second id="WorkStations" will not be populated until the first has been changed The definitions are below.
6
4309
by: w1688 | last post by:
Hi All, I had asp page using Visual studio 2005 to develop. I had a dropdownlist box with more than hundred items list. I am looking a function which allow user to type on dropdownlist box and the dropdownlist box will automatically to search the related items. I tried to use the JavaScript function, but it doesn’t work. Here is my...
3
10566
by: Lohboy | last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET side.) I have two DropDownList controls the second of which resides within an UpdatePanel control which responds to a change in the first DropDownList. I also have a hidden button nested inside the...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7970
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.