我在内容页面内遇到更新面板的问题,如果我将它们放在内容页面上的UpdatePanel中,我的控件如按钮事件就不会触发。
以下是我的Master& amp;的结构。内容页面。
ON主页我正在使用更新面板进行电子邮件注册,这在主页面上工作正常。但是当我尝试在内容/子页面上添加更新面板时,按钮事件不会因为soem原因而触发。我看过几个例子,但似乎没什么用。
下面是两页的结构,不确定我做错了什么
MASTER PAGE
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MainMP.master.cs" Inherits="MainMP" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
<!-- -->
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
<!-- -->
</head>
<body>
<form id="form2" runat="server">
<asp:ScriptManager runat="server" EnablePageMethods="true">
<Scripts>
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" />
</Scripts>
</asp:ScriptManager>
<!-- Page Content-->
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<!-- Page Content -->
</form>
</body>
</html>
内容页
<%@ Page Title="" Language="C#" MasterPageFile="~/MainMP.master" AutoEventWireup="true" CodeFile="Blog.aspx.cs" Inherits="Blog" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<!-- Some Page content ...... -->
<asp:UpdatePanel ID="updxxxx" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" >
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
答案 0 :(得分:0)
如果您的按钮位于更新面板之外,则需要在更新面板中将该按钮设置为触发器,以启动回发。
答案 1 :(得分:0)
可能是您可以按照以下方式进行测试,然后添加AjaxControlToolkit。
站长:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="SiteTest.master.cs" Inherits="ZeroBig.m_test.SiteTest" %>
<!DOCTYPE html>
<html>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
页:
<%@ Page Title="" Language="C#" MasterPageFile="~/m_test/SiteTest.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ZeroBig.m_test.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:UpdatePanel ID="updxxxx" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Page.cs
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "hello";
}
}