Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Stop on_click event from firing on Page Reload??? 2

Status
Not open for further replies.

mivey4

Programmer
Dec 8, 2006
10
0
0
US
Hey,

I have a problem that I'm sure someone has to have a very simple answer for.

I have an ASP.net web app that has a save button when clicked will save items in a listbox to a MSSQL 2005 database. Works great!

The problem is whenever the refresh button on the webpage is clicked, the previous save transaction is again played to the database because on on_click event gets fired again. This is not good.

!Page.IsPostback prevents the event from being fired altogether (during the initial page load and any subsequent postbacks. Someone plz, plz, plz tell me what I'm missing here.

Thanks
 
A server button control will ALWAYS cause a postback. Try using an HTML button instead.
 
Thanks jbenson001 for the reply

So based on what you've posted, there isn't anyway to insert records into a database via use of a Standard Button and C# coding?

I mean, I could use an HTML button instead and then I'd have to rewrite the code to perform the insertions using vbscript or javascript. Just seems kinda limited that the ASP.net platform won't adequately support database insertions unless its written in 1 of those 2 languages and an HTML button.

But you're saying this is correct???

 
No that is not what I am saying. What I am saying is that a server side button control will cause a post back.
I guess initally I wasn't understaning what you ment by refresh. Now I see you mean the refresh button on the browser.
There is no way to disable that button so as I see it you have 2 choices:
1.) You can check the database before the Insert to make sure that set of data has not been Inserted already

2.) Use javascript to open a modal window, that does not show the tool bar and enter the data there. This way the refresh cannot casue another set of data to be INserted.
 
So based on what you've posted, there isn't anyway to insert records into a database via use of a Standard Button and C# coding?
If, by a Standard Button, you mean a HTML element tag, then no there isn't anyway to do this unless you post the data to the server. A HTML button is a client-side element, the code-behind is a server-side element. Unless you tell the server what to do, it has no concept of the client.

Just seems kinda limited that the ASP.net platform won't adequately support database insertions unless its written in 1 of those 2 languages and an HTML button
It has nothing to do with ASP.NET - it is a limitation of all web applications as the server simply responds to requests. If you don't give it one, it won't do anyhting.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Very cool.

Thanks guys,

I believe I know what to do to get the results I'm lookin for now with the additional information you've provided.

btw, ca8msm:
By a Standard Button I was talking about the server-side element and not the HTML but I do understand what you're saying.

I really appreciate all the help![thumbsup2]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top