链接按钮母版页与Click事件上的内容页堆栈溢出异常 [英] link button on Master Page with Click Event on Content Page Stack-overflow Exception

查看:164
本文介绍了链接按钮母版页与Click事件上的内容页堆栈溢出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在主页上连接一个asp链接按钮的内容页面上的单击事件。我跟着各种网上的帖子的描述,但是当我尝试运行页面,我的链接按钮属性的get {}集合{}部分得到一个堆栈溢出异常。我找不到任何人有这个问题,主要是因为我不知道实际的问题是什么。这里是我的code的某些位:

I am trying to connect an asp link button on a master page to its click event on the content page. I followed descriptions from various online posts, but when I try running the page, I get a Stack-overflow exception in the get{} set{} part of the link button property. I could not find anyone else with this problem, mainly because I don't know what the actual problem is. Here are some bits of my code:

母版页:

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

<asp:LinkButton id="myLink" Text="Home" runat="server"/>

母版页CS:

    public LinkButton myLink
    {
        get
        {
            return myLink; //FAILS HERE IF I COMMENT OUT THE SET.
        }
        set
        {
            myLink = value; //THIS IS WHERE IT FAILS!
        }
    }

Index.aspx.cs:

Index.aspx.cs:

    protected void Page_Init(object sender, EventArgs e)
    {
        if(Master.myLink != null)
            Master.myLink.Click += new EventHandler(MainTabBtn_Click);
    }

    protected void MainTabBtn_Click(object sender, EventArgs e)
    {
           //DO STUFF
     }

Index.aspx的:

Index.aspx:

<%@ Page Title="MySite" Language="C#" MasterPageFile="~/MySite.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="MySite1.Index" %>

<%@ MasterType VirtualPath="~/MySite.Master" %>

任何人都可以从这个是什么问题讲?感谢您的帮助,

Anyone can tell from this what the problem is? Thanks for your help,

马文

推荐答案

您分配一个值,该分配给myLink的属性myLink的财产( myLink的=值)它分配给myLink的财产......在一个无限循环 - 经典的堆栈溢出异常查找母版页控制来代替。

You assign a value to the myLink property which assigns it to the myLink property (myLink = value) which assigns it to the myLink property... in an infinite loop - the classic stack overflow exception. Find the control on the master page instead.

这篇关于链接按钮母版页与Click事件上的内容页堆栈溢出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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