Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
On a dropdown list selection, I wanted a texbox and a dropdown to be enabled/disabled.. I used Jquery for functionality,

$(function() {
    $(".selectState").change(function() {
        if ($(this).find('option:selected').val() == "3") {
            alert("3");
            $(this).closest("tr").find(".ChallPrice").attr("disabled", false);
        } else {
            $(this).closest("tr").find(".ChallPrice").attr("disabled", true);
        }

    });
       });


Now on a button click (postback), Im losing the dropdown and text values and it is going empty.

Can someone help on this as how to retain the values on the postback
Posted

When Page posts back, all the controls are reset.

You can do one thing. On the Button Click, at server side read the values and store them in Session.

Read the values from Session whenever you want.
 
Share this answer
 
Comments
Member 10217959 10-Dec-13 13:20pm    
the drop down lists are in a gridview, how can I maintain sessions for these.

Because they may change one row A dropdown and instead of clicking in row A Save Button, they might click on row B Save button.
Do not postback the page on button click....

Handle the button click using jquery as well.

Plz ask for further queries....
 
Share this answer
 
Comments
Member 10217959 10-Dec-13 13:22pm    
I need to Save the transactions in database on the button click which needs a postback, how can I handle button click in jquery for database connection, not possible na :(
Jain Nishant 10-Dec-13 23:59pm    
Use Jquery selector for handling the button click and call an Ajax then. Then, u can save the transaction as well....
Post the form using JQuery ajax.This way you can prevent page refresh as well as can retain your data.On success call of JQuery ajax you can fetch current state value of the controls.For reference below is the link for JQuery ajax
http://api.jquery.com/jQuery.ajax/[^]
Hope this will sort out your difficulty.
 
Share this answer
 
v2
Comments
Member 10217959 10-Dec-13 13:21pm    
I tried using Hidden fields as well... the hidden fields are also going empty on postback :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900