验证(ASP.NET):属性'onclick'不是元素'dropdownlist'的有效属性。 [英] Validation (ASP.NET): attribute 'onclick' is not a valid attribute of element 'dropdownlist'.

查看:121
本文介绍了验证(ASP.NET):属性'onclick'不是元素'dropdownlist'的有效属性。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在onclick上试试这个下拉列表



我尝试过:



 <   asp:DropDownList     ID   =  DropDownList1    runat   =  server    

onselectedindexchanged = DropDownList1_SelectedIndexChanged

onclick = Loadchart(); >











但显示错误

验证(ASP.Net):属性'onclick'不是元素'DropDownList'的有效属性。



我在页面加载时调用此下拉列表

 DropDownList1.DataSource = getyear(); 
DropDownList1.DataTextField = year;
DropDownList1.DataValueField = year_id;
DropDownList1.DataBind();





当我构建时显示错误任何解决方案

解决方案

< blockquote>从标记中删除该事件并在页面中添加绑定事件后面的代码

load。

但是, onchange 事件应该对Dropdownlist事件有帮助。无论如何它符合你的要求。



 <   asp:dropdownlist     id   =  DropDownList1    runat   = 服务器   >  
OnSelectedIndexChanged =DropDownList1_SelectedIndexChanged> < / asp:dropdownlist >





CS



  protected   void  Page_Load( object  sender,EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Attributes.Add( < span class =code-string> onclick, Loadchart(); );
}
}


i try this dropdown list with onclick

What I have tried:

<asp:DropDownList ID="DropDownList1" runat="server" 

    onselectedindexchanged="DropDownList1_SelectedIndexChanged"

     onclick="Loadchart();">






but this shows error
Validation (ASP.Net): Attribute 'onclick' is not a valid attribute of element 'DropDownList'.

where as i call this dropdown on page load

DropDownList1.DataSource = getyear();
               DropDownList1.DataTextField = "year";
               DropDownList1.DataValueField = "year_id";
               DropDownList1.DataBind();



When i build this shows error any solution

解决方案

Remove that event from mark up and add bind the event from code behind during page
load.
however, onchange event should helpful in case of Dropdownlist events. anyhow its upto your requirement.

<asp:dropdownlist id="DropDownList1" runat="server" >
         OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:dropdownlist>



CS

protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              DropDownList1.Attributes.Add("onclick", "Loadchart();");
          }
      }


这篇关于验证(ASP.NET):属性'onclick'不是元素'dropdownlist'的有效属性。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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