Solved

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

Posted on 2014-10-20
2
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

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 …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

705 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