Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Title # Comments Views Activity
asp.net, radiobuttonlist, c# 3 69
Display info from DB to Label in asp.net 7 44
.NET Redemption/Outlook Examples 3 32
Javascript function 3 19
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

732 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