本文介绍了HTML Select控件需要在asp.net中回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我已在我的应用程序中使用HTML select控件用于外观目的,而不是使用Asp.net dropdownlist控件.

现在,当用户在选择控件"中选择项目时,我将无法回传数据.

在回发上,我需要在Onchange()事件中调用服务器端函数.

请帮助我做到这一点.

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.

推荐答案

<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);
     }



__doPostBack()在客户端触发时,将导致回发,并且使用Request.params对象,我们可以获得从javascript代码传递的参数.

Request.params看起来像{__EVENTTARGET=cmbID&__EVENTARGUMENT=Option2}

服务器端代码:



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:

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.


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



在javascript中,您必须编写以下方法



In javascript you''ve to write following method

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



最好的



All the Best


这篇关于HTML Select控件需要在asp.net中回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 00:52
查看更多