我在计时器刻度事件中收到错误 [英] I am getting error in timer tick event

查看:88
本文介绍了我在计时器刻度事件中收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="L_PaperSet.aspx.cs" Inherits="Lib_Web.WebForm2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <style type="text/css">
        .style7
        {
            width: 100%;
        }
        .style8
        {
            width: 228px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table class="style7">
        <tr>
            <td class="style8">
                &nbsp;</td>
            <td>
                <asp:ScriptManager ID="ScriptManager1" runat="server">
                </asp:ScriptManager>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>

                        <asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick">
                        </asp:Timer>
                        <asp:Image ID="Image1" runat="server" />
                    </ContentTemplate>


                </asp:UpdatePanel>

            </td>
        </tr>
        <tr>
            <td class="style8">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
</asp:Content>







using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Lib_Web
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                NewMethod();

            }
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            NewMethod();
        }

        private void NewMethod()
        {
            Random rand = new Random();
            int i = rand.Next(1, 4);
            Image1.ImageUrl = "~/L_pics/" + i.ToString() + ".jpg";
        }
    }
}





从下面的评论中复制的其他信息



additional information copied from comment below

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1061: 'ASP.l_paperset_aspx' does not contain a definition for 'Timer1_Tick' and no extension method 'Timer1_Tick' accepting a first argument of type 'ASP.l_paperset_aspx' could be found (are you missing a using directive or an assembly reference?)

Source Error:


Line 23:                     <contenttemplate>
Line 24:                     
Line 25:                         <asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick">
Line 26:                         </contenttemplate>
Line 27:                         <asp:Image ID="Image1" runat="server" />

推荐答案

in您的aspx页面代码文件是 CodeBehind =L_PaperSet.aspx.cs但您可能已将其重命名为其他内容。给出WebForm2类cs文件的正确名称,然后这个错误就会消失。
in your aspx page code file is CodeBehind="L_PaperSet.aspx.cs" but you may have renamed it to something else. give the correct name of WebForm2 class cs file, then this error will be vanished.


你试过公开这个方法吗?



Have you tried to make the method public?

protected void Timer1_Tick(object sender, EventArgs e)
public void Timer1_Tick(object sender, EventArgs e)
{
    NewMethod();
}


我遇到了完全相同的问题,并意识到这是一个......错误的客户问题。



我曾要求他们将一些代码添加到他们的 .aspx 文件中,还添加到他们的 .aspx中。 cs 文件(包含 timer_tick 函数)。



他们这样做了。 ..一切正常并在本地运行......但是,在Visual Studio 2015中,他们决定右键单击该特定的.aspx文件,然后发布那个文件。



那么,发生了什么?



.aspx 文件已成功部署到其IIS服务器,但其.cs文件中的C#代码已编译为 bin中的 .dll 文件目录,但是他们还没有发布那个



是的......我知道....


所以,如果你确实发现你的命名空间完全匹配,但你仍然会收到这个错误... w ell ...检查 bin 目录.... !!
I had exactly the same problem, and realised it was a... errrm.. client problem.

I had asked them to add some code to their .aspx file, and also to their .aspx.cs file (which contained the timer_tick function).

They did this... it all worked fine and ran locally... but then, in Visual Studio 2015, they had decided to right click on just that particular .aspx file, and just publish that file.

So, what happened ?

The .aspx file successfully deployed to their IIS server, but the C# code in their .cs file had been compiled into a .dll file in their bin directory, but they hadn't published that.

Yeah... I know....

So, if you do find that your namespaces do match exactly, but you're still getting this error... well... check your bin directory....!!


这篇关于我在计时器刻度事件中收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆