为什么ddl'onchange'事件没有出现在智能感知中? [英] Why does ddl 'onchange' event not appear in intellisense?

查看:102
本文介绍了为什么ddl'onchange'事件没有出现在智能感知中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在解决ddl的问题,试图在项目更改时弹出一个消息框.您可以在这里阅读有关>>> 如何从asp弹出Alert():DropDownList OnSelectedIndexChanged?

有效答案显示我使用onchange事件,但是随后我在VS2010中工作,此事件未出现在智能感知下拉列表中.但是,无论如何我都可以正常输入.

解决方案

为此,您需要了解它的工作原理....更改输入元素的值时,onchange事件会在浏览器,因此浏览器正在寻找一种处理它的方法.因此,当您放置为元素指定的onchange事件时,它将被调用.

现在,ASP.NET OnSelectedIndexChanged使用相同的功能(从逻辑上讲)将页面发布到服务器.从那里,ASP.NET运行时将触发您在代码隐藏文件中编写的函数,并向您返回结果.现在,如果您真的不需要任何只能在服务器上进行的操作,则无需使用服务器功能,而可以使用javascript来完成.

另一方面,如果您希望服务器上发生某些事情:像某些数据库获取一样,您应该使用OnSelectedIndexChanged事件.

如果使用OnSelectedIndexChanged事件,您仍然可以从那里调用一些javascript函数.

Page.ClientScript.RegisterClientScriptBlock(typeof(string),"myScript","alert('HI')",true);

要回答有关智能感知的问题,onchangeinput类型的事件,在aspx页面中,我猜您正在使用<asp:..>标记,该标记没有相同的事件-因此Visual Studio不会在智能感知中展示它.但是,当您放置它时,它会被分配给HTML标记,浏览器会正确解释这些标记.

优点和缺点

onchange可在您的浏览器上运行,因此它比服务器端代码快得多.另一方面,一旦浏览器具有限制弹出窗口的功能,我们就会遇到一个问题.因此,如果您希望显示一些非常重要的消息,最好使用服务器端事件和RegisterClientScriptBlock函数.

希望有帮助.

I was working out a problem with a ddl trying to get a message box to popup when the item changed. You can read about that here >>> How to Popup Alert() from asp:DropDownList OnSelectedIndexChanged?

The working answer shows me to use the onchange event but then I'm working in VS2010 this event does not appear in the intellisense dropdown. However if I type it in anyway it works fine.

解决方案

For this, you need to understand how the thing works....when you change the value of a input element, onchange event gets triggered on the browser, so the browser looks for a way to handle it. So when you put the onchange event specified for the element it gets called.

Now, ASP.NET OnSelectedIndexChanged uses the same functionality(logically saying) to POST the page to the server. From there, the ASP.NET runtime triggers the function you wrote in the codebehind file and returns you the result. Now, if you really don't require any operation that can only happen on the server, you don't need to use the server functionality, instead you can do it in javascript.

On the other hand, if you want something that happens on server: like some database get, you are supposed to use the OnSelectedIndexChanged event.

And if you use the OnSelectedIndexChanged event, you can still call some javascript functions from there.

Page.ClientScript.RegisterClientScriptBlock(typeof(string),"myScript","alert('HI')",true);

To answer your question about intellisense, onchange is a event of input types, and in aspx pages, i guess you are using <asp:..> tags, which does not have the same event - thus visual studio does not show it in the intellisense. But when you put it, it gets assigned to the HTML markups, which is interpreted correctly by the browser.

PROS and CONS

onchange works on your browser, so it is lot faster than the server-side code. On the other hand, we had an issue once that the browsers has the capability to restrict pop-ups. So if you want some really important message to be shown, it is better to use the Server-Side event and the RegisterClientScriptBlock function.

Hope it helps.

这篇关于为什么ddl'onchange'事件没有出现在智能感知中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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