3

Is it possible to cause a postback to an action from changing your selection in a dropdown list without using JavaScript?

I remember when using the ASP.NET Forms dropdown list control, there was a property that when set would cause a postback on change, did this work without JS? - If so, how?

Many thanks, Kohan.

4 Answers 4

6

You can achieve the postback effect using jQuery. JavaScript in some form or another is required for automatic postbacks. Even ASP.NET uses JavaScript in the background to implement the AutoPostBack property.

<script type='text/javascript'\> 
  $('#dropDown').change(function () {
    $(this).parents('form').submit();
  });
</script>
Sign up to request clarification or add additional context in comments.

Comments

4

You need JavaScript to automatically post back data. You don't have to write it, but you still need it. You can post without JavaScript (someone pressing a submit button), but not automatically.

I believe what you are thinking of is the AutoPostBack property.

4 Comments

RE: AutoPostBack, Yes i was, does it not work with Javascript disabled?
Silly question, What i meant to say is what does it do with javascript disabled. Fail silently?
Yes, that it does do. Now this does partially depend on the page. If you have no way to submit it without the autopostback from firing then the page is pretty much useless, but asp.net does gracefully degrade.
Also, you add a button in a <noscript> tag so that the users without javascript can make the form post. People with javascript can then use it as it was intended
1

Do this:

More here:

How do you submit a dropdownlist in asp.net mvc

Comments

1

Complete script which worked for me

 @Html.DropDownList("Projects", Model.Projects, new { 
 style = "Height: 25px; width: 225px;", 
 onchange = "$(this).parents('form').submit();" })

Comments

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.