Any way to prevent master pages from changing element IDs?

前端 未结 3 1869
不思量自难忘°
不思量自难忘° 2020-12-11 05:24

I\'m looking at adding master pages to an existing site but have found that once I do, the elements\' IDs get prepended with a code (e.g. ctl00_MainPageContent_

相关标签:
3条回答
  • 2020-12-11 05:41

    The question was already answered in the previous post: Remove MasterPage Generated ID

    The solution overrides the Render Event with the following code:

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
        Dim Html As New StringWriter()
        Dim Render As New HtmlTextWriter(Html)
        MyBase.Render(Render)
        writer.Write(Html.ToString().Replace("name=""ctl00$ContentBody$", _ 
                      "name=""").Replace("id=""ctl00_ContentBody_", "id="""))
    End Sub
    
    0 讨论(0)
  • 2020-12-11 05:45

    You can override ClientID and UniqueID in the controls. This is from here, an article by Rick Strahl.

    public override string UniqueID
    {
        get
        {
            return this.ID;
        }
    }
    
    public override string ClientID
    {   
        get
        {
            return this.ID;
        }
    }
    
    0 讨论(0)
  • 2020-12-11 05:52

    This question is old as dirt, but the new way to do it is ClientIDMode="Static".

    0 讨论(0)
提交回复
热议问题