1

Hello everyone I know may be its childish thing in which I am stuck. I am doing work on vb.net project after a long time so I am facing a little issue in which I stuck. I am working on a project in which I have to call a base class function on button click function. However may be I am doing a mistake in it. I have an aspx page which inherits with common.vb file.

Below I’m using the code,

newProduct.aspx

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="NewProduct.aspx.vb" Inherits="IES_dashboard.common" %>
<%@ Register TagPrefix="inc" TagName="head" Src="~/include/head.ascx" %>
<%@ Register TagPrefix="inc" TagName="header" Src="~/include/header.ascx" %>
<%@ Register TagPrefix="inc" TagName="sidebar" Src="~/include/sidebar.ascx" %>

newProduct.aspx.vb

Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Public Class NewProduct
    Inherits common
Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCancel.Click
        Dim redirect As common = New common()
    End Sub
End Class

common.vb code

Imports Microsoft.VisualBasic


Public Class common
    Public Function response()
        Response.Redirect("main.aspx")
    End Function
End Class

I want to call response function on btnCancel_Click. I will be thankful if someone help me in this issue. Thanks in advance.

1 Answer 1

2

You made NewProduct inherit from Common. In this case, you can think of NewProduct being 'Common'. There's no need to create an instance of it during btnCancel_Click. You can simply invoke the method available on Common (and therefore on NewProduct):

Public Sub btnCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCancel.Click
    response()
End Sub
Sign up to request clarification or add additional context in comments.

2 Comments

thank you so much for reply @Bruno Garcia. However I thought that earlier but it does not work for me :)
There could be something else not working there. This snippet I wrote should work. On your version (creating an instance of Common), you could just call: redirect.response() but in that case there's no need to use inheritance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.