I have a unique situation where I have a div element with the property set to runat="server" and an ID assigned to it. I am attempting to dynamically set the background image for this specific div from a MySQL database where the path URL is stored in a row. Everything is functioning properly, however, I am struggling with applying styling effect to only that particular div. Currently, I have defined the style on the div itself, which results in all divs on the page having the same background image. How can I assign a class or ID to this div in my code to target it specifically?
Private Sub coverContent_Init(sender As Object, e As EventArgs) Handles coverContent.Init
Try
Dim css As New HtmlGenericControl()
css.TagName = "style"
css.Attributes.Add("type", "text/css")
Dim imageURL As String = String.Empty
Dim var3 As String
var3 = Request.QueryString("hospitalID")
Dim str As String = "Select hospitalID, coverImage from hospitals where hospitalID='" + var3 + "';"
con.Open()
Dim cmd As New MySqlCommand(str, con)
Dim da As New MySqlDataAdapter(cmd)
Dim dt As New DataTable
da.Fill(dt)
con.Close()
If dt.Rows.Count > 0 Then
generalID.Text = dt.Rows(0)("hospitalID").ToString
imageURL = dt.Rows(0)("coverImage").ToString
End If
con.Close()
css.InnerHtml = (Convert.ToString("div#uniqueDiv{background-image: url(") & imageURL) + ");}"
Page.Header.Controls.Add(css)
MyBase.OnInit(e)
Catch ex As Exception
Response.Write(ex)
End Try
End Sub