Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear All,

I have used the HTML select Control in my application for look and feel purpose instead of use the Asp.net dropdownlist control.

Now I'm not able to post back the data when the user select the item in the Select Control.

On the Post back, I need to call the server side function in the Onchange() event.

Please help me to do this . Thanks.
Posted
Updated 18-Oct-11 19:22pm
v2

You can not make Postback directly using the HTML tag, rather i suggest use Asp.net server control set AutoPostBack= true and apply CSS OR define Theme as per the requirement..
still if you want to use HTML tag and want to make postback then you can write javascript and handle onchage() and call __doPostBack() as shown below:


HTML
<select id="cmbID" name="cmbname" onchange="CmbChange();">
    <option value="Option1">Option1</option>
    <option value="Option2">Option2</option>
</select>


Javascript:
JavaScript
function CmbChange(obj) {
         var cmbValue = document.getElementById("cmbID").value;
         __doPostBack('cmbID', cmbValue);
     }


When __doPostBack() fires on client side, it will cause a postback, and using Request.params object we can get the parameters which we passed from the javascript code.

Request.params looks like {__EVENTTARGET=cmbID&__EVENTARGUMENT=Option2}

server side code:

C#
protected void Page_Load(object sender, EventArgs e)
     {
         if (Page.IsPostBack)
         {
             string controlID = Request.Params["__EVENTTARGET"].ToString();
             object controlValue = Request.Params["__EVENTARGUMENT"].ToString();
         }
     }


Hope this will solve your problem.
 
Share this answer
 
v3
Comments
JQuery Geeks 24-Oct-11 1:34am    
Nice solution
Hi,

You can try this

HTML
<select id="slct" onchange="f1()">
    <option value ="fdgdfg">dfgdfg</option>
    <option value ="fdgdfg">dfgdfg</option>
    <option value ="fdgdfg">dfgdfg</option>
  </select>


In javascript you've to write following method

JavaScript
function f1() {
          form1.submit();
      }


All the Best
 
Share this answer
 

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



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