First Item in dropdownlist doesn't fire SelectedIndexChanged at all

后端 未结 7 2169
盖世英雄少女心
盖世英雄少女心 2021-02-20 12:24

I have following simple code:

<%@ Page Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"testForm.aspx.cs\" Inherits=\"Orbs.testForm\" %>

         


        
7条回答
  •  温柔的废话
    2021-02-20 12:45

    I solved the problem myself,

    I read somewhere that turning off the ViewStateMode will cause DropDownListnot work properly. In my web application I had to turn off ViewStateMode to achieve some global task and turn it on case by case.

    Somehow turning on ViewStateMode on DropDownList is not working, I even tried turning on ViewStateMode for page and master page but still DropDownList didn't work. it only worked when I turned on ViewStateMode in web.config.

    As turning on ViewStateMode in web.config is not an option, I found and alternate solution. I'm including it here hoping it help someone.

    • Add a HiddenField to your form.
    • In Page_Load compare value of HiddenField with Request.Forms[DropDownList1.UniqueID]
    • if they are different, call SelectedIndexChanged manually
    • Set the value of HiddenField to value of Request.Forms[DropDownList1.UniqueID].

提交回复
热议问题