Solved

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

Posted on 2014-10-20
2
159 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 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 40392945
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
ID: 40392967
That did it. Thank you.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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