Can this, maybe ASP code, be easily replaced with modern code

Discussion in 'ASP .Net' started by Cal Who, Jan 8, 2010.

  1. Cal Who

    Cal Who Guest

    The code below is from the routine DatePicker.vb from one of the 2005
    starter kits.

    For one thing - if I use it in a ascx file it can't show in the Designer.

    For another - since so much is simply string it must require a great mind to
    debug.

    I'm wondering is with the latest framework all this is still necessary.

    Do you think this can be replaced with a reasonable effort with some new
    control?

    If so, which one?

    Is this typical of ASP code. If so I salute anyone who wrote ASP and/or can
    follow this code.

    Any helpful comment would be appreciated.



    Thanks





    Imports Microsoft.VisualBasic


    Namespace My.Library

    Module commonScript

    Sub WritePopupRoutines(ByVal Page As System.Web.UI.Page)

    Dim sb As New Text.StringBuilder()

    sb = New StringBuilder

    sb.AppendLine("var __popup_panel;")

    sb.AppendLine("function __popup_clear() {")

    sb.AppendLine(" if (__popup_panel != null ) ")

    sb.AppendLine(" {")

    sb.AppendLine("
    document.getElementById(__popup_panel).style.display='none';")

    sb.AppendLine(" __popup_panel=null;")

    ' sb.AppendLine(" document.onclick=null;")

    sb.AppendLine(" }")

    sb.AppendLine("}")

    sb.AppendLine("function __popup_losefocus(panel)")

    sb.AppendLine("{")

    sb.AppendLine(" if (!panel.contains(document.activeElement))")

    sb.AppendLine(" {")

    sb.AppendLine(" panel.style.display='none';")

    sb.AppendLine(" }")

    sb.AppendLine("}")

    Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "PopupRoutines",
    sb.ToString, True)

    End Sub

    End Module

    Public Class DatePicker

    Inherits WebControl

    Implements INamingContainer

    Private _innerCal As Calendar

    Private _innerTbx As TextBox

    Private errorText As String = Nothing

    Private _panelvisible As Boolean = False

    Sub New()

    MyBase.New(UI.HtmlTextWriterTag.Div)

    End Sub

    Public Property SelectedDate() As Date

    Get

    EnsureChildControls()

    Dim d As Date

    Try

    d = Date.Parse(_innerTbx.Text)

    errorText = Nothing

    _innerCal.SelectedDate = d

    Catch

    errorText = "Date needs to be specified as mm/dd/yyyy"

    End Try

    Return d

    End Get

    Set(ByVal value As Date)

    EnsureChildControls()

    _innerCal.SelectedDate = value

    _innerTbx.Text = value.ToShortDateString

    End Set

    End Property

    Protected Overrides Sub CreateChildControls()

    MyBase.CreateChildControls()

    _innerTbx = New TextBox

    Me.Controls.Add(_innerTbx)

    _innerCal = New Calendar

    AddHandler _innerCal.SelectionChanged, AddressOf _innerCal_SelectionChanged

    AddHandler _innerCal.VisibleMonthChanged, AddressOf _innerCal_MonthChanged

    Controls.Add(_innerCal)

    End Sub

    Protected Overrides ReadOnly Property TagKey() As
    System.Web.UI.HtmlTextWriterTag

    Get

    Return HtmlTextWriterTag.Div

    End Get

    End Property

    Protected Overrides Sub AddAttributesToRender(ByVal writer As
    System.Web.UI.HtmlTextWriter)

    If Me.Width.IsEmpty Then Me.Width = New Unit(150)

    MyBase.AddAttributesToRender(writer)

    End Sub

    Protected Overrides Sub RenderContents(ByVal writer As
    System.Web.UI.HtmlTextWriter)

    _innerTbx.Attributes.Add("Align", "AbsMiddle")

    _innerTbx.Width = New Unit(100)

    '_innerTbx.Height = New Unit(20)

    _innerTbx.RenderControl(writer)

    Dim innerid As String = Me.UniqueID & "_inner"

    writer.AddAttribute("Align", "AbsMiddle")

    writer.AddAttribute("src", "../Images/DropDownBtn.gif")

    writer.AddAttribute("onClick", "__datepicker_showpopup('" & innerid & "')")

    writer.RenderBeginTag(HtmlTextWriterTag.Img)

    writer.RenderEndTag()

    If errorText <> Nothing Then

    writer.AddStyleAttribute("color", "red")

    writer.AddStyleAttribute("display", "block")

    writer.RenderBeginTag(HtmlTextWriterTag.Span)

    writer.Write(errorText)

    writer.RenderEndTag()

    End If


    writer.AddStyleAttribute("position", "relative")

    writer.RenderBeginTag(HtmlTextWriterTag.Div)


    writer.AddStyleAttribute("position", "absolute")

    writer.AddStyleAttribute("left", "0px")

    writer.AddStyleAttribute("top", "0px")

    writer.AddStyleAttribute("z-index", "100")

    Dim panelvisible As String

    If _panelvisible Then panelvisible = "block" Else panelvisible = "none"

    writer.AddStyleAttribute("display", panelvisible)

    ' writer.AddStyleAttribute("background-color", "white")

    writer.AddAttribute("id", innerid)

    writer.AddAttribute("onfocusout", "__popup_losefocus(this)")

    writer.RenderBeginTag(HtmlTextWriterTag.Div)

    _innerCal.RenderControl(writer)

    writer.RenderEndTag()

    writer.RenderEndTag()

    End Sub

    Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)

    MyBase.OnPreRender(e)

    commonScript.WritePopupRoutines(Page)

    Dim sb As New StringBuilder

    If _panelvisible Then

    sb.AppendLine("__popup_panel = '" & Me.UniqueID & "_inner';")

    End If

    sb.AppendLine("function __datepicker_showpopup(name)")

    sb.AppendLine("{")

    sb.AppendLine(" if (__popup_panel != null)")

    sb.AppendLine(" {")

    sb.AppendLine("
    document.getElementById(__popup_panel).style.display='none';")

    sb.AppendLine(" }")

    sb.AppendLine(" __popup_panel=name;")

    sb.AppendLine(" var panel=document.getElementById(__popup_panel);")

    sb.AppendLine(" panel.style.display='block';")

    sb.AppendLine(" var links=panel.getElementsByTagName('A');")

    sb.AppendLine(" links[0].focus();")

    ' sb.AppendLine(" document.onclick=__popup_clear();")

    sb.AppendLine(" window.event.cancelBubble=true;")

    sb.AppendLine("}")

    Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "popup",
    sb.ToString, True)

    Page.MaintainScrollPositionOnPostBack = True

    End Sub

    Private Sub _innerCal_SelectionChanged(ByVal sender As Object, ByVal e As
    System.EventArgs)

    EnsureChildControls()

    _innerTbx.Text = _innerCal.SelectedDate.ToShortDateString

    End Sub

    'keep the panel for another

    Private Sub _innerCal_MonthChanged(ByVal sender As Object, ByVal e As
    MonthChangedEventArgs)

    _panelvisible = True

    End Sub

    End Class

    End Namespace
    Cal Who, Jan 8, 2010
    #1
    1. Advertising

  2. Cal Who

    Scott M. Guest

    Well, since VB supports XML as a first class data type, you can reduce some
    of that code that builds up the JavaScript by doing this:

    Dim sb As New Text.StringBuilder()
    sb = New StringBuilder
    Dim theString = <myJS>
    var __popup_panel;
    function __popup_clear() {
    if (__popup_panel != null )
    {
    document.getElementById(__popup_panel).style.display='none';
    __popup_panel=null;
    }
    }

    function __popup_losefocus(panel)
    {
    if (!panel.contains(document.activeElement))
    {
    panel.style.display='none';
    }
    }
    </myJS>
    sb.Append(theString.Value)

    Actually, with VS 2010, you could now write this a little bit simpler, since
    VB now supports multiple line statements without the _ line continuation
    char.

    Dim sb As New Text.StringBuilder()
    sb = New StringBuilder
    Dim theString As String =
    var __popup_panel;
    function __popup_clear() {
    if (__popup_panel != null )
    {
    document.getElementById(__popup_panel).style.display='none';
    __popup_panel=null;
    }
    }

    function __popup_losefocus(panel)
    {
    if (!panel.contains(document.activeElement))
    {
    panel.style.display='none';
    }
    }
    sb.Append(theString)

    As for why you are importing the Microsoft.VisualBasic Namespace, I'm not
    sure.

    Also, with VS 2008, when you drop an .ascx file into an .aspx page, you will
    see the control in the designer.

    I think that your code can be reworked to be reduced and that you will find
    it easier to use the .ascx file than previously.

    -Scott

    " Cal Who" <> wrote in message
    news:...
    > The code below is from the routine DatePicker.vb from one of the 2005
    > starter kits.
    >
    > For one thing - if I use it in a ascx file it can't show in the Designer.
    >
    > For another - since so much is simply string it must require a great mind
    > to debug.
    >
    > I'm wondering is with the latest framework all this is still necessary.
    >
    > Do you think this can be replaced with a reasonable effort with some new
    > control?
    >
    > If so, which one?
    >
    > Is this typical of ASP code. If so I salute anyone who wrote ASP and/or
    > can follow this code.
    >
    > Any helpful comment would be appreciated.
    >
    >
    >
    > Thanks
    >
    >
    >
    >
    >
    > Imports Microsoft.VisualBasic
    >
    >
    > Namespace My.Library
    >
    > Module commonScript
    >
    > Sub WritePopupRoutines(ByVal Page As System.Web.UI.Page)
    >
    > Dim sb As New Text.StringBuilder()
    >
    > sb = New StringBuilder
    >
    > sb.AppendLine("var __popup_panel;")
    >
    > sb.AppendLine("function __popup_clear() {")
    >
    > sb.AppendLine(" if (__popup_panel != null ) ")
    >
    > sb.AppendLine(" {")
    >
    > sb.AppendLine("
    > document.getElementById(__popup_panel).style.display='none';")
    >
    > sb.AppendLine(" __popup_panel=null;")
    >
    > ' sb.AppendLine(" document.onclick=null;")
    >
    > sb.AppendLine(" }")
    >
    > sb.AppendLine("}")
    >
    > sb.AppendLine("function __popup_losefocus(panel)")
    >
    > sb.AppendLine("{")
    >
    > sb.AppendLine(" if (!panel.contains(document.activeElement))")
    >
    > sb.AppendLine(" {")
    >
    > sb.AppendLine(" panel.style.display='none';")
    >
    > sb.AppendLine(" }")
    >
    > sb.AppendLine("}")
    >
    > Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "PopupRoutines",
    > sb.ToString, True)
    >
    > End Sub
    >
    > End Module
    >
    > Public Class DatePicker
    >
    > Inherits WebControl
    >
    > Implements INamingContainer
    >
    > Private _innerCal As Calendar
    >
    > Private _innerTbx As TextBox
    >
    > Private errorText As String = Nothing
    >
    > Private _panelvisible As Boolean = False
    >
    > Sub New()
    >
    > MyBase.New(UI.HtmlTextWriterTag.Div)
    >
    > End Sub
    >
    > Public Property SelectedDate() As Date
    >
    > Get
    >
    > EnsureChildControls()
    >
    > Dim d As Date
    >
    > Try
    >
    > d = Date.Parse(_innerTbx.Text)
    >
    > errorText = Nothing
    >
    > _innerCal.SelectedDate = d
    >
    > Catch
    >
    > errorText = "Date needs to be specified as mm/dd/yyyy"
    >
    > End Try
    >
    > Return d
    >
    > End Get
    >
    > Set(ByVal value As Date)
    >
    > EnsureChildControls()
    >
    > _innerCal.SelectedDate = value
    >
    > _innerTbx.Text = value.ToShortDateString
    >
    > End Set
    >
    > End Property
    >
    > Protected Overrides Sub CreateChildControls()
    >
    > MyBase.CreateChildControls()
    >
    > _innerTbx = New TextBox
    >
    > Me.Controls.Add(_innerTbx)
    >
    > _innerCal = New Calendar
    >
    > AddHandler _innerCal.SelectionChanged, AddressOf
    > _innerCal_SelectionChanged
    >
    > AddHandler _innerCal.VisibleMonthChanged, AddressOf _innerCal_MonthChanged
    >
    > Controls.Add(_innerCal)
    >
    > End Sub
    >
    > Protected Overrides ReadOnly Property TagKey() As
    > System.Web.UI.HtmlTextWriterTag
    >
    > Get
    >
    > Return HtmlTextWriterTag.Div
    >
    > End Get
    >
    > End Property
    >
    > Protected Overrides Sub AddAttributesToRender(ByVal writer As
    > System.Web.UI.HtmlTextWriter)
    >
    > If Me.Width.IsEmpty Then Me.Width = New Unit(150)
    >
    > MyBase.AddAttributesToRender(writer)
    >
    > End Sub
    >
    > Protected Overrides Sub RenderContents(ByVal writer As
    > System.Web.UI.HtmlTextWriter)
    >
    > _innerTbx.Attributes.Add("Align", "AbsMiddle")
    >
    > _innerTbx.Width = New Unit(100)
    >
    > '_innerTbx.Height = New Unit(20)
    >
    > _innerTbx.RenderControl(writer)
    >
    > Dim innerid As String = Me.UniqueID & "_inner"
    >
    > writer.AddAttribute("Align", "AbsMiddle")
    >
    > writer.AddAttribute("src", "../Images/DropDownBtn.gif")
    >
    > writer.AddAttribute("onClick", "__datepicker_showpopup('" & innerid &
    > "')")
    >
    > writer.RenderBeginTag(HtmlTextWriterTag.Img)
    >
    > writer.RenderEndTag()
    >
    > If errorText <> Nothing Then
    >
    > writer.AddStyleAttribute("color", "red")
    >
    > writer.AddStyleAttribute("display", "block")
    >
    > writer.RenderBeginTag(HtmlTextWriterTag.Span)
    >
    > writer.Write(errorText)
    >
    > writer.RenderEndTag()
    >
    > End If
    >
    >
    > writer.AddStyleAttribute("position", "relative")
    >
    > writer.RenderBeginTag(HtmlTextWriterTag.Div)
    >
    >
    > writer.AddStyleAttribute("position", "absolute")
    >
    > writer.AddStyleAttribute("left", "0px")
    >
    > writer.AddStyleAttribute("top", "0px")
    >
    > writer.AddStyleAttribute("z-index", "100")
    >
    > Dim panelvisible As String
    >
    > If _panelvisible Then panelvisible = "block" Else panelvisible = "none"
    >
    > writer.AddStyleAttribute("display", panelvisible)
    >
    > ' writer.AddStyleAttribute("background-color", "white")
    >
    > writer.AddAttribute("id", innerid)
    >
    > writer.AddAttribute("onfocusout", "__popup_losefocus(this)")
    >
    > writer.RenderBeginTag(HtmlTextWriterTag.Div)
    >
    > _innerCal.RenderControl(writer)
    >
    > writer.RenderEndTag()
    >
    > writer.RenderEndTag()
    >
    > End Sub
    >
    > Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
    >
    > MyBase.OnPreRender(e)
    >
    > commonScript.WritePopupRoutines(Page)
    >
    > Dim sb As New StringBuilder
    >
    > If _panelvisible Then
    >
    > sb.AppendLine("__popup_panel = '" & Me.UniqueID & "_inner';")
    >
    > End If
    >
    > sb.AppendLine("function __datepicker_showpopup(name)")
    >
    > sb.AppendLine("{")
    >
    > sb.AppendLine(" if (__popup_panel != null)")
    >
    > sb.AppendLine(" {")
    >
    > sb.AppendLine("
    > document.getElementById(__popup_panel).style.display='none';")
    >
    > sb.AppendLine(" }")
    >
    > sb.AppendLine(" __popup_panel=name;")
    >
    > sb.AppendLine(" var panel=document.getElementById(__popup_panel);")
    >
    > sb.AppendLine(" panel.style.display='block';")
    >
    > sb.AppendLine(" var links=panel.getElementsByTagName('A');")
    >
    > sb.AppendLine(" links[0].focus();")
    >
    > ' sb.AppendLine(" document.onclick=__popup_clear();")
    >
    > sb.AppendLine(" window.event.cancelBubble=true;")
    >
    > sb.AppendLine("}")
    >
    > Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "popup",
    > sb.ToString, True)
    >
    > Page.MaintainScrollPositionOnPostBack = True
    >
    > End Sub
    >
    > Private Sub _innerCal_SelectionChanged(ByVal sender As Object, ByVal e As
    > System.EventArgs)
    >
    > EnsureChildControls()
    >
    > _innerTbx.Text = _innerCal.SelectedDate.ToShortDateString
    >
    > End Sub
    >
    > 'keep the panel for another
    >
    > Private Sub _innerCal_MonthChanged(ByVal sender As Object, ByVal e As
    > MonthChangedEventArgs)
    >
    > _panelvisible = True
    >
    > End Sub
    >
    > End Class
    >
    > End Namespace
    >
    >
    Scott M., Jan 8, 2010
    #2
    1. Advertising

  3. Cal Who

    Scott M. Guest

    Slight correction, on the Dim theString = code dont' forget to put double
    quotes around the beginning and end of the string.

    -Scott

    "Scott M." <> wrote in message
    news:...
    > Well, since VB supports XML as a first class data type, you can reduce
    > some of that code that builds up the JavaScript by doing this:
    >
    > Dim sb As New Text.StringBuilder()
    > sb = New StringBuilder
    > Dim theString = <myJS>
    > var __popup_panel;
    > function __popup_clear() {
    > if (__popup_panel != null )
    > {
    >
    > document.getElementById(__popup_panel).style.display='none';
    > __popup_panel=null;
    > }
    > }
    >
    > function __popup_losefocus(panel)
    > {
    > if (!panel.contains(document.activeElement))
    > {
    > panel.style.display='none';
    > }
    > }
    > </myJS>
    > sb.Append(theString.Value)
    >
    > Actually, with VS 2010, you could now write this a little bit simpler,
    > since VB now supports multiple line statements without the _ line
    > continuation char.
    >
    > Dim sb As New Text.StringBuilder()
    > sb = New StringBuilder
    > Dim theString As String =
    > var __popup_panel;
    > function __popup_clear() {
    > if (__popup_panel != null )
    > {
    >
    > document.getElementById(__popup_panel).style.display='none';
    > __popup_panel=null;
    > }
    > }
    >
    > function __popup_losefocus(panel)
    > {
    > if (!panel.contains(document.activeElement))
    > {
    > panel.style.display='none';
    > }
    > }
    > sb.Append(theString)
    >
    > As for why you are importing the Microsoft.VisualBasic Namespace, I'm not
    > sure.
    >
    > Also, with VS 2008, when you drop an .ascx file into an .aspx page, you
    > will see the control in the designer.
    >
    > I think that your code can be reworked to be reduced and that you will
    > find it easier to use the .ascx file than previously.
    >
    > -Scott
    >
    > " Cal Who" <> wrote in message
    > news:...
    >> The code below is from the routine DatePicker.vb from one of the 2005
    >> starter kits.
    >>
    >> For one thing - if I use it in a ascx file it can't show in the Designer.
    >>
    >> For another - since so much is simply string it must require a great mind
    >> to debug.
    >>
    >> I'm wondering is with the latest framework all this is still necessary.
    >>
    >> Do you think this can be replaced with a reasonable effort with some new
    >> control?
    >>
    >> If so, which one?
    >>
    >> Is this typical of ASP code. If so I salute anyone who wrote ASP and/or
    >> can follow this code.
    >>
    >> Any helpful comment would be appreciated.
    >>
    >>
    >>
    >> Thanks
    >>
    >>
    >>
    >>
    >>
    >> Imports Microsoft.VisualBasic
    >>
    >>
    >> Namespace My.Library
    >>
    >> Module commonScript
    >>
    >> Sub WritePopupRoutines(ByVal Page As System.Web.UI.Page)
    >>
    >> Dim sb As New Text.StringBuilder()
    >>
    >> sb = New StringBuilder
    >>
    >> sb.AppendLine("var __popup_panel;")
    >>
    >> sb.AppendLine("function __popup_clear() {")
    >>
    >> sb.AppendLine(" if (__popup_panel != null ) ")
    >>
    >> sb.AppendLine(" {")
    >>
    >> sb.AppendLine("
    >> document.getElementById(__popup_panel).style.display='none';")
    >>
    >> sb.AppendLine(" __popup_panel=null;")
    >>
    >> ' sb.AppendLine(" document.onclick=null;")
    >>
    >> sb.AppendLine(" }")
    >>
    >> sb.AppendLine("}")
    >>
    >> sb.AppendLine("function __popup_losefocus(panel)")
    >>
    >> sb.AppendLine("{")
    >>
    >> sb.AppendLine(" if (!panel.contains(document.activeElement))")
    >>
    >> sb.AppendLine(" {")
    >>
    >> sb.AppendLine(" panel.style.display='none';")
    >>
    >> sb.AppendLine(" }")
    >>
    >> sb.AppendLine("}")
    >>
    >> Page.ClientScript.RegisterClientScriptBlock(Page.GetType,
    >> "PopupRoutines", sb.ToString, True)
    >>
    >> End Sub
    >>
    >> End Module
    >>
    >> Public Class DatePicker
    >>
    >> Inherits WebControl
    >>
    >> Implements INamingContainer
    >>
    >> Private _innerCal As Calendar
    >>
    >> Private _innerTbx As TextBox
    >>
    >> Private errorText As String = Nothing
    >>
    >> Private _panelvisible As Boolean = False
    >>
    >> Sub New()
    >>
    >> MyBase.New(UI.HtmlTextWriterTag.Div)
    >>
    >> End Sub
    >>
    >> Public Property SelectedDate() As Date
    >>
    >> Get
    >>
    >> EnsureChildControls()
    >>
    >> Dim d As Date
    >>
    >> Try
    >>
    >> d = Date.Parse(_innerTbx.Text)
    >>
    >> errorText = Nothing
    >>
    >> _innerCal.SelectedDate = d
    >>
    >> Catch
    >>
    >> errorText = "Date needs to be specified as mm/dd/yyyy"
    >>
    >> End Try
    >>
    >> Return d
    >>
    >> End Get
    >>
    >> Set(ByVal value As Date)
    >>
    >> EnsureChildControls()
    >>
    >> _innerCal.SelectedDate = value
    >>
    >> _innerTbx.Text = value.ToShortDateString
    >>
    >> End Set
    >>
    >> End Property
    >>
    >> Protected Overrides Sub CreateChildControls()
    >>
    >> MyBase.CreateChildControls()
    >>
    >> _innerTbx = New TextBox
    >>
    >> Me.Controls.Add(_innerTbx)
    >>
    >> _innerCal = New Calendar
    >>
    >> AddHandler _innerCal.SelectionChanged, AddressOf
    >> _innerCal_SelectionChanged
    >>
    >> AddHandler _innerCal.VisibleMonthChanged, AddressOf
    >> _innerCal_MonthChanged
    >>
    >> Controls.Add(_innerCal)
    >>
    >> End Sub
    >>
    >> Protected Overrides ReadOnly Property TagKey() As
    >> System.Web.UI.HtmlTextWriterTag
    >>
    >> Get
    >>
    >> Return HtmlTextWriterTag.Div
    >>
    >> End Get
    >>
    >> End Property
    >>
    >> Protected Overrides Sub AddAttributesToRender(ByVal writer As
    >> System.Web.UI.HtmlTextWriter)
    >>
    >> If Me.Width.IsEmpty Then Me.Width = New Unit(150)
    >>
    >> MyBase.AddAttributesToRender(writer)
    >>
    >> End Sub
    >>
    >> Protected Overrides Sub RenderContents(ByVal writer As
    >> System.Web.UI.HtmlTextWriter)
    >>
    >> _innerTbx.Attributes.Add("Align", "AbsMiddle")
    >>
    >> _innerTbx.Width = New Unit(100)
    >>
    >> '_innerTbx.Height = New Unit(20)
    >>
    >> _innerTbx.RenderControl(writer)
    >>
    >> Dim innerid As String = Me.UniqueID & "_inner"
    >>
    >> writer.AddAttribute("Align", "AbsMiddle")
    >>
    >> writer.AddAttribute("src", "../Images/DropDownBtn.gif")
    >>
    >> writer.AddAttribute("onClick", "__datepicker_showpopup('" & innerid &
    >> "')")
    >>
    >> writer.RenderBeginTag(HtmlTextWriterTag.Img)
    >>
    >> writer.RenderEndTag()
    >>
    >> If errorText <> Nothing Then
    >>
    >> writer.AddStyleAttribute("color", "red")
    >>
    >> writer.AddStyleAttribute("display", "block")
    >>
    >> writer.RenderBeginTag(HtmlTextWriterTag.Span)
    >>
    >> writer.Write(errorText)
    >>
    >> writer.RenderEndTag()
    >>
    >> End If
    >>
    >>
    >> writer.AddStyleAttribute("position", "relative")
    >>
    >> writer.RenderBeginTag(HtmlTextWriterTag.Div)
    >>
    >>
    >> writer.AddStyleAttribute("position", "absolute")
    >>
    >> writer.AddStyleAttribute("left", "0px")
    >>
    >> writer.AddStyleAttribute("top", "0px")
    >>
    >> writer.AddStyleAttribute("z-index", "100")
    >>
    >> Dim panelvisible As String
    >>
    >> If _panelvisible Then panelvisible = "block" Else panelvisible = "none"
    >>
    >> writer.AddStyleAttribute("display", panelvisible)
    >>
    >> ' writer.AddStyleAttribute("background-color", "white")
    >>
    >> writer.AddAttribute("id", innerid)
    >>
    >> writer.AddAttribute("onfocusout", "__popup_losefocus(this)")
    >>
    >> writer.RenderBeginTag(HtmlTextWriterTag.Div)
    >>
    >> _innerCal.RenderControl(writer)
    >>
    >> writer.RenderEndTag()
    >>
    >> writer.RenderEndTag()
    >>
    >> End Sub
    >>
    >> Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
    >>
    >> MyBase.OnPreRender(e)
    >>
    >> commonScript.WritePopupRoutines(Page)
    >>
    >> Dim sb As New StringBuilder
    >>
    >> If _panelvisible Then
    >>
    >> sb.AppendLine("__popup_panel = '" & Me.UniqueID & "_inner';")
    >>
    >> End If
    >>
    >> sb.AppendLine("function __datepicker_showpopup(name)")
    >>
    >> sb.AppendLine("{")
    >>
    >> sb.AppendLine(" if (__popup_panel != null)")
    >>
    >> sb.AppendLine(" {")
    >>
    >> sb.AppendLine("
    >> document.getElementById(__popup_panel).style.display='none';")
    >>
    >> sb.AppendLine(" }")
    >>
    >> sb.AppendLine(" __popup_panel=name;")
    >>
    >> sb.AppendLine(" var panel=document.getElementById(__popup_panel);")
    >>
    >> sb.AppendLine(" panel.style.display='block';")
    >>
    >> sb.AppendLine(" var links=panel.getElementsByTagName('A');")
    >>
    >> sb.AppendLine(" links[0].focus();")
    >>
    >> ' sb.AppendLine(" document.onclick=__popup_clear();")
    >>
    >> sb.AppendLine(" window.event.cancelBubble=true;")
    >>
    >> sb.AppendLine("}")
    >>
    >> Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "popup",
    >> sb.ToString, True)
    >>
    >> Page.MaintainScrollPositionOnPostBack = True
    >>
    >> End Sub
    >>
    >> Private Sub _innerCal_SelectionChanged(ByVal sender As Object, ByVal e As
    >> System.EventArgs)
    >>
    >> EnsureChildControls()
    >>
    >> _innerTbx.Text = _innerCal.SelectedDate.ToShortDateString
    >>
    >> End Sub
    >>
    >> 'keep the panel for another
    >>
    >> Private Sub _innerCal_MonthChanged(ByVal sender As Object, ByVal e As
    >> MonthChangedEventArgs)
    >>
    >> _panelvisible = True
    >>
    >> End Sub
    >>
    >> End Class
    >>
    >> End Namespace
    >>
    >>

    >
    >
    Scott M., Jan 8, 2010
    #3
  4. Cal Who

    Cal Who Guest

    Are you suggesting that people still write code like this.
    I should study it, maybe improve it but it is not desirable to replace it?
    Thanks

    "Scott M." <> wrote in message
    news:...
    > Slight correction, on the Dim theString = code dont' forget to put double
    > quotes around the beginning and end of the string.
    >
    > -Scott
    >
    > "Scott M." <> wrote in message
    > news:...
    >> Well, since VB supports XML as a first class data type, you can reduce
    >> some of that code that builds up the JavaScript by doing this:
    >>
    >> Dim sb As New Text.StringBuilder()
    >> sb = New StringBuilder
    >> Dim theString = <myJS>
    >> var __popup_panel;
    >> function __popup_clear() {
    >> if (__popup_panel != null )
    >> {
    >>
    >> document.getElementById(__popup_panel).style.display='none';
    >> __popup_panel=null;
    >> }
    >> }
    >>
    >> function __popup_losefocus(panel)
    >> {
    >> if (!panel.contains(document.activeElement))
    >> {
    >> panel.style.display='none';
    >> }
    >> }
    >> </myJS>
    >> sb.Append(theString.Value)
    >>
    >> Actually, with VS 2010, you could now write this a little bit simpler,
    >> since VB now supports multiple line statements without the _ line
    >> continuation char.
    >>
    >> Dim sb As New Text.StringBuilder()
    >> sb = New StringBuilder
    >> Dim theString As String =
    >> var __popup_panel;
    >> function __popup_clear() {
    >> if (__popup_panel != null )
    >> {
    >>
    >> document.getElementById(__popup_panel).style.display='none';
    >> __popup_panel=null;
    >> }
    >> }
    >>
    >> function __popup_losefocus(panel)
    >> {
    >> if (!panel.contains(document.activeElement))
    >> {
    >> panel.style.display='none';
    >> }
    >> }
    >> sb.Append(theString)
    >>
    >> As for why you are importing the Microsoft.VisualBasic Namespace, I'm not
    >> sure.
    >>
    >> Also, with VS 2008, when you drop an .ascx file into an .aspx page, you
    >> will see the control in the designer.
    >>
    >> I think that your code can be reworked to be reduced and that you will
    >> find it easier to use the .ascx file than previously.
    >>
    >> -Scott
    >>
    >> " Cal Who" <> wrote in message
    >> news:...
    >>> The code below is from the routine DatePicker.vb from one of the 2005
    >>> starter kits.
    >>>
    >>> For one thing - if I use it in a ascx file it can't show in the
    >>> Designer.
    >>>
    >>> For another - since so much is simply string it must require a great
    >>> mind to debug.
    >>>
    >>> I'm wondering is with the latest framework all this is still necessary.
    >>>
    >>> Do you think this can be replaced with a reasonable effort with some new
    >>> control?
    >>>
    >>> If so, which one?
    >>>
    >>> Is this typical of ASP code. If so I salute anyone who wrote ASP and/or
    >>> can follow this code.
    >>>
    >>> Any helpful comment would be appreciated.
    >>>
    >>>
    >>>
    >>> Thanks
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> Imports Microsoft.VisualBasic
    >>>
    >>>
    >>> Namespace My.Library
    >>>
    >>> Module commonScript
    >>>
    >>> Sub WritePopupRoutines(ByVal Page As System.Web.UI.Page)
    >>>
    >>> Dim sb As New Text.StringBuilder()
    >>>
    >>> sb = New StringBuilder
    >>>
    >>> sb.AppendLine("var __popup_panel;")
    >>>
    >>> sb.AppendLine("function __popup_clear() {")
    >>>
    >>> sb.AppendLine(" if (__popup_panel != null ) ")
    >>>
    >>> sb.AppendLine(" {")
    >>>
    >>> sb.AppendLine("
    >>> document.getElementById(__popup_panel).style.display='none';")
    >>>
    >>> sb.AppendLine(" __popup_panel=null;")
    >>>
    >>> ' sb.AppendLine(" document.onclick=null;")
    >>>
    >>> sb.AppendLine(" }")
    >>>
    >>> sb.AppendLine("}")
    >>>
    >>> sb.AppendLine("function __popup_losefocus(panel)")
    >>>
    >>> sb.AppendLine("{")
    >>>
    >>> sb.AppendLine(" if (!panel.contains(document.activeElement))")
    >>>
    >>> sb.AppendLine(" {")
    >>>
    >>> sb.AppendLine(" panel.style.display='none';")
    >>>
    >>> sb.AppendLine(" }")
    >>>
    >>> sb.AppendLine("}")
    >>>
    >>> Page.ClientScript.RegisterClientScriptBlock(Page.GetType,
    >>> "PopupRoutines", sb.ToString, True)
    >>>
    >>> End Sub
    >>>
    >>> End Module
    >>>
    >>> Public Class DatePicker
    >>>
    >>> Inherits WebControl
    >>>
    >>> Implements INamingContainer
    >>>
    >>> Private _innerCal As Calendar
    >>>
    >>> Private _innerTbx As TextBox
    >>>
    >>> Private errorText As String = Nothing
    >>>
    >>> Private _panelvisible As Boolean = False
    >>>
    >>> Sub New()
    >>>
    >>> MyBase.New(UI.HtmlTextWriterTag.Div)
    >>>
    >>> End Sub
    >>>
    >>> Public Property SelectedDate() As Date
    >>>
    >>> Get
    >>>
    >>> EnsureChildControls()
    >>>
    >>> Dim d As Date
    >>>
    >>> Try
    >>>
    >>> d = Date.Parse(_innerTbx.Text)
    >>>
    >>> errorText = Nothing
    >>>
    >>> _innerCal.SelectedDate = d
    >>>
    >>> Catch
    >>>
    >>> errorText = "Date needs to be specified as mm/dd/yyyy"
    >>>
    >>> End Try
    >>>
    >>> Return d
    >>>
    >>> End Get
    >>>
    >>> Set(ByVal value As Date)
    >>>
    >>> EnsureChildControls()
    >>>
    >>> _innerCal.SelectedDate = value
    >>>
    >>> _innerTbx.Text = value.ToShortDateString
    >>>
    >>> End Set
    >>>
    >>> End Property
    >>>
    >>> Protected Overrides Sub CreateChildControls()
    >>>
    >>> MyBase.CreateChildControls()
    >>>
    >>> _innerTbx = New TextBox
    >>>
    >>> Me.Controls.Add(_innerTbx)
    >>>
    >>> _innerCal = New Calendar
    >>>
    >>> AddHandler _innerCal.SelectionChanged, AddressOf
    >>> _innerCal_SelectionChanged
    >>>
    >>> AddHandler _innerCal.VisibleMonthChanged, AddressOf
    >>> _innerCal_MonthChanged
    >>>
    >>> Controls.Add(_innerCal)
    >>>
    >>> End Sub
    >>>
    >>> Protected Overrides ReadOnly Property TagKey() As
    >>> System.Web.UI.HtmlTextWriterTag
    >>>
    >>> Get
    >>>
    >>> Return HtmlTextWriterTag.Div
    >>>
    >>> End Get
    >>>
    >>> End Property
    >>>
    >>> Protected Overrides Sub AddAttributesToRender(ByVal writer As
    >>> System.Web.UI.HtmlTextWriter)
    >>>
    >>> If Me.Width.IsEmpty Then Me.Width = New Unit(150)
    >>>
    >>> MyBase.AddAttributesToRender(writer)
    >>>
    >>> End Sub
    >>>
    >>> Protected Overrides Sub RenderContents(ByVal writer As
    >>> System.Web.UI.HtmlTextWriter)
    >>>
    >>> _innerTbx.Attributes.Add("Align", "AbsMiddle")
    >>>
    >>> _innerTbx.Width = New Unit(100)
    >>>
    >>> '_innerTbx.Height = New Unit(20)
    >>>
    >>> _innerTbx.RenderControl(writer)
    >>>
    >>> Dim innerid As String = Me.UniqueID & "_inner"
    >>>
    >>> writer.AddAttribute("Align", "AbsMiddle")
    >>>
    >>> writer.AddAttribute("src", "../Images/DropDownBtn.gif")
    >>>
    >>> writer.AddAttribute("onClick", "__datepicker_showpopup('" & innerid &
    >>> "')")
    >>>
    >>> writer.RenderBeginTag(HtmlTextWriterTag.Img)
    >>>
    >>> writer.RenderEndTag()
    >>>
    >>> If errorText <> Nothing Then
    >>>
    >>> writer.AddStyleAttribute("color", "red")
    >>>
    >>> writer.AddStyleAttribute("display", "block")
    >>>
    >>> writer.RenderBeginTag(HtmlTextWriterTag.Span)
    >>>
    >>> writer.Write(errorText)
    >>>
    >>> writer.RenderEndTag()
    >>>
    >>> End If
    >>>
    >>>
    >>> writer.AddStyleAttribute("position", "relative")
    >>>
    >>> writer.RenderBeginTag(HtmlTextWriterTag.Div)
    >>>
    >>>
    >>> writer.AddStyleAttribute("position", "absolute")
    >>>
    >>> writer.AddStyleAttribute("left", "0px")
    >>>
    >>> writer.AddStyleAttribute("top", "0px")
    >>>
    >>> writer.AddStyleAttribute("z-index", "100")
    >>>
    >>> Dim panelvisible As String
    >>>
    >>> If _panelvisible Then panelvisible = "block" Else panelvisible = "none"
    >>>
    >>> writer.AddStyleAttribute("display", panelvisible)
    >>>
    >>> ' writer.AddStyleAttribute("background-color", "white")
    >>>
    >>> writer.AddAttribute("id", innerid)
    >>>
    >>> writer.AddAttribute("onfocusout", "__popup_losefocus(this)")
    >>>
    >>> writer.RenderBeginTag(HtmlTextWriterTag.Div)
    >>>
    >>> _innerCal.RenderControl(writer)
    >>>
    >>> writer.RenderEndTag()
    >>>
    >>> writer.RenderEndTag()
    >>>
    >>> End Sub
    >>>
    >>> Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
    >>>
    >>> MyBase.OnPreRender(e)
    >>>
    >>> commonScript.WritePopupRoutines(Page)
    >>>
    >>> Dim sb As New StringBuilder
    >>>
    >>> If _panelvisible Then
    >>>
    >>> sb.AppendLine("__popup_panel = '" & Me.UniqueID & "_inner';")
    >>>
    >>> End If
    >>>
    >>> sb.AppendLine("function __datepicker_showpopup(name)")
    >>>
    >>> sb.AppendLine("{")
    >>>
    >>> sb.AppendLine(" if (__popup_panel != null)")
    >>>
    >>> sb.AppendLine(" {")
    >>>
    >>> sb.AppendLine("
    >>> document.getElementById(__popup_panel).style.display='none';")
    >>>
    >>> sb.AppendLine(" }")
    >>>
    >>> sb.AppendLine(" __popup_panel=name;")
    >>>
    >>> sb.AppendLine(" var panel=document.getElementById(__popup_panel);")
    >>>
    >>> sb.AppendLine(" panel.style.display='block';")
    >>>
    >>> sb.AppendLine(" var links=panel.getElementsByTagName('A');")
    >>>
    >>> sb.AppendLine(" links[0].focus();")
    >>>
    >>> ' sb.AppendLine(" document.onclick=__popup_clear();")
    >>>
    >>> sb.AppendLine(" window.event.cancelBubble=true;")
    >>>
    >>> sb.AppendLine("}")
    >>>
    >>> Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "popup",
    >>> sb.ToString, True)
    >>>
    >>> Page.MaintainScrollPositionOnPostBack = True
    >>>
    >>> End Sub
    >>>
    >>> Private Sub _innerCal_SelectionChanged(ByVal sender As Object, ByVal e
    >>> As System.EventArgs)
    >>>
    >>> EnsureChildControls()
    >>>
    >>> _innerTbx.Text = _innerCal.SelectedDate.ToShortDateString
    >>>
    >>> End Sub
    >>>
    >>> 'keep the panel for another
    >>>
    >>> Private Sub _innerCal_MonthChanged(ByVal sender As Object, ByVal e As
    >>> MonthChangedEventArgs)
    >>>
    >>> _panelvisible = True
    >>>
    >>> End Sub
    >>>
    >>> End Class
    >>>
    >>> End Namespace
    >>>
    >>>

    >>
    >>

    >
    >
    Cal Who, Jan 8, 2010
    #4
  5. Cal Who

    Patrice Guest

    Patrice, Jan 8, 2010
    #5
  6. Cal Who

    milop Guest

    You're an MVP?

    I've been programming professionally for over 25 years and probably know
    languages you've never heard of.

    I know C/C++, C#, VB, etc.

    Your comment is amateur at best.

    Mike

    "Mark Rae [MVP]" <> wrote in message
    news:...
    >" Cal Who" <> wrote in message
    >news:...
    >
    >> Any helpful comment would be appreciated.

    >
    > http://www.google.co.uk/search?aq=0&oq=AJAX date&sourceid=chrome&ie=UTF-8&q=ajax date picker
    >
    >
    >> Imports Microsoft.VisualBasic

    >
    > Anything which starts like that is *ALWAYS* the wrong answer.
    >
    > Forget VB and all its associated bloat and baggage and move to C'#.
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    milop, Jan 8, 2010
    #6
  7. Cal Who

    Scott M. Guest

    I'm addressing your coding technique, not the overall effect that the code
    acheives.

    -Scott

    " Cal Who" <> wrote in message
    news:...
    > Are you suggesting that people still write code like this.
    > I should study it, maybe improve it but it is not desirable to replace it?
    > Thanks
    >
    > "Scott M." <> wrote in message
    > news:...
    >> Slight correction, on the Dim theString = code dont' forget to put double
    >> quotes around the beginning and end of the string.
    >>
    >> -Scott
    >>
    >> "Scott M." <> wrote in message
    >> news:...
    >>> Well, since VB supports XML as a first class data type, you can reduce
    >>> some of that code that builds up the JavaScript by doing this:
    >>>
    >>> Dim sb As New Text.StringBuilder()
    >>> sb = New StringBuilder
    >>> Dim theString = <myJS>
    >>> var __popup_panel;
    >>> function __popup_clear() {
    >>> if (__popup_panel != null )
    >>> {
    >>>
    >>> document.getElementById(__popup_panel).style.display='none';
    >>> __popup_panel=null;
    >>> }
    >>> }
    >>>
    >>> function __popup_losefocus(panel)
    >>> {
    >>> if (!panel.contains(document.activeElement))
    >>> {
    >>> panel.style.display='none';
    >>> }
    >>> }
    >>> </myJS>
    >>> sb.Append(theString.Value)
    >>>
    >>> Actually, with VS 2010, you could now write this a little bit simpler,
    >>> since VB now supports multiple line statements without the _ line
    >>> continuation char.
    >>>
    >>> Dim sb As New Text.StringBuilder()
    >>> sb = New StringBuilder
    >>> Dim theString As String =
    >>> var __popup_panel;
    >>> function __popup_clear() {
    >>> if (__popup_panel != null )
    >>> {
    >>>
    >>> document.getElementById(__popup_panel).style.display='none';
    >>> __popup_panel=null;
    >>> }
    >>> }
    >>>
    >>> function __popup_losefocus(panel)
    >>> {
    >>> if (!panel.contains(document.activeElement))
    >>> {
    >>> panel.style.display='none';
    >>> }
    >>> }
    >>> sb.Append(theString)
    >>>
    >>> As for why you are importing the Microsoft.VisualBasic Namespace, I'm
    >>> not sure.
    >>>
    >>> Also, with VS 2008, when you drop an .ascx file into an .aspx page, you
    >>> will see the control in the designer.
    >>>
    >>> I think that your code can be reworked to be reduced and that you will
    >>> find it easier to use the .ascx file than previously.
    >>>
    >>> -Scott
    >>>
    >>> " Cal Who" <> wrote in message
    >>> news:...
    >>>> The code below is from the routine DatePicker.vb from one of the 2005
    >>>> starter kits.
    >>>>
    >>>> For one thing - if I use it in a ascx file it can't show in the
    >>>> Designer.
    >>>>
    >>>> For another - since so much is simply string it must require a great
    >>>> mind to debug.
    >>>>
    >>>> I'm wondering is with the latest framework all this is still necessary.
    >>>>
    >>>> Do you think this can be replaced with a reasonable effort with some
    >>>> new control?
    >>>>
    >>>> If so, which one?
    >>>>
    >>>> Is this typical of ASP code. If so I salute anyone who wrote ASP and/or
    >>>> can follow this code.
    >>>>
    >>>> Any helpful comment would be appreciated.
    >>>>
    >>>>
    >>>>
    >>>> Thanks
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>> Imports Microsoft.VisualBasic
    >>>>
    >>>>
    >>>> Namespace My.Library
    >>>>
    >>>> Module commonScript
    >>>>
    >>>> Sub WritePopupRoutines(ByVal Page As System.Web.UI.Page)
    >>>>
    >>>> Dim sb As New Text.StringBuilder()
    >>>>
    >>>> sb = New StringBuilder
    >>>>
    >>>> sb.AppendLine("var __popup_panel;")
    >>>>
    >>>> sb.AppendLine("function __popup_clear() {")
    >>>>
    >>>> sb.AppendLine(" if (__popup_panel != null ) ")
    >>>>
    >>>> sb.AppendLine(" {")
    >>>>
    >>>> sb.AppendLine("
    >>>> document.getElementById(__popup_panel).style.display='none';")
    >>>>
    >>>> sb.AppendLine(" __popup_panel=null;")
    >>>>
    >>>> ' sb.AppendLine(" document.onclick=null;")
    >>>>
    >>>> sb.AppendLine(" }")
    >>>>
    >>>> sb.AppendLine("}")
    >>>>
    >>>> sb.AppendLine("function __popup_losefocus(panel)")
    >>>>
    >>>> sb.AppendLine("{")
    >>>>
    >>>> sb.AppendLine(" if (!panel.contains(document.activeElement))")
    >>>>
    >>>> sb.AppendLine(" {")
    >>>>
    >>>> sb.AppendLine(" panel.style.display='none';")
    >>>>
    >>>> sb.AppendLine(" }")
    >>>>
    >>>> sb.AppendLine("}")
    >>>>
    >>>> Page.ClientScript.RegisterClientScriptBlock(Page.GetType,
    >>>> "PopupRoutines", sb.ToString, True)
    >>>>
    >>>> End Sub
    >>>>
    >>>> End Module
    >>>>
    >>>> Public Class DatePicker
    >>>>
    >>>> Inherits WebControl
    >>>>
    >>>> Implements INamingContainer
    >>>>
    >>>> Private _innerCal As Calendar
    >>>>
    >>>> Private _innerTbx As TextBox
    >>>>
    >>>> Private errorText As String = Nothing
    >>>>
    >>>> Private _panelvisible As Boolean = False
    >>>>
    >>>> Sub New()
    >>>>
    >>>> MyBase.New(UI.HtmlTextWriterTag.Div)
    >>>>
    >>>> End Sub
    >>>>
    >>>> Public Property SelectedDate() As Date
    >>>>
    >>>> Get
    >>>>
    >>>> EnsureChildControls()
    >>>>
    >>>> Dim d As Date
    >>>>
    >>>> Try
    >>>>
    >>>> d = Date.Parse(_innerTbx.Text)
    >>>>
    >>>> errorText = Nothing
    >>>>
    >>>> _innerCal.SelectedDate = d
    >>>>
    >>>> Catch
    >>>>
    >>>> errorText = "Date needs to be specified as mm/dd/yyyy"
    >>>>
    >>>> End Try
    >>>>
    >>>> Return d
    >>>>
    >>>> End Get
    >>>>
    >>>> Set(ByVal value As Date)
    >>>>
    >>>> EnsureChildControls()
    >>>>
    >>>> _innerCal.SelectedDate = value
    >>>>
    >>>> _innerTbx.Text = value.ToShortDateString
    >>>>
    >>>> End Set
    >>>>
    >>>> End Property
    >>>>
    >>>> Protected Overrides Sub CreateChildControls()
    >>>>
    >>>> MyBase.CreateChildControls()
    >>>>
    >>>> _innerTbx = New TextBox
    >>>>
    >>>> Me.Controls.Add(_innerTbx)
    >>>>
    >>>> _innerCal = New Calendar
    >>>>
    >>>> AddHandler _innerCal.SelectionChanged, AddressOf
    >>>> _innerCal_SelectionChanged
    >>>>
    >>>> AddHandler _innerCal.VisibleMonthChanged, AddressOf
    >>>> _innerCal_MonthChanged
    >>>>
    >>>> Controls.Add(_innerCal)
    >>>>
    >>>> End Sub
    >>>>
    >>>> Protected Overrides ReadOnly Property TagKey() As
    >>>> System.Web.UI.HtmlTextWriterTag
    >>>>
    >>>> Get
    >>>>
    >>>> Return HtmlTextWriterTag.Div
    >>>>
    >>>> End Get
    >>>>
    >>>> End Property
    >>>>
    >>>> Protected Overrides Sub AddAttributesToRender(ByVal writer As
    >>>> System.Web.UI.HtmlTextWriter)
    >>>>
    >>>> If Me.Width.IsEmpty Then Me.Width = New Unit(150)
    >>>>
    >>>> MyBase.AddAttributesToRender(writer)
    >>>>
    >>>> End Sub
    >>>>
    >>>> Protected Overrides Sub RenderContents(ByVal writer As
    >>>> System.Web.UI.HtmlTextWriter)
    >>>>
    >>>> _innerTbx.Attributes.Add("Align", "AbsMiddle")
    >>>>
    >>>> _innerTbx.Width = New Unit(100)
    >>>>
    >>>> '_innerTbx.Height = New Unit(20)
    >>>>
    >>>> _innerTbx.RenderControl(writer)
    >>>>
    >>>> Dim innerid As String = Me.UniqueID & "_inner"
    >>>>
    >>>> writer.AddAttribute("Align", "AbsMiddle")
    >>>>
    >>>> writer.AddAttribute("src", "../Images/DropDownBtn.gif")
    >>>>
    >>>> writer.AddAttribute("onClick", "__datepicker_showpopup('" & innerid &
    >>>> "')")
    >>>>
    >>>> writer.RenderBeginTag(HtmlTextWriterTag.Img)
    >>>>
    >>>> writer.RenderEndTag()
    >>>>
    >>>> If errorText <> Nothing Then
    >>>>
    >>>> writer.AddStyleAttribute("color", "red")
    >>>>
    >>>> writer.AddStyleAttribute("display", "block")
    >>>>
    >>>> writer.RenderBeginTag(HtmlTextWriterTag.Span)
    >>>>
    >>>> writer.Write(errorText)
    >>>>
    >>>> writer.RenderEndTag()
    >>>>
    >>>> End If
    >>>>
    >>>>
    >>>> writer.AddStyleAttribute("position", "relative")
    >>>>
    >>>> writer.RenderBeginTag(HtmlTextWriterTag.Div)
    >>>>
    >>>>
    >>>> writer.AddStyleAttribute("position", "absolute")
    >>>>
    >>>> writer.AddStyleAttribute("left", "0px")
    >>>>
    >>>> writer.AddStyleAttribute("top", "0px")
    >>>>
    >>>> writer.AddStyleAttribute("z-index", "100")
    >>>>
    >>>> Dim panelvisible As String
    >>>>
    >>>> If _panelvisible Then panelvisible = "block" Else panelvisible = "none"
    >>>>
    >>>> writer.AddStyleAttribute("display", panelvisible)
    >>>>
    >>>> ' writer.AddStyleAttribute("background-color", "white")
    >>>>
    >>>> writer.AddAttribute("id", innerid)
    >>>>
    >>>> writer.AddAttribute("onfocusout", "__popup_losefocus(this)")
    >>>>
    >>>> writer.RenderBeginTag(HtmlTextWriterTag.Div)
    >>>>
    >>>> _innerCal.RenderControl(writer)
    >>>>
    >>>> writer.RenderEndTag()
    >>>>
    >>>> writer.RenderEndTag()
    >>>>
    >>>> End Sub
    >>>>
    >>>> Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
    >>>>
    >>>> MyBase.OnPreRender(e)
    >>>>
    >>>> commonScript.WritePopupRoutines(Page)
    >>>>
    >>>> Dim sb As New StringBuilder
    >>>>
    >>>> If _panelvisible Then
    >>>>
    >>>> sb.AppendLine("__popup_panel = '" & Me.UniqueID & "_inner';")
    >>>>
    >>>> End If
    >>>>
    >>>> sb.AppendLine("function __datepicker_showpopup(name)")
    >>>>
    >>>> sb.AppendLine("{")
    >>>>
    >>>> sb.AppendLine(" if (__popup_panel != null)")
    >>>>
    >>>> sb.AppendLine(" {")
    >>>>
    >>>> sb.AppendLine("
    >>>> document.getElementById(__popup_panel).style.display='none';")
    >>>>
    >>>> sb.AppendLine(" }")
    >>>>
    >>>> sb.AppendLine(" __popup_panel=name;")
    >>>>
    >>>> sb.AppendLine(" var panel=document.getElementById(__popup_panel);")
    >>>>
    >>>> sb.AppendLine(" panel.style.display='block';")
    >>>>
    >>>> sb.AppendLine(" var links=panel.getElementsByTagName('A');")
    >>>>
    >>>> sb.AppendLine(" links[0].focus();")
    >>>>
    >>>> ' sb.AppendLine(" document.onclick=__popup_clear();")
    >>>>
    >>>> sb.AppendLine(" window.event.cancelBubble=true;")
    >>>>
    >>>> sb.AppendLine("}")
    >>>>
    >>>> Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "popup",
    >>>> sb.ToString, True)
    >>>>
    >>>> Page.MaintainScrollPositionOnPostBack = True
    >>>>
    >>>> End Sub
    >>>>
    >>>> Private Sub _innerCal_SelectionChanged(ByVal sender As Object, ByVal e
    >>>> As System.EventArgs)
    >>>>
    >>>> EnsureChildControls()
    >>>>
    >>>> _innerTbx.Text = _innerCal.SelectedDate.ToShortDateString
    >>>>
    >>>> End Sub
    >>>>
    >>>> 'keep the panel for another
    >>>>
    >>>> Private Sub _innerCal_MonthChanged(ByVal sender As Object, ByVal e As
    >>>> MonthChangedEventArgs)
    >>>>
    >>>> _panelvisible = True
    >>>>
    >>>> End Sub
    >>>>
    >>>> End Class
    >>>>
    >>>> End Namespace
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Scott M., Jan 8, 2010
    #7
  8. Cal Who

    milop Guest

    I don't want to get into an argument but your answer offered no solution for
    the original poster. Instead you knocked a language.

    And you'd think with over 25 years experience you'd have learned that the VB
    vs. C argument is silly and that language wars, in general, are impertinent
    and wasteful.

    "Mark Rae [MVP]" <> wrote in message
    news:epc81$...
    > "milop" <> wrote in message
    > news:...
    >
    > [please don't top-post]
    >
    >> You're an MVP?

    >
    > Yes.
    >
    >
    >> I've been programming professionally for over 25 years

    >
    > Me too.
    >
    >
    >> I know C/C++, C#, VB, etc.

    >
    > So do I - that's how I'm able to compare them...
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    milop, Jan 10, 2010
    #8
  9. Cal Who

    Tom Dacon Guest

    "milop" <> wrote in message
    news:%...
    >I don't want to get into an argument but your answer offered no solution
    >for the original poster. Instead you knocked a language.
    >
    > And you'd think with over 25 years experience you'd have learned that the
    > VB vs. C argument is silly and that language wars, in general, are
    > impertinent and wasteful.


    Right on, milop.

    While I refuse to get involved in yet another immature flame war about VB's
    perceived "deficiencies", Mark's wrong about this, and he's not showing the
    maturity that that amount of experience should have equipped him with. I'd
    normally expect a comment like that from, say, a twenty-five-year-old junior
    programmer whose first and only programming language was C++ or C#, and
    who'd been told by someone else to believe that about VB. Certainly not from
    someone who's been around this business as long as he claims.

    ....speaks someone with over forty years in computer science, and
    professional programming experience in over a dozen programming languages.

    Tom
    Tom Dacon, Jan 10, 2010
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shawn Modersohn

    replaced vs non replaced

    Shawn Modersohn, Jul 19, 2004, in forum: HTML
    Replies:
    4
    Views:
    972
    Shawn Modersohn
    Jul 20, 2004
  2. Guest
    Replies:
    5
    Views:
    610
  3. Ville Vainio
    Replies:
    11
    Views:
    606
    Hamish Lawson
    Aug 10, 2004
  4. Solo.Wolve
    Replies:
    0
    Views:
    284
    Solo.Wolve
    Dec 13, 2006
  5. Solo.Wolve
    Replies:
    2
    Views:
    258
    Solo.Wolve
    Dec 17, 2006
Loading...

Share This Page