0

The auto post back for my drop down list is not hitting the break point in the code behind. It appears that changing the value of the drop down list is not causing the post back at all.

<asp:DropDownList ID="RidingType" runat="server" CssClass="option" DataValueField="VarId" DataTextField="Name" AutoPostBack="true" OnSelectedIndexChanged="RidingType_SelectedIndexChanged"></asp:DropDownList>

I have tried both OnSelectedIndexChanged and OnTextChanged. I am doing something similar on a different page, where it does work as expected.

<asp:DropDownList CssClass="listBoxes" runat="server" ID="lstBrands" DataValueField="brand" DataTextField="brand" AutoPostBack="true" OnTextChanged="lstBrands_SelectedIndexChanged" Width="100%"></asp:DropDownList>

I've done everything I can to match up the surrounding environments. Any ideas as to why the first appears not to post back and the second works correctly?

Edit: Here is an excerpt from the code behind the binding function

protected void Page_Load(object sender, EventArgs e)
{
    if(!Page.IsPostBack)
    {
         /* code to set up other drop down lists */
         BindRidingType();
         /* more of the same */
    }
}

private void BindRidingType()
{
    prams[3].Value = "Riding Type";
    RidingType.DataSource = ReturnSelection(prams); //return DataTable from Database   
    RidingType.SelectedValue = DefaultValue("Riding Type"); //Finds default value for list
    RidingType.DataBind();        
}

Per suggestion I tried not setting a default value, but I saw no change.

Edit: The event handler as requested

 protected void RidingType_SelectedIndexChanged(object sender, EventArgs e)                   
{
    throw new NotImplementedException();
}
Red Gordon
  • 43
  • 9
  • I have tried both of your code and its work fine with me autopostback hit breakpoint in both cases – Pankaj Toshniwal Nov 16 '17 at 07:14
  • Are you perhaps binding data to the DropDownList without an `IsPostBack` check? – VDWWD Nov 16 '17 at 07:45
  • @VDWWD no, the function binding each drop down is within an if(!Page.IsPostBack) block. I've done my best to make the 2 cases match, but the non-working drop down is on a page with many other drop down all using the same parametered query, so that query has its own function, returning a DataTable. Could that perhaps be the issue? – Red Gordon Nov 16 '17 at 17:45
  • I've transplanted the reused code into the binding function and it makes no difference. – Red Gordon Nov 16 '17 at 17:54
  • Are you setting the SelectedValue to a default value in page load? When you do the DropDownList does not change and will not trigger the method. – VDWWD Nov 16 '17 at 19:41
  • @VDWWD changing the value in the drop down doesn't appear to be causing a post back. I am setting a default value, but the Page_Load isn't being hit a second time. – Red Gordon Nov 16 '17 at 20:56
  • please show the code behind event handler and where the break point is – DaniDev Nov 16 '17 at 22:37
  • @DaniDev I reduced the event handler for testing – Red Gordon Nov 17 '17 at 17:38
  • Presumably the break point is located in the RidingType_SelectedIndexChanged and you are still not hitting it ? If that is the case then put a break point in the beginning of your Page_Load it most certainly will hit there and then you can go line by line using F10 to see where you are getting to before hitting the desired eventhandler. you can also add and else{} to your if(!Page.IsPostBack) – DaniDev Nov 17 '17 at 18:07
  • @DaniDev yes, I put the break point in Page_Load as well. It is also not being hit when the drop down is changed. As far as I can tell, this drop down is not prompting a post back at all. Is there some other part of the web page that could prevent the post back? – Red Gordon Nov 17 '17 at 23:13
  • was wondering what happened :-). There could be several reasons. A likely culprit is some helper .js file . e.g. https://stackoverflow.com/questions/4324034/asp-net-button-not-raising-postback You will have to show your entire page, bro. – DaniDev Nov 17 '17 at 23:22
  • Basically, the post back mechanism relies on JS that asp control imbed in your page output if there is any malformed JS anytime run prior to the postback event it can cause your post back to not run. – DaniDev Nov 17 '17 at 23:45
  • I don't know if this changes anything, but there is a button later in the page that successfully does a postback – Red Gordon Dec 14 '17 at 00:48

0 Answers0