When the user clicks to open a popup I want to add a class to the body HTML tag to prevent scrolling of the background. The popup resides in a content page. I've added runat server to my body tag on my main.Master page:
<body runat="server" id="MasterPageBodyTag">
In the code behind of my content page I have the following:
Protected Sub lnkShowNotes_Click(sender As Object, e As EventArgs) Handles lnkShowNotes.Click
mvwNotes.SetActiveView(vwNoteList)
mdlNotesPopup.Show()
Dim body As HtmlControl = Master.FindControl("MasterPageBodyTag")
body.Attributes.Add("class", "cssBodyClass")
End Sub
When I debug I can see in the results view that the class is there in the attributes, however on the page the class is not getting added to the body element.
The problem is that the popup is loaded with Ajax. Therefore there will be no full PostBack and thus the body class does not change. You need to set the bodyclass with JavaScript or jQuery, either in the frontent or in the backend.
In the backend you can do this
ScriptManager.RegisterStartupScript(Page, Page.GetType, "setBodyClass", "$('#MasterPageBodyTag').attr('class', 'cssBodyClass');", true)