Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to submit form when there are more than on buttons by pressing enter

how to submit form when there are more than on buttons by pressing enter

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptcomtutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shashank veerkar
    wrote on last edited by
    #1

    hi.. i hav three buttons on my home page i want to submit form by pressing enter.. there are more than three textboxes.. im using c# code behind..so please give me code in c# or javascript..u can check my home page.. http://www.indicustech.com/wd\_home.aspx shashank

    N 1 Reply Last reply
    0
    • S shashank veerkar

      hi.. i hav three buttons on my home page i want to submit form by pressing enter.. there are more than three textboxes.. im using c# code behind..so please give me code in c# or javascript..u can check my home page.. http://www.indicustech.com/wd\_home.aspx shashank

      N Offline
      N Offline
      NeverHeardOfMe
      wrote on last edited by
      #2

      Here'a a cheap and cheerful answer for two textboxes and two buttons, and it's in VB - but I'm sure you are quite capable of extending it and translating it to C#... purists may grind their teeth, but hey, it works, and that's what counts, right? ;P <%@ Page Language="VB" %> Sub Page_Load(Sender As Object, e As EventArgs) If Not Page.IsPostBack Then Textbox1.Attributes.Add("onblur","document.f1.hidTb.value='';") Textbox2.Attributes.Add("onblur","document.f1.hidTb.value='';") Textbox1.Attributes.Add("onfocus","document.f1.hidTb.value='Textbox1';") Textbox2.Attributes.Add("onfocus","document.f1.hidTb.value='Textbox2';") End If End Sub Sub Submit(Sender As Object, e As EventArgs) If hidTb.Text = "" Then If Sender.ID = "Button1" Then Proc_1() Exit Sub End If If Sender.ID = "Button2" Then Proc_2() Exit Sub End If End If If hidTb.Text = "Textbox1" Then Proc_1() Exit Sub End If If hidTb.Text = "Textbox2" Then Proc_2() Exit Sub End If End Sub Sub Proc_1() ' code to execute when Submit1 is clicked, or 'Enter' hit when focus is in textbox1 lblMsg.Text = "You clicked Submit1 or hit your Enter key while Textbox1 had the focus" End Sub Sub Proc_2() ' code to execute when Submit2 is clicked, or 'Enter' hit when focus is in textbox2 lblMsg.Text = "You clicked Submit2 or hit your Enter key while Textbox2 had the focus" End Sub

      Bos 1:

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups