<%@ 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>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事件
<%@ 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>
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 + " ', ' ');}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();
}
}运行时 提示 Microsoft JScript runtime error: '__doPostBack' is undefined莫非这是一BUG?
解决方案 »
- 怎么执行的,事件是在哪里注册的
- falshFXP 网站远程发布是连接超时?
- 请达人指点:asp.net页面如何给获得Asp接口变量值?
- session 超时的问题
- web.sitemap文件有什麽用?
- sharepoint2003 开发webpart问题
- 关于显示文件,求助!!!!!!
- 求救:连接数据库出错(未处理的“System.InvalidOperationException”类型的异常出现在 system.data.dll 中。)
- vs2012 新建项目失败,提示注册表问题
- B/S 模式 实现类似 socket通信
- 重置 session 过期时间
- ckeditor怎样更改皮肤?改不了啊
是.NET 的服务器控件产生的。 所以要使用此函数,必须整个页面上至少要有一个控件 可以回传页面。有些控件 的autoPostBack 必须设为TRUE。so this problem is solve. thanks, everyone
是.NET 的服务器控件产生的。 所以要使用此函数,必须整个页面上至少要有一个控件 可以回传页面。有些控件 的autoPostBack 必须设为TRUE。so this problem is solve. thanks, everyone