November 24, 2003

Pre-filling a TextBox control with TextMode=”Password”

When the TextMode property of a TextBox control is set to Password, the value you assign to the Text property (either declaratively or programmatically) isn’t actually displayed at runtime, not even in masked mode (with the * chars). This is of course done for security reasons, because even if the

SetListSelections – Select in a List control the items passed as a comma delimited list

‘ Select the specified items (passed as a comma delimited list) in the input ‘ List control (e.g. ListBox, CheckBoxList)’ ‘ Example:’ SetListSelections(CheckBoxList1, “item 3, item 5, item 6”)Sub SetListSelections(ByVal listCtl As System.Web.UI.WebControls.ListControl, _ ByVal selections As String) ‘ first reset the list’s selections For Each item As System.Web.UI.WebControls.ListItem In

GetControlHtml – Retrieving the HTML code generated by the input ASP.NET server control

‘ Return the HTML code generated by the input ASP.NET server control’ Note: the function only works with server side controls that don’t generate ‘ postbacks and that can be declared outside a server-side form’ ‘ Example: TextBox1.Text = GetControlHtml(DataGrid1)Function GetControlHtml(ByVal ctl As System.Web.UI.Control) As String Dim writer As New

ShowMessageBox – Showing a client-side message box at the next page load

‘ Show a client-side message box at the next page load’ Example:’ ShowMessageBox(Me, “Order successfully submitted!”)Sub ShowMessageBox(ByVal webPage As System.Web.UI.Page, ByVal message As String) ‘ replace ‘ with ‘, otherwise the resulting javascript may raise errors message = message.Replace(“‘”, “‘”) ‘ create the script and add it to the page’s

GetListSelections – Retrieve a comma delimited list of items selected in a List control

‘ Return a comma delimited list of items selected in a List control (e.g. ‘ ListBox, CheckBoxList)” Example:’ Dim selections As String = GetListSelections(CheckBoxList1)Function GetListSelections(ByVal listCtl As _ System.Web.UI.WebControls.ListControl) As String Dim selections As New System.Text.StringBuilder Dim sep As String = “” ‘ add to the list each selected item