【发布时间】:2015-11-25 06:42:11
【问题描述】:
我想在下拉菜单 selectedindexchanged 上调用 javascript 函数。我试过这个
<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>
错误
BC30456:“GetRoute”不是“ASP.index3_aspx”的成员。
然后我尝试了 onChange 而不是 OnSelectedIndexChanged 但它对我没有用,因为在我的 js 函数中插入的文本框中的值正在工作但是当页面重新加载时文本框再次变为空白并且我无法关闭 AutoPostBack 因为它需要回发。有可能我可以运行 javascript OnSelectedIndexChanged 吗?
【问题讨论】:
-
不,
OnSelectedIndexChanged是服务器端事件处理程序,您不能将客户端处理程序附加到它。你到底想做什么? -
@RahulSingh on dropdownselection 我想调用 GetRoute();计算两个地方之间的距离并将其放在文本框中的脚本。如果我使用 OnChange 然后回发文本框再次变为空白。我只想在回发后将距离值保留在文本框中。
-
@RahulSingh 我可以将 GetRoute() 函数放在后面的代码中,然后 OnSelected IndexChanged 可能对我有用吗?如果可以的话,你能告诉我怎么做吗?
-
是的,如果你无论如何都在做回发,那么在后面的代码中编写下拉更改事件处理程序中的逻辑。
标签: javascript asp.net vb.net