In my webpage, I have a button "SAVE DRAFT". The first time it is clicked the record must be inserted and the text of the button would be changed as "Update Draft". Then how manytimes the button is hit, it should just update the record. However if the user goes from that page and enters this page again it should go back to "save draft" and rec insertion. How can I do this?

You could save the primary key in hidden fields on the web form after the initial save. If the value of the primary key is null or blanks (which is an invalid value for a primary key) you know that the record needs to be inserted. If it contains a value, you know you need to update the record. This will also ensure that you have the primary key available for the Update process.

The nature of web pages should guarantee that if you navigate away from this page and then back to this page from another page that this will always be true (except, maybe, if they used the back button on the browser).

You could add an extra piece of mind by clearing the primary key field in teh page load when Not Page.IsPostBack.

if(primary<>0)
{
Update()
}
else
{
add()}
}

Thanks

You could save the primary key in hidden fields on the web form after the initial save. If the value of the primary key is null or blanks (which is an invalid value for a primary key) you know that the record needs to be inserted. If it contains a value, you know you need to update the record. This will also ensure that you have the primary key available for the Update process.

The nature of web pages should guarantee that if you navigate away from this page and then back to this page from another page that this will always be true (except, maybe, if they used the back button on the browser).

You could add an extra piece of mind by clearing the primary key field in teh page load when Not Page.IsPostBack.

Thanks... Ur idea did the trick!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.