Results 1 to 4 of 4

Thread: Trigger button_click via checkbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2016
    Posts
    7

    Trigger button_click via checkbox

    Hi there,

    I have been trying to use an asp checkbox to trigger the code of a regular button on the same page. I"m going to remove the button, however I want the same code to be run when a checkbox is checked or the text changes in a textbox.

    Can a checkbox fire the button_click for the button? My code isn't working.

    <asp:CheckBox ID="cbchargesnotongfe10pfc" runat="server" AutoPostBack="true" OnCheckedChanged="Button1_Click" />&nbsp; <-this is not working
    <asp:CheckBox ID="cbchargesnotongfe10f" runat="server" />&nbsp;
    <asp:CheckBox ID="cbchargesnotongfe10poc" runat="server" onchange="totalcharges()" />&nbsp; <- this run javascript fine
    <asp:CheckBox ID="cbchargesnotongfe10fin" runat="server" onchange="totalcharges()" />&nbsp; <- this run javascript fine

    Protected Sub Button1_Click(sender As Object, e As EventArgs)
    Dim feearray As String()

    Also, how would firing the same code work when the text is changed in a textbox? If I use this code:
    asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>

    can I direct every textbox on the page to the same codebehind, or does each textbox have to have it's on codebehind? I want every checkbox and textbox to fire the same codebehind sub.
    Last edited by sking; Dec 3rd, 2022 at 11:03 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Trigger button_click via checkbox

    You can use one handler for many textboxes. I don’t see what you’re saying about the checkboxes? They don’t have a TextChanged event. You could probably use the same event for the checkedchanged event of the checkboxes…

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Trigger button_click via checkbox

    It’s also possible to handle the appropriate event of controls in separate multiple control handlers, then call the same method (sub) from all of your handlers. Mixed multi-handlers only work if the eventhandler has the same arguments passed to it…

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: Trigger button_click via checkbox

    Strictly speaking, you'll get better help in the Asp.Net forum...

    https://www.vbforums.com/forumdispla...d-ASP-NET-Core

    I'll ask a moderator to move your thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width