FormViewDesigner.GetDesignTimeHtml Method ()
Gets the markup that is used to render the associated control at design time.
Assembly: System.Design (in System.Design.dll)
If an item template has been defined for the FormView control, the GetDesignTimeHtml method sets the DataKeyNames collection of the control to an empty String array if the schema for the data source cannot be obtained. The GetDesignTimeHtml refreshes the TypeDescriptor object to force a call to the PreFilterProperties method. The GetDesignTimeHtml then calls the base method to generate the markup.
If no item template has been defined for the FormView control, the GetDesignTimeHtml calls the GetEmptyDesignTimeHtml method to generate markup that renders to a placeholder.
Notes to Inheritors:
If you override the GetDesignTimeHtml method, be sure to call the base method because it eventually, through several override levels, calls on the FormView control or a copy of the FormView control to generate the markup.
The following code example shows how to override the GetDesignTimeHtml method in a class that is inherited from the FormViewDesigner class to change the appearance of the FormView control at design time. The example adds a new first row to the grid to contain the Caption property, if the Caption is defined. If the BorderStyle property of the control that is derived from the FormView is the NotSet or None value, the GetDesignTimeHtml draws a blue dashed border around the control to make its extent more visible. The example does not change the run-time appearance of the control.
' Generate the design-time markup. Private Const capTag As String = "caption" Private Const trOpen As String = "tr><td colspan=9 align=center" Private Const trClose As String = "td></tr" Public Overrides Function GetDesignTimeHtml() As String ' Make the full extent of the control more visible in the designer. ' If the border style is None or NotSet, change the border to ' a wide, blue, dashed line. Include the caption within the border. Dim myGV As MyFormView = CType(Component, MyFormView) Dim markup As String = Nothing Dim charX As Integer ' Check if the border style should be changed. If (myGV.BorderStyle = BorderStyle.NotSet Or _ myGV.BorderStyle = BorderStyle.None) Then Dim oldBorderStyle As BorderStyle = myGV.BorderStyle Dim oldBorderWidth As Unit = myGV.BorderWidth Dim oldBorderColor As Color = myGV.BorderColor ' Set the design-time properties and catch any exceptions. Try myGV.BorderStyle = BorderStyle.Dashed myGV.BorderWidth = Unit.Pixel(3) myGV.BorderColor = Color.Blue ' Call the base method to generate the markup. markup = MyBase.GetDesignTimeHtml() Catch ex As Exception markup = GetErrorDesignTimeHtml(ex) Finally ' Restore the properties to their original settings. myGV.BorderStyle = oldBorderStyle myGV.BorderWidth = oldBorderWidth myGV.BorderColor = oldBorderColor End Try Else ' Call the base method to generate the markup. markup = MyBase.GetDesignTimeHtml() End If ' Look for a <caption> tag. charX = markup.IndexOf(capTag) If charX > 0 Then ' Replace the first caption with ' "tr><td colspan=9 align=center". ' It is okay if the colspan exceeds the ' number of columns in the table. markup = markup.Remove(charX, _ capTag.Length).Insert(charX, trOpen) ' Replace the second caption with "td></tr". charX = markup.IndexOf(capTag, charX) If charX > 0 Then markup = markup.Remove(charX, _ capTag.Length).Insert(charX, trClose) End If End If Return markup End Function ' GetDesignTimeHtml
Available since 2.0
Refresh
CurrentMode
ItemTemplate
GetEmptyDesignTimeHtml
FormView
BaseDataBoundControlDesigner.GetDesignTimeHtml
ControlDesigner.GetDesignTimeHtml
GetDesignTimeHtml Overload
FormViewDesigner Class
System.Web.UI.Design.WebControls Namespace
Walkthrough: Creating a Basic Control Designer for a Web Server Control