Click here to Skip to main content
15,884,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi

I want to perform both operations such as inserting and updating on a single button save.?


any suggestions..?
Posted
Comments
Kenneth Haugland 20-Jul-12 8:45am    
Not a good question. Please use the Improve question to update it.
bbirajdar 20-Jul-12 9:28am    
repost http://www.codeproject.com/Questions/425257/how-to-perform-two-different-actions-on-single-but
Sebastian T Xavier 21-Jul-12 0:00am    
Why repost?

Yes it is possible. But you would require to identify which operation is being performed. Such as if you have newly entered data in the input form, you obviously want to insert it. Set a flag in the code saying "INSERT".
When you are editing a record, you would require to update it, while doing this, set the same flag as "UPDATE".

Sample Code:
C#
string private strflag = string.Empty;
protected void Button_Click(object sender, EventArgs e) 
{
   if(strflag.toUpper() == "INSERT")
   {
      //Insert code
   }
   else if(strflag.toUpper() == "UPDATE")
   {
      //Update code
   }   
}
 
Share this answer
 
Comments
shashavali 23-Jul-12 6:45am    
thanks a lot...
can please you explain how to set a flag.?
C#
protected void btnSave_Update_Click(object sender, EventArgs e)
{
//Your server side code for 'Insert'


//Your server side code for 'Update'
}
 
Share this answer
 
Comments
shashavali 20-Jul-12 9:01am    
a new event .net framework 5.0!!!!
bbirajdar 20-Jul-12 9:24am    
Thats the event name and not a new event.. The event name should reflect the functionality it is written for.... you should learn about coding conventions and nomenclatures..'btnSave_Update' is the button id here...
shashavali 20-Jul-12 9:42am    
ok sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900