从下拉控件中调用方法 [英] Calling a method from a dropdown control

查看:50
本文介绍了从下拉控件中调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在ASP.NET 2.0中运行以下代码,则会失败并显示对象

必需错误,我不明白为什么。


有人能告诉我为什么会失败吗?然后,如果我能得到一个

的答案,我实际上更愿意运行一个C#方法而不是

a javascript one,并想知道如何设置它(但是

我也得到同样的错误)。

< 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">

功能测试()

{

alert(" this");

}

< / script>

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>

推荐答案

" Doogie" < dn ****** @ dtgnet.com写信息

新闻:11 ********************** @ n60g2000hse .googlegr oups.com ...
"Doogie" <dn******@dtgnet.comwrote in message
news:11**********************@n60g2000hse.googlegr oups.com...

如果我在ASP.NET 2.0中运行以下代码,则会失败并显示Object

必需"错误,我不明白为什么。
If I run this code below in ASP.NET 2.0 it fails with an "Object
Required" error and I have no idea why.



如果你改变会发生什么


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





< select id = QUOT; cbCarriers" onchange =" test();">


并更改


< script type =" javascript">





< script type =" text / javascript">

-

Mark Rae

ASP.NET MVP
http ://www.markrae.net

What happens if you change

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

to

<select id="cbCarriers" onchange="test();">

and change

<script type="javascript">

to

<script type="text/javascript">
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


要尝试的事情。


theres a javascript后的空格


alert(''this'');


i不记得双引号在javascript中做,但单打是

一般你想要的。双打可能试图将您的

对象引用转换为字符串。函数是javascript中的对象,

这是一个引用该对象的特殊变量。


在你的代码中执行它你想要的将autopostback设置为

true,然后进行选定的Index change事件。你不会在你的代码后面有一个javascript警告弹出窗口。

couple things to try.

theres a space after the javascript:

alert(''this'');

i dont remember what double quotes do in javascript, but singles are
generally what you want. doubles might be trying to convert your
object reference to a string. functions are objects in javascript,
and this is a special variable which references that object.

to do it in your code behind you''ll want to set the autopostback to
true and then make a selected Index changed event. you won''t be
having an javascript alert popup in your code behind though.


以为我发布了,但它的没有出现。


尝试这些:

似乎是javascript 之后的空格:并且在test()之前;

alert(''blah'');


不知道javascript中的双引号,但它可能正在尝试

to调用函数对象的tostring方法。函数是javascript中的
对象,这是对该函数对象的引用。

我不记得双引号行为了。


用单引号和非保留字试试。

thought i posted, but its not showing up.

try these:
seems to be a space after javascript: and before test();
alert(''blah'');

dont know what double quotes do in javascript, but it could be trying
to call the tostring method of your function object. functions are
objects in javascript, this is a reference to that functions object.
I don''t remember double quote behavior though.

try it with single quotes, and with a non reserved word.


这篇关于从下拉控件中调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆