Thanks in advance for the response.Where is your event handler code (i.e. Page_Load, subroutine, etc.)? Could you post a small sample?
Hi,
Here is a sample of my code. Whenever, I clicked on the add entry button, then I pressed refresh to refresh the screen, my program always run the addentry_click event handler so my database is getting filled up although I don't want to do that during the refresh.
Thanks,
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.AddEntry.Click += new System.EventHandler(this.AddEntry_Click);
}
//*******************************************************
//
// AddEntry_Click server event handler on this page is used to
// saves a time entry and adds it to the system.
//
//*******************************************************
protected void AddEntry_Click(object sender, System.EventArgs e)
{
// check validation.
if (Page.IsPostBack)
{
ExpiryDateRFV.Validate();
DepartmentListRFV.Validate();
// proceeds if data is valid then create an obejct and save it.
if ( (ExpiryDateRFV.IsValid) && (DepartmentListRFV.IsValid) )
{
ChangeManagement.Announcement announcement = new ChangeManagement.Announcement();
int iResult = announcement.AddEntry();
if (iResult == Constants.SUCCESS)
{
ClearEntryFields();
}
}
}
}
This may be wrong due to the fact I'm not familiar with C#. I use VB.NET myself.
But here it goes...In your AddEntry_Click subroutine you have specified the following:
IF (Page.IsPostBack)
I believe this means that the code gets executed everytime the page is posted back. Try using IF NOT(Page.IsPostBack). I'm not exectly sure of the syntax for C# but you get the idea. This should prevent the code from executing on every post back.
Let me know how you make out.
Hi Todd,
It works. Thanks.
0 comments:
Post a Comment