Solved

How do I get this VB script in my HTML to work?

Posted on 2014-10-20
2
152 Views
Last Modified: 2014-10-20
I'm unfamiliar with VB and scripting it inside of HTML (.aspx page) I have a segment that I'm trying to get working but am having trouble with one line.

        Protected Overrides Sub OnInit(e As EventArgs)
            InitializeComponent()
            MyBase.OnInit(e)
        End Sub

        Private Sub InitializeComponent()
            Me.ibSearch.Click += New System.Web.UI.ImageClickEventHandler(Me.ibSearch_Click)
            //IN THE LINE ABOVE, I'M BEING TOLD THAT I NEED TO USE 'RaiseEvent'? BUT I'M 
            //SURE THERE'S MORE TO IT AND SOMETHINGS THAT I'M MISSING BUT I'M TOO
           //UNFAMILIAR TO KNOW WHAT. HELP
        End Sub
        
        Sub ibSearch_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs)
            ' Get search terms
            Dim searchTerms As String = txtSearchTerms.Text

            ' Check search terms
            If searchTerms IsNot Nothing Then
                ' Set search output page
                Dim outUrl As String = Page.Request.Path

                ' Build query string
                Dim queryStr As String = (outUrl & "?usterms=" & searchTerms & "&ustype=") + ddlSearchType.SelectedValue

                ' Redirect to search output page
                Page.Response.Redirect(queryStr, True)
            End If
        End Sub

Open in new window


        Private Sub InitializeComponent()
            Me.ibSearch.Click += New System.Web.UI.ImageClickEventHandler(Me.ibSearch_Click)
            //IN THE LINE ABOVE, I'M BEING TOLD THAT I NEED TO USE 'RaiseEvent'? BUT I'M
            //SURE THERE'S MORE TO IT AND SOMETHINGS THAT I'M MISSING BUT I'M TOO
           //UNFAMILIAR TO KNOW WHAT. HELP
        End Sub
0
Comment
Question by:mikesExpertExchange
2 Comments
 
LVL 32

Accepted Solution

by:
it_saige earned 500 total points
Comment Utility
Try:
Private Sub InitializeComponent()
	AddHandler Me.lbSearch.Click, AddressOf Me.ibSearch_Click
End Sub

Open in new window

Or
Sub ibSearch_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles Me.lbSearch.Click
	' Get search terms
	Dim searchTerms As String = txtSearchTerms.Text

	' Check search terms
	If searchTerms IsNot Nothing Then
		' Set search output page
		Dim outUrl As String = Page.Request.Path

		' Build query string
		Dim queryStr As String = (outUrl & "?usterms=" & searchTerms & "&ustype=") + ddlSearchType.SelectedValue

		' Redirect to search output page
		Page.Response.Redirect(queryStr, True)
	End If
End Sub

Open in new window


With the first code block you add an handler.  However, vb allows you to assign the handler directly to the method that the event raises.  So if you use the second code block, remove the code in the first code block.

-saige-
0
 
LVL 1

Author Closing Comment

by:mikesExpertExchange
Comment Utility
That did it. Thank you.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now