如何在HTML中不向服务器端发送仅服务器端ID?

时间:2013-12-05 01:08:56

标签: html asp.net client-side server-side

我正在开发一个.aspx页面,它不会对某些控件使用任何回发,所以我不需要HTML中那些控件上出现的ID。我确实需要ID服务器端,因为我在发送之前正在进行一些操作。

有什么方法我不能在HTML中发送它们吗?真的想最小化装载尺寸,因为这个网站被视图粉碎了。

1 个答案:

答案 0 :(得分:1)

如果可能,我会考虑使用除.net之外的其他解决方案,如果这是一个真正的问题。 .net在很大程度上依赖于id。

您可以出于此特定原因删除它们。

public partial class SiteHomePage : MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
    // After you render the page in C#, remove the IDs.
    RemoveIDs();
    }

    /// <summary>
    /// Reduce page size by 200 bytes by removing the ASP.NET ids.
    /// </summary>
    public void RemoveIDs()
    {
    Body1.ID = null;
    CategoryCountSpan1.ID = null;
    CategoryText1.ID = null;
    CategoryListItem1.ID = null;
    RssListItem1.ID = null;
    Prefix1.ID = null; // Shown in below example.
    Header1.ID = null; // Shown in below example.
    Author1.ID = null; // Shown in below example.
    BottomDivHome1.ID = null;
    BottomDivHome2.ID = null;
    JavaBlock1.ID = null;
    Advertisement1.ID = null;
    LogoLink1.ID = null;
    }
}

这是从Dot Net Perls:ASP.NET Remove ID获取的,这是一个很棒的教程网站。