开发者

Create a public function/sub to set CSS and other properties

开发者 https://www.devze.com 2023-02-04 05:35 出处:网络
I am trying to create a Public Sub / Function that will allow me to pass certain variables into it and this will affect the output. e.g.

I am trying to create a Public Sub / Function that will allow me to pass certain variables into it and this will affect the output. e.g.

DIV ID = InfoDiv

CSS Class = "Warning"

LBInfoMsg.Text = "An Error has occured"

DIV Visibility = True or False

I would like to type something similar in the code behind page:

InfoMsg(InfoDiv, "warning", "An Error has Occured", True)

I know this is wrong but here is what I have tried so far and failed...

Public Sub InfMsg(ByRef MyDIV As System.Web.UI.HtmlControls.HtmlGene开发者_开发问答ricControl, ByRef CSS As System.Web.UI.WebControls.Style, ByVal strMessage As String)
        strMessage = strMessage.Replace("'", "''")
        MyDIV.Attributes.Add("Style", "warning")
        MyDIV.Visible = "True"

    End Sub


Without getting too advanced into Lambdas and such, here's what I came up with based on the detail you gave:

Public Sub InfMsg(ByRef MyDIV As System.Web.UI.HtmlControls.HtmlGenericControl, ByRef CssClass As String, ByVal strMessage As String, ByVal visible As Boolean)

    MyDIV.Attributes("style") = "visibility:" & If(visible, "visible", "hidden") & ";"
    Dim lbl As New Label
    lbl.CssClass = CssClass
    lbl.Text = System.Web.HttpUtility.HtmlEncode(strMessage)
    MyDIV.Controls.Add(lbl)

End Sub
0

精彩评论

暂无评论...
验证码 换一张
取 消