0

Why does it happen (only some times) that when I add an event handler to a control it doesn't give the intellisense option to generate a new event handler. This results in Visual studio 2012 not creating the code in the background to associate the control with the event.

I can go an manually create the event, but like I said, it creates other background code to associate the control with that event handler.

asp.net

 <asp:DropDownList ID="drpdwnRecordId" runat="server" Visible="false" OnSelectedIndexChanged="MyOwnEventHandler_OnSelectedIndexChanged">
        <asp:ListItem Text="Please Select a Record ID" Value="nothing"></asp:ListItem>
    </asp:DropDownList>

c#

  protected void MyOwnEventHandler_OnSelectedIndexChanged(object sender, EventArgs e)
        {

        }

Why is this happening? How can I fix this, or is there a way that I can go and write that background code myself (and is it a good idea?)

Ruan
  • 3,969
  • 10
  • 60
  • 87
  • What would you like to do in `OnSelectedIndexChanged` event ? You may need to use `Update Panel` , or add `AutoPostBack="true"` :) – zey May 31 '13 at 10:08
  • You show follow this link > http://stackoverflow.com/q/341080/1427849 – zey May 31 '13 at 10:25

2 Answers2

0

If you put it in the ui page it will generate all the code needed to call the function at compile time. You have to compile your project for that code to be created.

There should be no additional code needed (written by you) besides what you show here.

Hogan
  • 69,564
  • 10
  • 76
  • 117
0

You can go to Code Behind by Right Clicking page (.aspx,.ascx) and select View code. You can assosiate your event in OnInit or OnLoad method.

But you must have definition of your control in that page!

DropDownList dropdwnRecordId;

protected void override OnLoad(...)
{
    dropdwnRecordId.SelectedIndexChanged += YourHandler;
}

Regards, Dmitry.

StNickolas
  • 576
  • 7
  • 20