【问题标题】:Control not reflecting updates控件不反映更新
【发布时间】:2011-02-02 20:44:22
【问题描述】:

我有一个母版页,上面有一个更新面板。我正在处理的应用程序的其中一个页面有一个自定义控件,上面有一些 asp:textboxes。该控件也有一个gridview。

当单击一行的 asp:linkbutton 时,OnRowCommand 事件会触发并正确执行其魔法,其中一部分是设置 asp:textbox 的“Text”属性。这行得通。

我的问题是更新没有反映在 UI 中。

更新面板:

<asp:ScriptManager ID="scriptManager" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="updPanel" runat="server">
        <ContentTemplate>
              [...more code...]

链接按钮:

 <ItemTemplate>
         <asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("ID")%>' CommandName="EDIT" runat="server">Edit</asp:LinkButton>     
</ItemTemplate>

事件处理程序:

protected void RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "EDIT":
                    //stuff happens here
                    [ASP:Textbox].Text = [Result of stuff that happened];
                     ^this is what isn't reflected on the page
                    break;

我知道我在页面生命周期中遗漏了一些东西,但我正在画一个空白。

【问题讨论】:

    标签: asp.net updatepanel page-lifecycle rowcommand


    【解决方案1】:

    只花了几个小时。

    看起来,只有在“编辑”(以及任何其他标准命令)以外的其他内容上设置了 CommandName 属性时,才会反映更改。尝试将其设置为“EditThis”,它对我有用。

    【讨论】:

    • 天哪。几个月前我自己经历过这个。在ListView 中保留了实现内置功能的CommandNames。不幸的是,如果您设置的命令名称等于其中一个,MS 设计团队认为不适合抛出任何类型的异常,即使它不会在您的特定设计中导致任何操作。这是一个相当大的前额拍板,直到我真正浏览了 MS 的源代码以了解为什么没有引发任何事件时,我才弄清楚这一点。老实说,我不确定他们为什么会阻止该事件,即使它在内部做了什么。非常混乱。
    • 天哪!直到明天我才能更改此内容,但感谢您发布!如果它有效,我会回来并“接受”答案。再次感谢!
    【解决方案2】:
    protected void RowCommand(object sender, GridViewCommandEventArgs e)
            {
                switch (e.CommandName)
                {
                    case "EDIT":
                        //stuff happens here
                        [ASP:Textbox].Text = [Result of stuff that happened];
                         ^this is what isn't reflected on the page
                        // ADD THIS
                        updPanel.Update();
                        break;
    

    【讨论】:

    • 试过了,没有骰子。在调试器中,我可以看到文本框设置为正确的值,但 UI 永远不会更新。
    猜你喜欢
    • 2016-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-01
    • 2011-05-24
    • 1970-01-01
    • 2012-05-14
    相关资源
    最近更新 更多