473,466 Members | 1,451 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamically (in code) add a Event Proc Prop??

This might be fairly easy to do. Hopefully, it is.

(asp.net 2 / vb)

I have a Drop Down List and in th code-behind vb file, I'd like to
optionally add a OnSelectedIndexChanged attribute to it. Depending on
whether certain conditions are met when the page loads, I'd like to be able
to optionally add this attribute to my DDL. Does this make sense? I tried
using this but it doesn't work:

ddlOperatingItems.Attributes.Add("OnSelectedIndexC hanged",
"ddlExpenseItems_SelectedIndexChange")

This shows up in the html source code:
OnSelectedIndexChanged="ddlExpenseItems_SelectedIn dexChange"
Essentially what I'm trying to accomplish is that **under certain
conditions**, require the user to provide a brief explaination if they chose
"Other" in the DDL. The txtbox and RequiredValidator become enabled. The
trick is optionally making this DDL change on SelectedIndex. I don't want
this to **always** be in place.
Here's clips of my code.

Sub Page_load
If myVariable= True Then
ddlOperatingItems.Attributes.Add("OnSelectedIndexC hanged",
"ddlExpenseItems_SelectedIndexChange")
End If
End Sub

Protected Sub ddlExpenseItems_SelectedIndexChange(ByVal Sender As Object,
ByVal E As EventArgs)

If ddlOperatingItems.SelectedValue = XXX Then
txtOtherDescription.Enabled = True
txtOtherDescription.Text = ""
OtherDescRequired.Enabled = True
Else
txtOtherDescription.Enabled = False
txtOtherDescription.Text = "Not Required"
OtherDescRequired.Enabled = False
End If

End Sub


Jun 2 '06 #1
3 2170
You are adding a client side event handler. And I believe the javascript
<select> object does not have an OnSelectedIndexChanged. This is a server
side event only.

To add server side events, use AddHandler.

So, something ilke:

AddHandler ddlOperatingItems.SelectedIndexChanged, AddressOf
ddlExpenseItems_SelectedIndexChanged

"Groove" <no***@noemail.com> wrote in message
news:eo**************@TK2MSFTNGP04.phx.gbl...
This might be fairly easy to do. Hopefully, it is.

(asp.net 2 / vb)

I have a Drop Down List and in th code-behind vb file, I'd like to
optionally add a OnSelectedIndexChanged attribute to it. Depending on
whether certain conditions are met when the page loads, I'd like to be
able to optionally add this attribute to my DDL. Does this make sense? I
tried using this but it doesn't work:

ddlOperatingItems.Attributes.Add("OnSelectedIndexC hanged",
"ddlExpenseItems_SelectedIndexChange")

This shows up in the html source code:
OnSelectedIndexChanged="ddlExpenseItems_SelectedIn dexChange"
Essentially what I'm trying to accomplish is that **under certain
conditions**, require the user to provide a brief explaination if they
chose "Other" in the DDL. The txtbox and RequiredValidator become
enabled. The trick is optionally making this DDL change on SelectedIndex.
I don't want this to **always** be in place.
Here's clips of my code.

Sub Page_load
If myVariable= True Then
ddlOperatingItems.Attributes.Add("OnSelectedIndexC hanged",
"ddlExpenseItems_SelectedIndexChange")
End If
End Sub

Protected Sub ddlExpenseItems_SelectedIndexChange(ByVal Sender As Object,
ByVal E As EventArgs)

If ddlOperatingItems.SelectedValue = XXX Then
txtOtherDescription.Enabled = True
txtOtherDescription.Text = ""
OtherDescRequired.Enabled = True
Else
txtOtherDescription.Enabled = False
txtOtherDescription.Text = "Not Required"
OtherDescRequired.Enabled = False
End If

End Sub


Jun 2 '06 #2
Thanks!

I added this:
AddHandler ddlOperatingItems.SelectedIndexChanged, AddressOf
ddlExpenseItems_SelectedIndexChange

to my code in page_load and nothing seems to happen when change the values
in the DDL. I'm NOT testing for PostBack so it should be loading this each
and every time. VWD Express isn't indicating any syntax errors and the page
compiles and loads fine. Just nothing happens.

Any ideas?

Thanks



"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:uQ**************@TK2MSFTNGP04.phx.gbl...
You are adding a client side event handler. And I believe the javascript
<select> object does not have an OnSelectedIndexChanged. This is a server
side event only.

To add server side events, use AddHandler.

So, something ilke:

AddHandler ddlOperatingItems.SelectedIndexChanged, AddressOf
ddlExpenseItems_SelectedIndexChanged

"Groove" <no***@noemail.com> wrote in message
news:eo**************@TK2MSFTNGP04.phx.gbl...
This might be fairly easy to do. Hopefully, it is.

(asp.net 2 / vb)

I have a Drop Down List and in th code-behind vb file, I'd like to
optionally add a OnSelectedIndexChanged attribute to it. Depending on
whether certain conditions are met when the page loads, I'd like to be
able to optionally add this attribute to my DDL. Does this make sense?
I tried using this but it doesn't work:

ddlOperatingItems.Attributes.Add("OnSelectedIndexC hanged",
"ddlExpenseItems_SelectedIndexChange")

This shows up in the html source code:
OnSelectedIndexChanged="ddlExpenseItems_SelectedIn dexChange"
Essentially what I'm trying to accomplish is that **under certain
conditions**, require the user to provide a brief explaination if they
chose "Other" in the DDL. The txtbox and RequiredValidator become
enabled. The trick is optionally making this DDL change on
SelectedIndex. I don't want this to **always** be in place.
Here's clips of my code.

Sub Page_load
If myVariable= True Then
ddlOperatingItems.Attributes.Add("OnSelectedIndexC hanged",
"ddlExpenseItems_SelectedIndexChange")
End If
End Sub

Protected Sub ddlExpenseItems_SelectedIndexChange(ByVal Sender As Object,
ByVal E As EventArgs)

If ddlOperatingItems.SelectedValue = XXX Then
txtOtherDescription.Enabled = True
txtOtherDescription.Text = ""
OtherDescRequired.Enabled = True
Else
txtOtherDescription.Enabled = False
txtOtherDescription.Text = "Not Required"
OtherDescRequired.Enabled = False
End If

End Sub



Jun 2 '06 #3
Nevermind. I needed to add AutoPostback = True.

Thanks!
"Groove" <no***@noemail.com> wrote in message
news:O1****************@TK2MSFTNGP05.phx.gbl...
Thanks!

I added this:
AddHandler ddlOperatingItems.SelectedIndexChanged, AddressOf
ddlExpenseItems_SelectedIndexChange

to my code in page_load and nothing seems to happen when change the values
in the DDL. I'm NOT testing for PostBack so it should be loading this
each and every time. VWD Express isn't indicating any syntax errors and
the page compiles and loads fine. Just nothing happens.

Any ideas?

Thanks



"Marina Levit [MVP]" <so*****@nospam.com> wrote in message
news:uQ**************@TK2MSFTNGP04.phx.gbl...
You are adding a client side event handler. And I believe the javascript
<select> object does not have an OnSelectedIndexChanged. This is a server
side event only.

To add server side events, use AddHandler.

So, something ilke:

AddHandler ddlOperatingItems.SelectedIndexChanged, AddressOf
ddlExpenseItems_SelectedIndexChanged

"Groove" <no***@noemail.com> wrote in message
news:eo**************@TK2MSFTNGP04.phx.gbl...
This might be fairly easy to do. Hopefully, it is.

(asp.net 2 / vb)

I have a Drop Down List and in th code-behind vb file, I'd like to
optionally add a OnSelectedIndexChanged attribute to it. Depending on
whether certain conditions are met when the page loads, I'd like to be
able to optionally add this attribute to my DDL. Does this make sense?
I tried using this but it doesn't work:

ddlOperatingItems.Attributes.Add("OnSelectedIndexC hanged",
"ddlExpenseItems_SelectedIndexChange")

This shows up in the html source code:
OnSelectedIndexChanged="ddlExpenseItems_SelectedIn dexChange"
Essentially what I'm trying to accomplish is that **under certain
conditions**, require the user to provide a brief explaination if they
chose "Other" in the DDL. The txtbox and RequiredValidator become
enabled. The trick is optionally making this DDL change on
SelectedIndex. I don't want this to **always** be in place.
Here's clips of my code.

Sub Page_load
If myVariable= True Then
ddlOperatingItems.Attributes.Add("OnSelectedIndexC hanged",
"ddlExpenseItems_SelectedIndexChange")
End If
End Sub

Protected Sub ddlExpenseItems_SelectedIndexChange(ByVal Sender As
Object, ByVal E As EventArgs)

If ddlOperatingItems.SelectedValue = XXX Then
txtOtherDescription.Enabled = True
txtOtherDescription.Text = ""
OtherDescRequired.Enabled = True
Else
txtOtherDescription.Enabled = False
txtOtherDescription.Text = "Not Required"
OtherDescRequired.Enabled = False
End If

End Sub




Jun 2 '06 #4

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

Similar topics

4
by: Perion | last post by:
I have a simple form with, among other things, an ADODC data control (called "Adodc1"). The ADO connection to the database tests fine but when I try to add code to any of the Adodc1 control's event...
4
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; ...
3
by: N. Demos | last post by:
How do you dynamically assign a function to an element's event with specific parameters? I know that the code is different for MSIE and Mozilla, and need to know how to do this for both. I...
0
by: viovanov | last post by:
I am trying to get some events to fire properly. I have a series of LinkButtons with some attribute set, one of which is unique for each LinkButton. At first I load a few buttons, and I set...
7
by: Ron Goral | last post by:
Hello I am new to creating objects in javascript, so please no flames about my coding style. =) I am trying to create an object that will represent a "div" element as a menu. I have written...
5
by: J | last post by:
I am having problems dynamically adding more than one event handler to an input. I have tried the Javascript included at the bottom. The lines inp.attachEvent('onkeyup',...
1
by: Payodhi | last post by:
At runtime I am binding value of a grid view.First & last columns are template column .Inside first column I have taken a Dropdownlist and last column I have text box.Remember everything I am doing...
2
by: svenkat | last post by:
Hi i got the keycode for ie like (event.keyCode) but this is not working in the firefox browser. can u give me the solution for the both the browsers.
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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 ...

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.