HTML Select控件需要在asp.net中回发 [英] HTML Select Control Needs to Postback in asp.net

查看:86
本文介绍了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.

推荐答案

您不能直接使用HTML标记进行回发,而是建议使用Asp.net服务器控件集AutoPostBack= true并应用CSS或将Theme定义为根据要求.
仍然,如果您想使用HTML标记并希望进行回发,则可以编写javascript并处理onchage()并调用__doPostBack(),如下所示:


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:


<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.




你可以试试这个

Hi,

You can try this

<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中回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆