Avatar of Sam T
Sam T
 asked on

Button needs to be clicked twice to trigger btnSaveEvent() in VB.net

I have a form on web application, I load the field values on the form and click the save button and it doesn't save the record on the database at first click but if I press the button again it saves it. I put the breakpoint on my Page_Load()event and tried debugging it so what happens is as I run the application, Page_Load() gets executed populates the data on the grid. Now, if I enter field values and click save, it again goes to Page_Load() event but it doesn't go to button_save() event. But if I click it again then it goes to Page_Load() and then goes to button_Save() and saves the record.

I want to click the mouse button once and save the record, how could I be able to do that? I am using VB.NET. Thank you.
ASP.NETVisual Basic.NET

Avatar of undefined
Last Comment
Arana (G.P.)

8/22/2022 - Mon
Arana (G.P.)

See if removing the Javascript ONCLICK properties helps it trigger at the first time.
Also when you edit the grid does it postback the data? or does it trigger a grid.changed event?
when you edit grid and then click save button the textbox loses focus and  might be triggering other events instead of the save button
Sam T

I removed the ONCLICK Properties from Javascript still does the same thing

I put the field values on the text box and click the save. It goes to form_load() event but it doesn't call the btnSave() event. But on the next Save Click it goes to form_load()event and then goes to btnSave()event and display the grid result like shown above. 
David Johnson, CD

are you using a jfavascript button or a web form button?
It shouldn't be reloading the page the button_click event shuld be fireing
Your help has saved me hundreds of hours of internet surfing.
Sam T

Thanks David, that is what I am expecting it should not reload the page but when I put the break point in the form_load() event every time I save button the first thing it does is it loads the page and during the second click it again calls Page_Load() and then goes to btnSave_Click().  Below is the btnSave_Click() event

Protected WithEvents btnSave As Global.System.Web.UI.WebControls.Button

Open in new window

Sam T

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Arana (G.P.)

Exactly what I was trying to get at with my previous comment, but you never answered it.
textchanged event was interfering with the click event,  

This is what I was trying to say in above answer, hence asking if it was postingback but  you did not answer, and if you had events after editing the grid,
 but I guess I didnt explain well enough.