母版页中的脚本管理器和用户控件中的更新面板。 部分回发未发生

发布于 2024-07-24 22:15:29 字数 2160 浏览 6 评论 0原文

我有一个带有以下 scriptmanager 标签的母版页:

<asp:ScriptManager ID="scriptManger" EnablePartialRendering="true" runat="server" >
    <Scripts>
        <asp:ScriptReference Path="~/common/js/jquery-1.3.2.js" />
        <asp:ScriptReference Path="~/common/js/validation.js" />
    </Scripts>
</asp:ScriptManager>

我的 aspx 页面是:

    <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/common/MasterPages/Login.master" CodeBehind="SecurityQuestionsEnroll.aspx.cs" Inherits="Login.SecurityQuestionsEnroll" %>

    <%@ Register src="~/controls/Views/Login/SecurityQuestions.ascx" tagname="SecurityQuestions" tagprefix="uc1" %>

这是用户控件:

  <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="always"  >
<ContentTemplate>  
    <asp:DataList ID="dlSecurityQuestions" runat="server" AutoPostBack="true" OnSelectedIndexChanged ="dlSecurityQuestions_SelectedIndexChanged">
        <ItemTemplate>
            <div>
                <asp:Label ID="lbl_question" AssociatedControlID="lst_question" runat="server"><%# DataBinder.Eval(Container.DataItem, "QuestionName")%></asp:Label>
                <asp:DropDownList ID="lst_question" runat="server" AutoPostBack="true" >
                    <asp:ListItem Value="0">Select a Question...</asp:ListItem>
                    <asp:ListItem Value="1">Select a Question1..</asp:ListItem>
                </asp:DropDownList>
            </div>
            <div>
                <asp:Label ID="lbl_answer1" AssociatedControlID="txt_answer" runat="server">Answer *</asp:Label>
                <asp:TextBox ID="txt_answer" runat="server" />
                <div id="validate"></div>
            </div>
        </ItemTemplate>
    </asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>  

我已经尝试了谷歌推荐的大部分选项,但我无法进行部分回发。 每次选定索引更改时,它都会进行整页回发。 正如您所看到的,下拉菜单位于项目模板中并且是重复的。 您认为我做错了什么,它不触发更新面板的回发。

i have a master page with following scriptmanager tag:

<asp:ScriptManager ID="scriptManger" EnablePartialRendering="true" runat="server" >
    <Scripts>
        <asp:ScriptReference Path="~/common/js/jquery-1.3.2.js" />
        <asp:ScriptReference Path="~/common/js/validation.js" />
    </Scripts>
</asp:ScriptManager>

My aspx page is :

    <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/common/MasterPages/Login.master" CodeBehind="SecurityQuestionsEnroll.aspx.cs" Inherits="Login.SecurityQuestionsEnroll" %>

    <%@ Register src="~/controls/Views/Login/SecurityQuestions.ascx" tagname="SecurityQuestions" tagprefix="uc1" %>

and this is the user control:

  <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="always"  >
<ContentTemplate>  
    <asp:DataList ID="dlSecurityQuestions" runat="server" AutoPostBack="true" OnSelectedIndexChanged ="dlSecurityQuestions_SelectedIndexChanged">
        <ItemTemplate>
            <div>
                <asp:Label ID="lbl_question" AssociatedControlID="lst_question" runat="server"><%# DataBinder.Eval(Container.DataItem, "QuestionName")%></asp:Label>
                <asp:DropDownList ID="lst_question" runat="server" AutoPostBack="true" >
                    <asp:ListItem Value="0">Select a Question...</asp:ListItem>
                    <asp:ListItem Value="1">Select a Question1..</asp:ListItem>
                </asp:DropDownList>
            </div>
            <div>
                <asp:Label ID="lbl_answer1" AssociatedControlID="txt_answer" runat="server">Answer *</asp:Label>
                <asp:TextBox ID="txt_answer" runat="server" />
                <div id="validate"></div>
            </div>
        </ItemTemplate>
    </asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>  

I have tried most of the options which google recommends, but i am not able to do a partial postback. evry time selectedindex is changed it does a full page postback. the drop down as you can see is in a itemtemplate and is repeated.
what do you think I am doing wrong that its not firing postback of just the update panel.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

木格 2024-07-31 22:15:29

如果您有更新面板但没有脚本管理器,则此方法有效:

<asp:ScriptManager ID="scriptManger" EnablePartialRendering="true" runat="server" >

</asp:ScriptManager>

但我也有一个母版页。 所以我想知道是不是因为母版页我需要脚本管理器

This works if you have an update Panel but no Script Manager:

<asp:ScriptManager ID="scriptManger" EnablePartialRendering="true" runat="server" >

</asp:ScriptManager>

But I also have a master page. So I wonder is it because of the Master page that I require the Script Manager

手长情犹 2024-07-31 22:15:29

我构建了一个小测试项目来稍微模仿您的文件。 我没有使用 DataList,并且我已将需要更新的区域移至单独的 div 中(这意味着如果您保留 DataList,我认为您的问题/答案不会像您那样位于 DataList 内现在,我构建的示例只是从下拉列表中获取文本,并使用用户选择的选项更新 UpdatePanel 中的文字,

这是我的代码:

MasterPage:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="UpdatePanelTest.Site1" %>

<!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>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scriptManger" EnablePartialRendering="true" runat="server" >
        <Scripts>
            <asp:ScriptReference Path="~/common/js/jquery-1.3.2.min.js" />
        </Scripts>
    </asp:ScriptManager>

    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>


    </form>
</body>
</html>

默认页面(代码中没有其他代码) 。后面):

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="UpdatePanelTest.Default" %>
<%@ Register src="Selector.ascx" tagname="Selector" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <uc1:Selector ID="Selector1" runat="server" />

</asp:Content>

用户控制(Html):

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Selector.ascx.cs" Inherits="UpdatePanelTest.Selector" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="always"  >
<ContentTemplate>  
    <asp:DropDownList ID="lst_question" runat="server" AutoPostBack="true" 
    onselectedindexchanged="lst_question_SelectedIndexChanged" >
        <asp:ListItem Value="0">Option 1</asp:ListItem>
        <asp:ListItem Value="1">Option 2</asp:ListItem>
    </asp:DropDownList>

    <div>
        <asp:Literal ID="Literal1" runat="server"></asp:Literal>
    </div>
</ContentTemplate>
</asp:UpdatePanel>

用户控制(代码隐藏):

using System;
using System.Web.UI.WebControls;

namespace UpdatePanelTest
{
    public partial class Selector : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void lst_question_SelectedIndexChanged(object sender, EventArgs e)
        {
            var ddl = sender as DropDownList;
            Literal1.Text = "You selected " + ddl.SelectedItem.Text;
        }
    }
}

I built a little test project that mimics your files a little bit. I'm not using a DataList and I've moved the area that needs to be updated into a seperate div (meaning that if you keep the DataList, I don't think your question/answer would be located inside the DataList the way you have it now. So right now, the sample I built just grabs the text from a drop down list and updates a literal in the UpdatePanel with the option the user selected.

Here's my code:

MasterPage:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="UpdatePanelTest.Site1" %>

<!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>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scriptManger" EnablePartialRendering="true" runat="server" >
        <Scripts>
            <asp:ScriptReference Path="~/common/js/jquery-1.3.2.min.js" />
        </Scripts>
    </asp:ScriptManager>

    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>


    </form>
</body>
</html>

Default page (no additional code in code-behind):

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="UpdatePanelTest.Default" %>
<%@ Register src="Selector.ascx" tagname="Selector" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <uc1:Selector ID="Selector1" runat="server" />

</asp:Content>

User Control (Html):

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Selector.ascx.cs" Inherits="UpdatePanelTest.Selector" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="always"  >
<ContentTemplate>  
    <asp:DropDownList ID="lst_question" runat="server" AutoPostBack="true" 
    onselectedindexchanged="lst_question_SelectedIndexChanged" >
        <asp:ListItem Value="0">Option 1</asp:ListItem>
        <asp:ListItem Value="1">Option 2</asp:ListItem>
    </asp:DropDownList>

    <div>
        <asp:Literal ID="Literal1" runat="server"></asp:Literal>
    </div>
</ContentTemplate>
</asp:UpdatePanel>

User Control (Code-behind):

using System;
using System.Web.UI.WebControls;

namespace UpdatePanelTest
{
    public partial class Selector : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void lst_question_SelectedIndexChanged(object sender, EventArgs e)
        {
            var ddl = sender as DropDownList;
            Literal1.Text = "You selected " + ddl.SelectedItem.Text;
        }
    }
}
忘东忘西忘不掉你 2024-07-31 22:15:29

我在 UpdatePanel 定义中看到 - 这需要如果您希望 UpdatePanel 异步工作,则为 UpdateMode="Conditional"。 不知道为什么 ASP:NET 开发人员一开始没有将其设置为默认条件(我有时仍然忘记它)。

也许已经是这样了?

I see <asp:UpdatePanel ID="id" runat="server" ChildrenAsTriggers="true" UpdateMode="always" > in your UpdatePanel definition - this needs to be UpdateMode="Conditional" if you want your UpdatePanel to work asynchronously. No idea why the ASP:NET devs didn't set it to Conditional as a default in the first place (I still sometimes forget it).

Maybe that's already it?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文