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. 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. In my case, I always left it in 'Source' mode and never saw the asp.net properties (and events) in Properties Dropdown.
The Design/Split/Soruce buttons are in the lower left of the text editor window pane.
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.
You do not have to use 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
If you want to create OnSelectedIndexChanged
Event you can double click your DropDownList
in design view.
if not try writing this :
myDropDownList.SelectedIndexChanged +=
and then press tab 2 times. so it will create event handler for you. then you need to copy your handler name and paste it in your control markup.
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? It's quite annoying as I don't like the Design view in VS, I always prefer Source view.
Can't speak for earlier versions of VS, but for 2013, after adding the element, Build the project. 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:
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. I know the question is specifically for VS2010, but I can't test this answer myself.
In source
view simply start adding the appropriate attribute, for example OnServerValidate
on a CustomValidator
. 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.
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.
Click on the 'Split' view in MS Visual Studio - select a button in the 'Design' view and then look into property window now. You should be able to see Events now. Good luck.
精彩评论