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 FalseI 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
精彩评论