Calling a method from a drop down control

D

Doogie

If I run this code below in ASP.NET 2.0 it fails with an "Object
Required" error and I have no idea why.

Could someone tell me why this is failing? Then if I can get an
answer to that, I would actually prefer to run a C# method instead of
a javascript one and would like to figure out how to set that up (but
I get the same error doing that too).

<select id="cbCarriers" onchange="javascript: test();">
<option value='241'>3GP</option>
<option value='441'>AAC</option>
<option value='1115'>AB1</option>
</select>

<script type="javascript">
function test()
{
alert("this");
}
</script>
 
D

David Mark

If I run this code below in ASP.NET 2.0 it fails with an "Object
Required" error and I have no idea why.

Could someone tell me why this is failing? Then if I can get an
answer to that, I would actually prefer to run a C# method instead of
a javascript one and would like to figure out how to set that up (but
I get the same error doing that too).

<select id="cbCarriers" onchange="javascript: test();">
<option value='241'>3GP</option>
<option value='441'>AAC</option>
<option value='1115'>AB1</option>
</select>

<script type="javascript">
function test()
{
alert("this");
}
</script>

onchange="test();"

And don't do this for navigation. Keyboard and mousewheel users will
hate it.

As for .NET and C#, you will have to ask elsewhere.
 
D

Daz

If I run this code below in ASP.NET 2.0 it fails with an "Object
Required" error and I have no idea why.

Could someone tell me why this is failing? Then if I can get an
answer to that, I would actually prefer to run a C# method instead of
a javascript one and would like to figure out how to set that up (but
I get the same error doing that too).

<select id="cbCarriers" onchange="javascript: test();">
<option value='241'>3GP</option>
<option value='441'>AAC</option>
<option value='1115'>AB1</option>
</select>

<script type="javascript">
function test()
{
alert("this");
}
</script>

Try removing the "javascript: " clause from your function. It's not
needed, as anything within the onchange attribute is automatically
passed on to the JavaScript engine, as onchange is JavaScript.
 
H

Henry

If I run this code below in ASP.NET 2.0 it fails with an "Object
Required" error and I have no idea why.

Could someone tell me why this is failing? Then if I can get an
answer to that, I would actually prefer to run a C# method instead of
a javascript one and would like to figure out how to set that up (but
I get the same error doing that too).

<select id="cbCarriers" onchange="javascript: test();">
<option value='241'>3GP</option>
<option value='441'>AAC</option>
<option value='1115'>AB1</option>
</select>

<script type="javascript">
function test()
{
alert("this");
}
</script>

The value of your TYPE attribute in the SCRIPT element is not being
recognised. Use type="text/javascript" in HTML documents (for the time
being).
 
D

Doogie

onchange="test();"

And don't do this for navigation. Keyboard and mousewheel users will
hate it.

Not sure what you are getting at with the navigation...but I tried
putting the onchange value like you have above and it still failed.
 
D

Doogie

[snip]
<select id="cbCarriers" onchange="javascript: test();">

^^^
[/snip]

Have you tried and removed the space I'm pointing at?

Yes, I tried to remove that space so that there is no space between
the : and 'test' and it still fails with the same error.
 
D

Doogie

Try removing the "javascript: " clause from your function. It's not
needed, as anything within the onchange attribute is automatically
passed on to the JavaScript engine, as onchange is JavaScript.- Hide quoted text -

- Show quoted text -

I tried that and it didn't work...however I think I found my
javascript issue...my <script> tag was incorrect...once I got it like
this:

<script language="JavaScript" type="text/javascript">

It worked fine. But, now I need to figure out a way to have this call
a .NET method. Is that even possible with a client side control?
 
B

Benjamin Sattler

[snip]
It worked fine. But, now I need to figure out a way to have
this call a .NET method. Is that even possible with a client
side control?

I don't know, but maybe those guys can help you:

microsoft.public.dotnet.languages.csharp

Guess it's that group.
 
D

David Mark

[snip]
<select id="cbCarriers" onchange="javascript: test();">
^^^
[/snip]

Have you tried and removed the space I'm pointing at?

Yes, I tried to remove that space so that there is no space between
the : and 'test' and it still fails with the same error.

Also change the type attribute of the script tag as noted by another
posted.

And as for the navigation issue, try it with the keyboard and/or a
mousewheel. SELECT tags are form inputs and not meant to be used as
menus. I know that there are millions of incompetent sites out there
doing this, but you shouldn't follow their lead. If you must do this,
pair the input with a button.
 
D

Doogie

And as for the navigation issue, try it with the keyboard and/or a
mousewheel. SELECT tags are form inputs and not meant to be used as
menus. I know that there are millions of incompetent sites out there
doing this, but you shouldn't follow their lead. If you must do this,
pair the input with a button.

I'm using the select tag to create a drop down list. I actually am
not creating the tag myself, our company has a common method that you
can query the DB and return the values inside a string that is the
select tag itself. So I just reference the string variable in my html
and the drop down box is created. I don't believe I'm using it as a
menu in the sense of how you are describing but am not really sure.
 
D

David Mark

I'm using the select tag to create a drop down list. I actually am
not creating the tag myself, our company has a common method that you
can query the DB and return the values inside a string that is the
select tag itself. So I just reference the string variable in my html
and the drop down box is created. I don't believe I'm using it as a
menu in the sense of how you are describing but am not really sure.

What is it that you are doing in the onchange event? If you are
navigating to another page, that is a bad idea. That is what I was
referring to. It is a common and very irritating practice. I really
can't think of anything that should be done in the onchange event of a
select tag, but faux navigation menus are the worst example.
 
D

Doogie

What is it that you are doing in the onchange event? If you are
navigating to another page, that is a bad idea. That is what I was
referring to. It is a common and very irritating practice. I really
can't think of anything that should be done in the onchange event of a
select tag, but faux navigation menus are the worst example.

Well, the select tag is inside a user control and so I need to get the
value of the item selected within it, so that when the user clicks on
the command button (also in that control), I have the proper value to
do a database call. So I want to grab that value and store it in a
variable inside the user control and pass it over to the actual page
that is using the user control. That's also why I would prefer to do
this inside .net instead of javascript so I can easily send that value
from the user control to the page that uses the control.
 
D

David Mark

Well, the select tag is inside a user control and so I need to get the
value of the item selected within it, so that when the user clicks on
the command button (also in that control), I have the proper value to

Why not check the value when the user clicks the button?
 
D

Doogie

Why not check the value when the user clicks the button?

That's a good idea too. However, since I am building this select tag
dynamically and it is a client side control, I'm thinking I'll have
issues trying to determine it's value in any case inside .net. I
might have to either stick with javascript or use a server side drop
down box.
 
D

Daz

I tried that and it didn't work...however I think I found my
javascript issue...my <script> tag was incorrect...once I got it like
this:

<script language="JavaScript" type="text/javascript">

It worked fine. But, now I need to figure out a way to have this call
a .NET method. Is that even possible with a client side control?

The language attribute has now been deprecated, as of HTML 4.0(?). You
only need to supply the type.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,616
Members
45,306
Latest member
TeddyWeath

Latest Threads

Top