English 中文(简体)
ASP 超链接在站点. master. cs 中找不到吗?
原标题:ASP Hyperlink not found in Site.master.cs?

我的Site.master 中有这个代码:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %> 
<!-- ... -->
<AnonymousTemplate>
    [ <asp:HyperLink ID="LoginHyperLink" runat="server" EnableViewState="false">Log In</asp:HyperLink> | 
    <asp:HyperLink ID="RegisterHyperLink" runat="server" EnableViewState="false">Register</asp:HyperLink> ]
</AnonymousTemplate>

我的Site.master.cs 中有这个代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
// ...
protected void Page_Load(object sender, EventArgs e)
{
    // this is just placeholder for now. 
    RegisterHyperLink.NavigateUrl = "Register.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
}

我在 Visual Working 2010 中,在 RegisterHyperLink.NavigateUrl 中发现一个 Compil-Time 错误: 2010 ,在 RegisterHyperLink.NavigateUrl 中说:

"目前情况下不存在" "注册HyperLink这个名字"

我从非主页上看到这个工作,所以这在大师身上不起作用吗?

我觉得会...

问题回答

这是一个错误, 在 Ddesing/ 源代码保存中添加一个新的 HyperLink 并重试保存。 删除新的超链接以完成

  • 确保您的代码后方继承 System.web.UI.MasterPage

  • 确保Aspx增加适当的指令,并确保该指令在正确的情况下具有拼写权利:

因为这个匿名模板。 它可能创造了新的命名容器, 因此无法直接从Page_Load直接进入。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签