简体   繁体   English

dropdownlist事件不会在属性窗口asp.net Visual Studio 2010中显示

[英]dropdownlist events does not show in properties window asp.net Visual Studio 2010

I recently found that dropdownlist events are not shown in properties window. 我最近发现下拉列表事件没有显示在属性窗口中。 I was disappointed. 我很失望。 I already hate asp.net designer in visual studio. 我已经厌倦了visual studio中的asp.net设计师。 its slow and full with ugly things like this. 它的速度很慢,充满了丑陋的东西。 please help me. 请帮我。 I need to generate events automatically not to write it by hand. 我需要自动生成事件而不是手动编写。

在此输入图像描述

It seems that the Properties Dropdown changes after viewing 'Split' or 'Design' view of the .aspx file at least once. 在查看.aspx文件的“拆分”或“设计”视图后,属性下拉列表似乎会更改一次。 In my case, I always left it in 'Source' mode and never saw the asp.net properties (and events) in Properties Dropdown. 在我的情况下,我总是将它保留在“源”模式中,并且从未在“属性下拉列表”中看到asp.net属性(和事件)。

The Design/Split/Soruce buttons are in the lower left of the text editor window pane. Design / Split / Soruce按钮位于文本编辑器窗口窗格的左下角。 在此输入图像描述

I haven't found a good answer for this anywhere on the web so here it is: 我在网上的任何地方都没有找到一个好的答案,所以这里是:

After playing around I noticed that the Events options in Properties disappears after you have started editing the file. 在玩完之后,我注意到在开始编辑文件后,属性中的事件选项消失了。 If you save or Ctrl+s then Visual Studio will reevaluate the page and realize its an actual ASP tag and give you the full properties with the events choices again. 如果您保存或按Ctrl + s,则Visual Studio将重新评估页面并实现其实际的ASP标记,并再次为您提供事件选项的完整属性。

You do not have to use Designer. 您不必使用Designer。

The solution is very easy. 解决方案非常简单。

It is just simple,it just that you can not see the events in the source view, you have to just switch to the design view to see the events and double click them to generate events. 它很简单,只是您无法在源视图中看到事件,您只需切换到设计视图即可查看事件并双击它们以生成事件。 and again come to design view 并再次来设计视图

I have found this too, only it happens on every control. 我也发现了这一点,只有它发生在每一个控件上。

I found that if you are using "Source View", the events button is not shown in the properties window, but if you use design view and single click the control in design view (or "Both" view) then the events button is then shown in the properties window. 我发现如果您使用“源视图”,则事件按钮不会显示在属性窗口中,但是如果您使用设计视图并在设计视图(或“两个”视图)中单击控件,则会显示事件按钮显示在属性窗口中。

I suspect this is a bug in VS10? 我怀疑这是VS10中的一个错误? It's quite annoying as I don't like the Design view in VS, I always prefer Source view. 这很烦人,因为我不喜欢VS中的Design视图,我总是喜欢Source视图。

Can't speak for earlier versions of VS, but for 2013, after adding the element, Build the project. 不能代表VS的早期版本,但是对于2013年,添加元素后,构建项目。 Sometimes I have to switch to Design view and back to Source view once on the page, but then the events appear: 有时我必须在页面上切换到“设计”视图并返回“源”视图,但随后会显示以下事件:

在此输入图像描述

Click the lightning bolt icon for the events. 单击事件的闪电图标。 Double click SelectedIndexChanged and it creates this in the codebehind: 双击SelectedIndexChanged并在代码隐藏中创建它:

    protected void ddlChoice_SelectedIndexChanged(object sender, EventArgs e) {

    }

And adds the event handler to the markup: 并将事件处理程序添加到标记:

 <asp:DropDownList runat="server" ID="ddlChoice" OnSelectedIndexChanged="ddlChoice_SelectedIndexChanged" />

When using VS2012 this can be done without actually going into Design view. 使用VS2012时,无需实际进入设计视图即可完成。 I know the question is specifically for VS2010, but I can't test this answer myself. 我知道这个问题专门针对VS2010,但我不能自己测试这个答案。

In source view simply start adding the appropriate attribute, for example OnServerValidate on a CustomValidator . source视图中,只需开始添加适当的属性,例如在CustomValidator上添加OnServerValidate As soon as you type the = sign the very first item in the list is <Create new event> , which has the same function as double clicking the control. 只要键入=符号,列表中的第一项就是<Create new event> ,它具有与双击控件相同的功能。

If you want to create OnSelectedIndexChanged Event you can double click your DropDownList in design view. 如果要创建OnSelectedIndexChanged事件,可以在设计视图中双击DropDownList

if not try writing this : 如果没有尝试写这个:

myDropDownList.SelectedIndexChanged += 

and then press tab 2 times. 然后按Tab键2次。 so it will create event handler for you. 所以它会为你创建事件处理程序。 then you need to copy your handler name and paste it in your control markup. 然后你需要复制你的处理程序名称并将其粘贴到你的控制标记中。

Click on the ' Split ' view in MS Visual Studio - select a button in the ' Design ' view and then look into property window now. 单击MS Visual Studio中的“ 拆分 ”视图 - 在“ 设计 ”视图中选择一个按钮 ,然后立即查看属性窗口。 You should be able to see Events now. 你现在应该可以看到事件了。 Good luck. 祝好运。

At the top of your code page there are two comboboxes. 在代码页的顶部有两个组合框。 Choose your dropdownlist from the one on the left (It says "(General)" by default) and then choose your event from the one on the right one. 从左侧的下拉列表中选择您的下拉列表(默认情况下显示“(常规)”),然后从右侧的那个中选择您的事件。

It will create the event for you and so you can just add your code. 它将为您创建活动,因此您只需添加代码即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio 2008在Asp.NET中不显示事件按钮 - Visual Studio 2008 Does Not Show Events Button in Asp.NET Visual Studio 2010:ASP.Net项目中的数据源窗口? - Visual Studio 2010: Data Sources window in ASP.Net project? 在Windows 7 ASP.Net页上的IIS上,CSS的显示不正确,如在Visual Studio 2010中的嵌入式服务器中 - On IIS in Windows 7 ASP.Net pages CSS is not show correclty as In the embedded server in Visual Studio 2010 Visual Studio 2010(最终版本):ASP.NET Web服务-调试断点未命中。 无法调试 - Visual Studio 2010 (Ultimate): ASP.NET Web Service - Debug Breakpoint does not hit. Not able to Debug Visual Studio 2010和2012 ASP.Net调试和布局问题 - Visual Studio 2010 & 2012 ASP.Net debug & layout issues 向asp.net添加样式表(使用Visual Studio 2010) - Adding a stylesheet to asp.net (using Visual Studio 2010) visual studio 2010 asp.net gridview不是一个已知的元素 - visual studio 2010 asp.net gridview is not a known element Visual Studio 2010缺少ASP.NET项目模板吗? - Visual Studio 2010 missing ASP.NET projects templates? 使用Visual Studio 2010进入asp.net中的类库 - Step into a class library in asp.net using visual studio 2010 未知服务器标签ASP.NET 2.0 Visual Studio 2010 - Unknown Server tag ASP.NET 2.0 Visual Studio 2010
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM