日期:2014-05-18  浏览次数:20482 次

莫非是.net一BUG
HTML code

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:DropDownList ID="DropDownList3" runat="server"  onselectedindexchanged="DropDownList3_SelectedIndexChanged">
            <asp:ListItem>choose</asp:ListItem>
        <asp:ListItem>delete</asp:ListItem>
        <asp:ListItem>save</asp:ListItem>
    </asp:DropDownList>

    <br />
    <br />
    <br />

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</asp:Content>



C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DropDownList3.Attributes.Add("onchange", "if(confirm(\'确认删除吗?\')){__doPostBack( ' " + DropDownList3.ClientID + " ', ' ');}else{return(false);} ");
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = "afasfasdfasdf";
    }
    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {
        Random ran = new Random();
        Label1.Text = "执行了后台事件" + ran.Next().ToString();
    }
}



上述代码可以执行dopostback事件

HTML code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!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>
        <br />
    <br />
    <br />
    <asp:DropDownList ID="DropDownList3" runat="server"  onselectedindexchanged="DropDownList3_SelectedIndexChanged">
            <asp:ListItem>choose</asp:ListItem>
        <asp:ListItem>delete</asp:ListItem>
        <asp:ListItem>save</asp:ListItem>
    </asp:DropDownList>

    <br />
    <br />
    <br />

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>




C# code

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DropDownList3.Attributes.Add("onchange", "if(confirm(\'确认删除吗?\')){__doPostBack( ' " + DropDownList3.ClientID + " ', ' ');