Click here to Skip to main content
15,906,574 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi guys

I have the code below that runs on page load

C#
if (IsPostBack)
               {
                   if (System.Windows.Forms.MessageBox.Show("Sure want to Cancel Appointment?", "Cancel Appointment",
                              System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == DialogResult.Yes)
                   {
                       systemBusinessLayer = new BusinessLayer();
                       systemBusinessLayer.cancelAppointmentByEmployee(Convert.ToInt32(SlotId), Convert.ToInt32(EmpRecNr));

                   }

               }


Now I have a gridview to cancel an appointment, but it works only if I have "if(!Page.IsPostBack)"

C#
if (!IsPostBack)
               {
                   if (System.Windows.Forms.MessageBox.Show("Sure want to Cancel Appointment?", "Cancel Appointment",
                              System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == DialogResult.Yes)
                   {
                       systemBusinessLayer = new BusinessLayer();
                       systemBusinessLayer.cancelAppointmentByEmployee(Convert.ToInt32(SlotId), Convert.ToInt32(EmpRecNr));

                   }

               }



Is there another way to run the code on top on page load with out executing it?
Posted

Hiiiiiiiiiiii,

No other way............... you must wrote this if(!ispostback) in page load.............
 
Share this answer
 
Comments
Toniyo Jackson 12-Aug-11 5:40am    
Why are you using these many 'i' for i and so many dots. Please avoid it.
Ashika s 12-Aug-11 7:19am    
okay
You dont want to write it in Page_load. You Can use RowCommand event of Gridview.

For Example Cancel Button in ASPX inside Grid

C#
<asp:imagebutton id="CancelButton" runat="server" imageurl="~/images/CancelButton.jpg" commandname="Cancel" xmlns:asp="#unknown" />


C# Code

C#
protected void MainGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
   if (e.CommandName == "Cancel")
   {
     if (System.Windows.Forms.MessageBox.Show("Sure want to Cancel Appointment?", "Cancel Appointment",
                              System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == DialogResult.Yes)
                   {
                       systemBusinessLayer = new BusinessLayer();
                       systemBusinessLayer.cancelAppointmentByEmployee(Convert.ToInt32(SlotId), Convert.ToInt32(EmpRecNr));
   }
     
   }
}
 
Share this answer
 

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