DropDownList的SelectedIndexChanged事件,由JS提交执行。怎么做?
<asp:DropDownList ID="ddlList" runat="server" AutoPostBack="True" onselectedindexchanged="ddlList_SelectedIndexChanged">
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="JavaScriptCallServerEvent.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlList" runat="server" AutoPostBack="True" onselectedindexchanged="ddlList_SelectedIndexChanged">
<asp:ListItem Value="0">请选择</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<%--<input id="Button2" type="button" value="button" onclick="javascript:document.getElementById('<%=this.ddlList.ClientID%>').onchange();" />--%>
<input id="Button2" type="button" value="button" onclick="javascript:<%=this.SC %>;" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace JavaScriptCallServerEvent
{
public partial class Default : System.Web.UI.Page
{
public string CS;
protected void Page_Load(object sender, EventArgs e)
{
ClientScriptManager csm = this.ClientScript;
CS = csm.GetPostBackEventReference(ddlList, null);
Response.Write(CS);
Response.End();
if (!Page.IsPostBack)
{
CS = csm.GetPostBackEventReference(ddlList, null);
}
else
{
Response.Write("postback");
}
}
protected void ddlList_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write("A");
Response.Write((sender as DropDownList).SelectedValue);
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
}
------解决方案--------------------
http://www.google.com.hk/search?hl=zh-CN&newwindow=1&safe=strict&sa=X&ei=e7DlT4ubGu6SiQfM1ehZ&ved=0CEkQvwUoAQ&q=ipostbackeventhandler+dropdownlist+getpostbackeventreference&spell=1&biw=1364&bih=707
------解决方案--------------------