Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3212706
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:51:57+00:00 2026-05-17T14:51:57+00:00

I am programming in VB.NET. I am trying to make an onClick event for

  • 0

I am programming in VB.NET.
I am trying to make an onClick event for a div tag. How can I make this in the code behind?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T14:51:58+00:00Added an answer on May 17, 2026 at 2:51 pm

    One possible solution would be to create a Webusercontrol with a Panel(will be rendered as DIV) and an invisible Button(Display:none). Onclick of the div you could click the button per javascript which would cause an automatic Postback. In Codebehind you would catch that ButtonClick-Event and Raise a custom event(DivClicked). So you can reuse that control everywhere. Something like this:

    ClickableDiv.ascx

    <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ClickableDiv.ascx.vb" Inherits="WebApplication1.ClickableDiv" %>
    <asp:Panel id="TheDiv" runat="server" onMouseOver="this.style.cursor='pointer'"  onclick="this.nextSibling.click()" /><asp:Button ID="DivButton" runat="server"  />
    

    ClickableDiv.ascx Codebehind

    Partial Public Class ClickableDiv
        Inherits System.Web.UI.UserControl
    
        Public Event DivClicked(ByVal src As ClickableDiv)
    
        Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            Me.DivButton.Style.Add("display", "none")
        End Sub
    
        Public ReadOnly Property Div() As Panel
            Get
                Return Me.TheDiv
            End Get
        End Property
    
        Protected Sub DivButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles DivButton.Click
            RaiseEvent DivClicked(Me)
        End Sub
    
    End Class
    

    And for example in any page(drag&drop it to the designer):

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim imgTest As New Image
            imgTest.ImageUrl = "http://skins.gmodules.com/ig/images/logos/approved/white.png"
            Me.ClickableDiv1.Div.Controls.Add(imgTest)
        End Sub
    
        Private Sub ClickableDiv1_DivClicked(ByVal src As ClickableDiv) Handles ClickableDiv1.DivClicked
            Dim div As ClickableDiv = src
        End Sub
    

    Btw, you could also use the __doPostback-function on the DIV’s onclick event to raise a Postback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a .NET developer trying to make the leap into objective-c iPhone programming. I
Im trying to make a small app in c++ that saves midifiles with this
I am trying my hands on Socket programming in C# (.NET). I have referred
Okay I am trying to make minecraft mods using eclipse. I used this video
I am trying Infer.Net ( An F# Library for Probabilistic Programming ) And running
I'm programming in C# using .Net 3.5, trying to control the format in which
I am trying PetaPoco with my Asp.Net Project. How can I use PetaPoco with
I have been trying to solve this Concurrent Programming exam exercise (in C#): Knowing
I'm programming a COM Interop .NET Assembly (a COM Callable Wrapper) and I'm trying
I am trying to pick up on VB.net and have been programming in c#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.