Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Intellisense告诉我更新面板的UpdateMode属性需要设置为Conditional,即使它是_C#_Asp.net_Ajax - Fatal编程技术网

C# Intellisense告诉我更新面板的UpdateMode属性需要设置为Conditional,即使它是

C# Intellisense告诉我更新面板的UpdateMode属性需要设置为Conditional,即使它是,c#,asp.net,ajax,C#,Asp.net,Ajax,我有一个ASP.Net更新面板,其中包含我试图从代码隐藏文件中更新的控件,方法是将控件的值设置为我想要的值,然后调用UpdatePanel的Update()方法 我知道要调用Update()方法,我需要将UpdateMode属性设置为conditional,所以这就是我所做的,但不管怎样,我都会得到以下错误: 当UpdateMode设置为Conditional时,只能对ID为“UpdatePanel1”的UpdatePanel调用Update方法 “我的属性”框如下所示: using Syste

我有一个ASP.Net更新面板,其中包含我试图从代码隐藏文件中更新的控件,方法是将控件的值设置为我想要的值,然后调用UpdatePanel的
Update()
方法

我知道要调用Update()方法,我需要将UpdateMode属性设置为conditional,所以这就是我所做的,但不管怎样,我都会得到以下错误:

当UpdateMode设置为Conditional时,只能对ID为“UpdatePanel1”的UpdatePanel调用Update方法

“我的属性”框如下所示:

using System;
using System.Timers;

namespace WebApplication2
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var myTimer = new System.Timers.Timer();
            myTimer.Interval = 1000;

            myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);

            myTimer.Start();
        }

        void myTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var newGUID = Guid.NewGuid().ToString();
            Label1.Text = newGUID;
            UpdatePanel1.Update();
        }
    }
}

我的代码如下所示:

using System;
using System.Timers;

namespace WebApplication2
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var myTimer = new System.Timers.Timer();
            myTimer.Interval = 1000;

            myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);

            myTimer.Start();
        }

        void myTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var newGUID = Guid.NewGuid().ToString();
            Label1.Text = newGUID;
            UpdatePanel1.Update();
        }
    }
}
我的表单如下所示:

using System;
using System.Timers;

namespace WebApplication2
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var myTimer = new System.Timers.Timer();
            myTimer.Interval = 1000;

            myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);

            myTimer.Start();
        }

        void myTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var newGUID = Guid.NewGuid().ToString();
            Label1.Text = newGUID;
            UpdatePanel1.Update();
        }
    }
}

我的标记如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>

<!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>
    <style type="text/css">
        #form1
        {
            text-align: center;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" style="text-align: center" Text="Label"></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>

#表格1
{
文本对齐:居中;
}
为什么这不起作用


谢谢

Designer
模式下查看页面,并将其重命名,保存即可。这很可能是VS的缓存问题,切换设计器模式会强制控件在“设计”模式下渲染,因此它应该在后台更新代码以清除错误。

设计器
模式下查看页面并重命名它,保存,然后就可以开始了。这很可能是VS的缓存问题,切换设计器模式会强制控件以“设计”模式渲染,因此它应该在后台更新代码以清除错误。

我建议您检查。使用的计时器控件是
System.Web.UI.Timer
,而不是代码中的
System.Timers.Timer
。此外,计时器必须放置在更新面板中,以便在触发
OnTick
事件时触发AJAX调用:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="C#" %>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script runat="server" type="text/c#">
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        Label1.Text = "Panel refreshed at: " + DateTime.Now.ToLongTimeString();
    }
</script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" id="ScriptManager1" />

        <asp:UpdatePanel runat="server" id="UpdatePanel1">
        <ContentTemplate>
            <asp:Timer runat="server" id="Timer1" Interval="1000" OnTick="Timer1_Tick" />
            <asp:Label runat="server" Text="Page not refreshed yet." id="Label1" />
        </ContentTemplate>
        </asp:UpdatePanel>

        <asp:Label runat="server" Text="Label" id="Label2"></asp:Label>
    </form>
</body>
</html>

受保护的无效计时器1_刻度(对象发送方,事件参数e)
{
Label1.Text=“面板刷新时间:”+DateTime.Now.ToLongTimeString();
}

我建议您检查。使用的计时器控件是
System.Web.UI.Timer
,而不是代码中的
System.Timers.Timer
。此外,计时器必须放置在更新面板中,以便在触发
OnTick
事件时触发AJAX调用:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Page Language="C#" %>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script runat="server" type="text/c#">
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        Label1.Text = "Panel refreshed at: " + DateTime.Now.ToLongTimeString();
    }
</script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" id="ScriptManager1" />

        <asp:UpdatePanel runat="server" id="UpdatePanel1">
        <ContentTemplate>
            <asp:Timer runat="server" id="Timer1" Interval="1000" OnTick="Timer1_Tick" />
            <asp:Label runat="server" Text="Page not refreshed yet." id="Label1" />
        </ContentTemplate>
        </asp:UpdatePanel>

        <asp:Label runat="server" Text="Label" id="Label2"></asp:Label>
    </form>
</body>
</html>

受保护的无效计时器1_刻度(对象发送方,事件参数e)
{
Label1.Text=“面板刷新时间:”+DateTime.Now.ToLongTimeString();
}

能否显示您的标记?我不信任VS设计师。这看起来是正确的。您是否尝试过重建解决方案和/或重新启动VS?重建完成了,有点,仍然不起作用,但没有更多错误,当您说它看起来正确时,您的意思是只是语法正确,还是它看起来应该实现我试图实现的目标?或者我应该问一个新问题吗?=)你能展示一下你的标记吗?我不信任VS设计师。这看起来是正确的。您是否尝试过重建解决方案和/或重新启动VS?重建完成了,有点,仍然不起作用,但没有更多错误,当您说它看起来正确时,您的意思是只是语法正确,还是它看起来应该实现我试图实现的目标?或者我应该问一个新问题吗?=)