0

I have a problem in firing a dropdownlist event.

I have the following dropdown:

asp:dropdownlist id="ddlhello" Runat="server" AutoPostBack="True"  onchange="javascript:return ChangeHeader();"

I have also added an event in the code behind i.e. selectedindex change event.

Now the problem occurs when I execute the page: it executes javascript but the server side code does not fire. If I remove this line onchange="javascript:return ChangeHeader();" then the server side code fires.

When I checked the source page it shows me two onchange events associated: one for javascript and other for server side.

I think that it is picking client side code and neglects server side.

I am not pretty sure, so I want to know the behavior reason.

And what is the way out for this.

I want server and client side code to be executed. I have searched for solutions but I have not found any correct reason.

Please help me.

2 Answers 2

1

You can not bind the server side event with dropdown, bind it with onselectedindexchanged

onselectedindexchanged="DropDownList1_SelectedIndexChanged"

<asp:dropdownlist id="ddlhello" Runat="server" AutoPostBack="True"   onselectedindexchanged="DropDownList1_SelectedIndexChanged" onchange="javascript:return ChangeHeader();" </asp:dropdownlist>

Returning false from client stops the postback.

function ChangeHeader()
{
 //return false; // will stop the postback
  return true; //will cause postback
}
Sign up to request clarification or add additional context in comments.

1 Comment

i have returned true still it is not firing event.
0

Use like following instead of onchange="return ChangeHeader();" onchange="ChangeHeader();"

I hope this can help you.

1 Comment

Whoever down voted this for whatever reason, please provide a reason for that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.