Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在vb.net中调用javascript onSelectedIndexchanged_Javascript_Asp.net_Vb.net - Fatal编程技术网

在vb.net中调用javascript onSelectedIndexchanged

在vb.net中调用javascript onSelectedIndexchanged,javascript,asp.net,vb.net,Javascript,Asp.net,Vb.net,我想调用下拉菜单上的javascript函数selectedindexchanged。我试过这个 <asp:DropDownList ID="selectVehicle" AutoPostBack="true" OnSelectedIndexChanged="GetRoute(this.options[this.selectedIndex].value);" runat="server" CssClass="inners"> <asp:listitem Selected>

我想调用下拉菜单上的javascript函数selectedindexchanged。我试过这个

<asp:DropDownList ID="selectVehicle" AutoPostBack="true" OnSelectedIndexChanged="GetRoute(this.options[this.selectedIndex].value);" runat="server" CssClass="inners">
<asp:listitem Selected>-- Select Vehicle --</asp:listitem>
<asp:listitem Value="16">Tata Ace</asp:listitem>
<asp:listitem Value="28">Tata 407</asp:listitem>
</asp:DropDownList>

--选择车辆--
塔塔王牌
塔塔407
错误

BC30456:“GetRoute”不是“ASP.index3_aspx”的成员


然后我尝试了onChange而不是OnSelectedIndexChanged,但它对我没有任何用处,因为在我的js函数中,插入textbox的值正在工作,但当页面重新加载textbox时,textbox再次变为空白&我无法关闭AutoPostBack,因为它是回发所必需的。我可以在SelectedIndexChanged上运行javascript吗

您可以使用标准javascript onchange:

<asp:DropDownList ID="selectVehicle" AutoPostBack="false" onchange="GetRoute(this.options[this.selectedIndex].value);" runat="server" CssClass="inners">
</asp:DropDownList>

假设GetRoute是一个javascript函数


ASP.NET将忽略onchange属性,并将其呈现在结果select元素中。

Rahul Singh将JS代码写入服务器代码的注释,并且只运行服务器代码,而不运行Javascript,这是有意义的

如果出于某种原因必须使用JS,您可以删除autopostback=true,并使用参数手动调用_doPostBack,例如JS生成的值


否,
OnSelectedIndexChanged
是一个服务器端事件处理程序,您不能将客户端处理程序附加到它。你到底想做什么?@RahulSingh on dropdownselection我想调用GetRoute();脚本,用于计算两个位置之间的距离并将其放在文本框中。如果我使用OnChange,那么回发后文本框将再次变为空白。我只想在回发后将距离值保留在文本框中。@RahulSingh我可以将GetRoute()函数放在代码中隐藏吗?那么OnSelected IndexChanged可能对我有用吗?如果可能的话,你能告诉我怎么做吗?是的,如果你无论如何都在做回发,那么在代码隐藏中的下拉更改事件处理程序中写入逻辑。感谢回复,但我已经完成了,但我希望autopostback=“true”我需要保持启用自动回发。如果我让它保持启用状态,那么Textbox将丢失由GetRoute函数计算的值。回发后是否仍要保留该值?如果回发为true,它将运行您定义的onchange,然后运行onselectedindexchange服务器端函数。文本框是asp.net文本框吗?您使用的是传统的完整回发还是Ajax回发/脚本管理器?