locked
Addition to MailLink Sample RRS feed

  • Question

  • Hi,

    Class Library project, Framework 4.7.2

    Been looking at the https://msdn.microsoft.com/en-us/library/f820d25y.aspx and to add a few more options and to change the example back to href

    1) Open in New Window (boolean)

    2) always include 'onDragStart="return false;" to every link. So, when used in a VB.net ASP.net project it renders as

    NewWindow='true':

    <a href="bla bla" title="some text here" target="_blank" onDragStart=return false;">My Text Here</a>

    NewWindow='false':

    <a href="bla bla" title="some text here" onDragStart=return false;">My Text Here</a>

    Ideally, I wish to override onDragStart so it doesn't appear in the markup but still doesn't allow the link to be dragged or dropped appearing like so in markup.

    <a href="bla bla" title="some text here">My Text Here</a>

    or

    <a href="bla bla" title="some text here" target="_blank">My Text Here</a>

    Code so far:

        Public Class MailLink
            Inherits WebControl
            <
            Bindable(True),
            Category("Appearance"),
            DefaultValue(""),
            Description("The link (href).")
            >
            Public Overridable Property Href() As String
                Get
                    Dim s As String = CStr(ViewState("Href"))
                    If s Is Nothing Then s = String.Empty
                    Return s
                End Get
                Set(ByVal value As String)
                    ViewState("Href") = value
                End Set
            End Property
    
            <
            Bindable(True),
            Category("Appearance"),
            DefaultValue("false"),
            Description("Open in a new window.")
            >
            Public Property NewWindow() As Boolean
                Get
                    Dim nw As Boolean = CBool(ViewState("Target"))
                    If nw = Nothing Then nw = False
                    Return nw
                End Get
                Set(ByVal value As Boolean)
                    ViewState("Target") = value
                End Set
            End Property
    
            <
            Bindable(True),
            Category("Appearance"),
            DefaultValue(""),
            Description("The text to display on the link."),
            Localizable(True),
            PersistenceMode(PersistenceMode.InnerDefaultProperty)
            >
            Public Overridable Property Text() As String
                Get
                    Dim s As String = CStr(ViewState("Text"))
                    If s Is Nothing Then s = String.Empty
                    Return s
                End Get
                Set(ByVal value As String)
                    ViewState("Text") = value
                End Set
            End Property
    
            Protected Overrides ReadOnly Property TagKey() _
                As HtmlTextWriterTag
                Get
                    Return HtmlTextWriterTag.A
                End Get
            End Property
    
    
            Protected Overrides Sub AddAttributesToRender(
                ByVal writer As HtmlTextWriter)
                MyBase.AddAttributesToRender(writer)
                If NewWindow = True Then
                    writer.AddAttribute(HtmlTextWriterAttribute.Target,
                                    "target" & "_blank")
                End If
                writer.AddAttribute(HtmlTextWriterAttribute.Href, Href.ToLower)
            End Sub
    
            Protected Overrides Sub RenderContents(
                ByVal writer As HtmlTextWriter)
                If (Text = String.Empty) Then
                    Text = "link text goes here"
                End If
                writer.WriteEncodedText(Text)
            End Sub
    
        End Class

    When I build the sample, add to the VS Toolbox and drag to a new aspx page it says something about adding some info to the web.config and I use <pages><controls>...

    DO NOT ASK ME TO ASK THIS IN THE ASP.NET FORUM BECAUSE ITS A COMPLETE WASTE OF TIME. HERE'S WHY: 99.9% OF PEOPLE HAVE BING OR GOOGLE OPEN, TYPE IN VB.NET, LINK THEN PASTE ALL LINKS FOUND LIKE TO A JAVA SAMPLE SO THEY GET SOME POINTS. OTHERWISE, I RECEIVE A LINK TO A LINK TO ANOTHER LINK TO YET ANOTHER LINK WHICH IS ABSOLUTELY NO USE WHATSOEVER, THEY GET A FEW POINTS AND EVERYONE IGNORES MY QUESTION BECAUSE THEY THINK SOMEONE HAS ANSWERED IT.

    Unfortunately, ASP.NET Forums have been working like that for over 10 years which doesn't help anyboby.

    Thank you in advance

    Wednesday, June 6, 2018 10:56 PM

All replies

  • Hi Crouchie2018.

    Your project is asp.net project? If yes, I suggest you to ask your question at asp.net forum, because this forum is vb.net forum, discussing and asking questions about the Visual Basic programming language, IDE, libraries, samples, and tools.

    asp.net forum:

    https://forums.asp.net/

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 7, 2018 2:34 AM