這是我在網上的第一篇技術文檔。很可能這種內容已經被不少人研究過,顯得過於簡單了,不過當時卻花了我整整一個下午,所以還是記錄一下吧。
先從兩個極其簡單的問題開始。
問題一:如果頁面上有一個server端控件,比如說Button btnNew,頁面後臺代碼有響應這個Button事件的方法btnNew_Click
那麼,當用戶點擊這個Button時,頁面後臺代碼的執行順序是什麼樣的呢?
答案是:首先執行Page_Load方法,然後執行btnNew_Click方法
問題二:如果這個頁面上還有其它server控件,比如說CheckBox或者DropDownList,btnNew_Click方法需要從這些控件中獲取用戶輸入的數據進行處理,而此時Page_Load方法是空的,請問:btnNew_Click方法能夠爭取獲取控件上的數據嗎?
答案是:可以。只要把控件的AutoPostBack屬性值設爲false就行了,否則在進入Page_Load方法時控件值會被刷新成默認值。
兩個很無聊的問題對吧?這是本文後面所要講述的問題的基礎。
那麼再看一個問題:
如果CheckBox與DropDownList這樣的server端控件被綁定在一個DataGrid的每一行,如下圖,虛線框中是一個DataGrid,每一行都綁定了兩個這樣的控件。
DataGrid的HTML代碼如下:
<AlternatingItemStyle CssClass="listtableGREYSTRIP"></AlternatingItemStyle>
<ItemStyle CssClass="bodyText"></ItemStyle>
<HeaderStyle Height="30px" CssClass="listtableHEADLINE"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Select">
<HeaderStyle Width="5%"></HeaderStyle>
<ItemTemplate>
<asp:CheckBox id="chkSelect" Runat="server" AutoPostBack="false"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="IntAspirationId" DataNavigateUrlFormatString="../Employee/AppraiseeView.aspx?intAspSeqNo={0}" DataTextField="StrAspirationContent" HeaderText="Aspiration">
<HeaderStyle Width="40%"></HeaderStyle>
<ItemStyle CssClass="hyperlink"></ItemStyle>
</asp:HyperLinkColumn>
<asp:BoundColumn DataField="StrDateOfCreation" HeaderText="Date Raised">
<HeaderStyle Width="10%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="IntStatusId" HeaderText="Status">
<HeaderStyle Width="15%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="StrMgrId" HeaderText="Currently With">
<HeaderStyle Width="10%"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Action">
<HeaderStyle Width="5%"></HeaderStyle>
<ItemTemplate>
<asp:DropDownList id="cmbAction" CssClass="DropDownListStyle" Runat="server" AutoPostBack="False"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="StrLastActed" HeaderText="Last Acted">
<HeaderStyle Width="10%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn Visible="False" DataField="IntAspirationId"></asp:BoundColumn>
</Columns>
<PagerStyle Position="TopAndBottom" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
而Page_Load方法的代碼如下:
{
//調用邏輯結構層,返回集合
AspirationFcd objAspFcd = new AspirationFcd();
aspDataSource = objAspFcd.GetEmpAspirationListFcd();
//集合中有元素時將集合綁定至DataGrid
if(aspDataSource.Count > 0)
{
pnlDatagrid.Visible = true;
pnlError.Visible = false;
dgrdEmpInbox.Visible = true;
dgrdEmpInbox.DataSource = aspDataSource;
dgrdEmpInbox.DataBind();
}
else
{
pnlDatagrid.Visible = false;
pnlError.Visible = true;
btnEdit.Enabled = false;
}
}
問題:現在btnNew_Click方法還能夠獲取控件值嗎?
答案:不能。因爲Button點擊後,後臺代碼必然首先執行Page_Load方法,而由於Page_Load方法中有DataGrid綁定代碼,控件也被重新綁定爲默認值
解決方法如下:只需用if(!IsPostBack)將代碼括起即可
{
if(!IsPostBack)
{
aspDataSource = objAspFcd.GetEmpAspirationListFcd();
if(aspDataSource.Count > 0)
{
pnlDatagrid.Visible = true;
pnlError.Visible = false;
dgrdEmpInbox.Visible = true;
dgrdEmpInbox.DataSource = aspDataSource;
dgrdEmpInbox.DataBind();
}
else
{
pnlDatagrid.Visible = false;
pnlError.Visible = true;
btnEdit.Enabled = false;
}
}
}
因爲btnNew的點擊事件屬於PostBack,它總會跳過if(!IsPostBack)代碼塊,因此可以避免DataGrid的重新綁定造成的控件值丟失。
這兩個問題仍然顯得很沒技術含量,因爲太常見了。但是,下面開始麻煩了:
仔細看DataGrid的HTML代碼和上面那幅頁面外觀圖上的頁碼,可知DataGrid設置了分頁(10條記錄一頁),而且DataGrid裏面還綁定了一個OnPageIndexChanged="dgrdEmpInbox_Page",用來響應翻頁事件。
然而,翻頁事件OnPageIndexChanged與Button點擊事件一樣,進入後臺後會跳過if(!IsPostBack)這個代碼塊,但是翻頁事件又必須依賴於DataGrid的綁定,即爲了正確實現翻頁,這一段代碼
dgrdEmpInbox.DataBind();
必須放在if(!IsPostBack)之外,否則無論怎樣翻頁,DataGrid永遠會停留在第一頁,並且有時候還會出現DataGrid中的記錄莫名其妙的丟失的現象,還有時候會產生其它異常的翻頁現象,總之就是無法正確進入指定頁。大家可以試試看。
但是把DataGrid的綁定代碼放在if(!IsPostBack)之外,又會產生btnNew_Click總是無法取得控件值的問題。
那麼,怎麼解決呢?
說到這裏,我想應該說明一下這個項目的一些情況了。這是一個rework項目,雖然初次開發我也參與了,但是當時並不負責這個頁面,而由於設計文檔的審覈沒能通過,因此這個項目被退回並要求rework,此時這個頁面因原開發者已經離開項目組,而分配給了我。
原開發者的實現方式是在Button點擊事件產生後,在Page_Load方法中捕捉到控件值並存入頁面的ViewState對象中(其它一些頁面也使用過存入HttpContext.Current.Session中的方法),執行代碼進入btnNew_Click方法後,再從ViewState中取出控件值,並進行驗證,最後調用邏輯層的方法進行業務處理。
但項目被退回rework後一個重要的指標是設法提高性能,而新來的PM認爲將驗證放在後臺代碼對性能有影響,因此要求所有驗證移至客戶端(javascript)。如此一來,使用ViewState或context來存儲控件值的方法就不可行了
(太晚了,明天再寫吧)
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InfyIS.CCM.Business.Entity;
using InfyIS.CCM.Business.Framework;
using ISCCMBizLogic.Framework;
using ISCCMBizLogic.Security;
namespace ISCCMWebApp.Employee
...{
/**//// <summary>
/// Summary description for AppraiseeMain.
/// </summary>
public class AppraiseeMain : Page
...{
protected Button btnAddNew;
protected Button btnEdit;
protected Button btnDelete;
protected Button btnSave;
protected Label lblDelete;
protected Label lblError;
protected Panel pnlError;
protected Panel pnlDatagrid;
protected LinkButton lnkbtnHomeLink;
protected LinkButton hyplHomeLink;
protected DataGrid dgEmpInbox;
protected DataGrid dgrdEmpInbox;
protected string strMaxNo;
protected AspirationCollection aspDataSource;
/**//********************************************************************************
* Purpose: Load/reload Aspirations of an employee.
* Parameters: 1)object sender,EventArgs e
* Returned Value: void
* Calls:
* Programmer's Notes:
*
* ******************************************************************************/
private void Page_Load(object sender, EventArgs e)
...{
InfyIS.CCM.Business.Entity.Employee empMy= (InfyIS.CCM.Business.Entity.Employee)HttpContext.Current.Session["MyAccount"];
Security objSecur = new Security();
if(false == objSecur.IsAuthorized("EmpAspInbox",empMy.StrMailId))
...{
Session.Add("ErrorMsg",ExceptionHandler.SoleInstance.GetMessage(2));
Response.Redirect("../CCMHome.aspx");
}
this.btnDelete.Attributes.Add("OnClick","javascript:return ClickbtnDelete();");
this.btnSave.Attributes.Add("OnClick","javascript:return ClickbtnSave();");
this.btnEdit.Attributes.Add("OnClick","javascript:return ClickbtnEdit();");
this.btnAddNew.Attributes.Add("OnClick","javascript:return ClickbtnAdd();");
AspirationFcd objAspFcd = new AspirationFcd();
objAspFcd.SetCurrentUserDetails(empMy);
empMy.QueryQuota();
strMaxNo = empMy.Max_open_number.ToString();
if(!IsPostBack)
...{
aspDataSource = objAspFcd.GetEmpAspirationListFcd();
PageReload();
}
}
Web Form Designer generated code#region Web Form Designer generated code
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.lnkbtnHomeLink.Click += new EventHandler(this.hyplHomeLink_Click);
this.dgrdEmpInbox.PageIndexChanged += new DataGridPageChangedEventHandler(this.dgrdEmpInbox_Page);
this.dgrdEmpInbox.ItemDataBound += new DataGridItemEventHandler(this.dgrdEmpInbox_ItemDataBound);
this.btnAddNew.Click += new EventHandler(this.btnAddNew_Click);
this.btnSave.Click += new EventHandler(this.btnSave_Click);
this.btnEdit.Click += new EventHandler(this.btnEdit_Click);
this.btnDelete.Click += new EventHandler(this.btnDelete_Click);
this.Load += new EventHandler(this.Page_Load);
}
#endregion
events#region events
private void btnAddNew_Click(object sender, EventArgs e)
...{
}
/**//********************************************************************************
* Purpose: initiate delete operations when delete button is being clicked
* Parameters: 1)object sender,EventArgs e
* Returned Value: void
* Calls:
* Programmer's Notes:
*
* ******************************************************************************/
private void btnDelete_Click(object sender, EventArgs e)
...{
InfyIS.CCM.Business.Entity.Employee empMy = (InfyIS.CCM.Business.Entity.Employee)HttpContext.Current.Session["MyAccount"];
AspirationFcd objAspFcd = new AspirationFcd();
objAspFcd.SetCurrentUserDetails(empMy);
int intCount = 0;
foreach(DataGridItem objItem in dgrdEmpInbox.Items)
...{
CheckBox chkSelect = (CheckBox) objItem.FindControl("chkSelect");
if(chkSelect.Enabled)
...{
int intNumber = Convert.ToInt32(objItem.Cells[7].Text.ToString());
if(chkSelect.Checked)
...{
try
...{
objAspFcd.DeleteEmpAspirationFcd(intNumber);
intCount++;
}
catch(Exception ex)
...{
this.pnlError.Visible = true;
this.lblError.Text = ex.Message.Trim();
}
}
}
}
if(intCount>0)
...{
Page.RegisterStartupScript("","<script language=javascript>window.navigate('../Employee/AppraiseeMain_New.aspx');window.alert('Operation Successful!');</script>");
return;
}
}
/**//********************************************************************************
* Purpose: initiate edit operations when edit button is being clicked
* Parameters: 1)object sender,EventArgs e
* Returned Value: void
* Calls:
* Programmer's Notes:
*
* ******************************************************************************/
private void btnEdit_Click(object sender, EventArgs e)
...{
// int [] arrAspId = new int[2];
string strQuerySeqNo="";
int intCount = 0;
foreach (DataGridItem objItem in dgrdEmpInbox.Items)
...{
CheckBox chkSelect = (CheckBox) objItem.FindControl("chkSelect");
if(chkSelect.Enabled)
if(chkSelect.Checked)
...{
int iNumber = Convert.ToInt32(objItem.Cells[7].Text.ToString());
AspirationFcd aspFcd = new AspirationFcd();
InfyIS.CCM.Business.Entity.Employee emp = (InfyIS.CCM.Business.Entity.Employee)Session["MyAccount"];
aspFcd.SetCurrentUserDetails(emp);
// Aspiration aspToEdit = emp.AspirationCollection.Item(iNumber);
Aspiration aspToEdit = aspFcd.GetEmpAspirationBySeqNoFcd(iNumber);
if(aspToEdit.IntStatusId != 1)
...{
string strErrorMsg = ExceptionHandler.SoleInstance.GetMessage(216);
Page.RegisterStartupScript("","<script>window.alert('"+ strErrorMsg +"');" +
"window.navigate('../Employee/AppraiseeMain_New.aspx');</script>");
return;
}
strQuerySeqNo = strQuerySeqNo + iNumber.ToString() + "-";
intCount++;
}
}
if(intCount < 1)
...{
string strMsg = ExceptionHandler.SoleInstance.GetMessage(201);
Page.RegisterStartupScript("","<script>window.alert('"+strMsg+"');</script>");
return;
}
// Session.Add("intAspSeqNo", arrAspId);
// string strShowOpen = "<script language='javascript'>" +
// "window.open('../Employee/AppraiseeAspiration.aspx?Query=emp_asp_edit&Seq="+ strQuerySeqNo +"',''," +
// "'height=400,width=780, left=80,top=200,channelmode=0,dependent=0,directories=0,fullscreen=0," +
// "location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0');</script>";
// if(!IsClientScriptBlockRegistered("clientScript"))
// RegisterClientScriptBlock("clientScript",strShowOpen);
Page.RegisterStartupScript("","<script language='javascript'>window.navigate('../Employee/AppraiseeMain_New.aspx');"+
"window.open('../Employee/AppraiseeAspiration.aspx?Query=emp_asp_edit&Seq="+ strQuerySeqNo +"',''," +
"'height=400,width=780, left=80,top=200,channelmode=0,dependent=0,directories=0,fullscreen=0," +
"location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0')</script>");
}
/**//********************************************************************************
* Purpose: initiate save operations when save button is being clicked
* Parameters: 1)object sender,EventArgs e
* Returned Value: void
* Calls:
* Programmer's Notes:
*
* ******************************************************************************/
private void btnSave_Click(object sender, EventArgs e)
...{
//Check which row to save
int [] arrAspId = new int[2];
int[] arrAction = new int[2];
int[] arrStatusIds = new int[2];
int intCount = 0;
foreach (DataGridItem objItem in dgrdEmpInbox.Items)
...{
CheckBox chkSelect = (CheckBox) objItem.Cells[0].FindControl("chkSelect");
DropDownList cmbAction = (DropDownList)objItem.Cells[5].FindControl("cmbAction");
if(chkSelect.Enabled && chkSelect.Checked)
if(cmbAction.Enabled)
...{
int intAspSeqNo = Convert.ToInt32(objItem.Cells[7].Text.ToString());
string strStatus = objItem.Cells[3].Text;
if(strStatus.Equals("With Employee for Review"))
arrStatusIds[intCount] = 3;
else if(strStatus.Equals("With Employee for Sign-Off"))
arrStatusIds[intCount] = 5;
arrAspId[intCount] = intAspSeqNo;
int key = Convert.ToInt32(cmbAction.SelectedItem.Value);
if(key != -1)
...{
arrAction[intCount] = key;
intCount++;
}
else
...{
string strMsg = ExceptionHandler.SoleInstance.GetMessage(208);
Page.RegisterStartupScript("","<script>window.alert('"+strMsg+"');window.navigate('../Employee/AppraiseeMain_New.aspx')</script>");
return;
}
}
}
AspirationFcd aspFcd = new AspirationFcd();
InfyIS.CCM.Business.Entity.Employee empMy = (InfyIS.CCM.Business.Entity.Employee)HttpContext.Current.Session["MyAccount"];
aspFcd.SetCurrentUserDetails(empMy);
int intResult = intCount;
for(int intLoop=0;intLoop<intCount;intLoop++)
...{
int[] arrPassAspId = new int[2];
arrPassAspId[0] = arrAspId[intLoop];
arrPassAspId[1] = arrAspId[intLoop];
EnumState enumStateToBe = new EnumState();
if(arrAction[intLoop]==0)
enumStateToBe = EnumState.WithMgrSignOffState;
else if(arrAction[intLoop]==1)
enumStateToBe = EnumState.AbandonedState;
else
enumStateToBe = EnumState.SignedOffState;
string strResult = aspFcd.UpdateAspStatusFcd(arrPassAspId,(EnumState)arrStatusIds[intLoop],enumStateToBe);
InbayFcd objInbayFcd = new InbayFcd();
objInbayFcd.AddInbayEmailRecordFcd(empMy.StrMailId,empMy.StrEmpNo,empMy.StrMgrNo,(EnumState)arrStatusIds[intLoop],enumStateToBe,arrPassAspId[0]);
if(!strResult.Equals("Operation successful"))
intResult--;
}
if(intResult==intCount)
...{
Page.RegisterStartupScript("","<script language='javascript'>window.alert('Operation Successful!');window.navigate('../Employee/AppraiseeMain_New.aspx');</script>");
}
else
...{
string strFail = (intCount-intResult).ToString();
Page.RegisterStartupScript("","<script language='javascript'>window.alert('"+strFail+" operation failed as the current status is modified by Manager.');window.navigate('../Employee/AppraiseeMain_New.aspx');</script>");
}
// Session.Add("intAspSeqNo",arrAspId);
// Session.Add("enumAction",arrAction);
// Session.Add("statusIds",arrStatusIds);
// if(arrStatusIds[0] != (int)EnumState.WithEmpSignOffState && arrStatusIds[1] != (int)EnumState.WithEmpSignOffState)
// {
// Response.Redirect("../Employee/emp_inbox.aspx?Category=Counselling&Command=emp_inbox_save");
// }
// string strShowOpen = "<script language='javascript'>" +
// "window.open('../Employee/emp_comments.aspx?Category=counselling&Command=emp_cmt',''," +
// "'height=400,width=780, left=80,top=200,channelmode=0,dependent=0,directories=0,fullscreen=0," +
// "location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0');</script>";
// if(!IsClientScriptBlockRegistered("clientScript"))
// RegisterClientScriptBlock("clientScript",strShowOpen);
}
/**//********************************************************************************
* Purpose: initiate column value row by row when databinding to Aspiration
* collection
* Parameters: 1)object sender,EventArgs e
* Returned Value: void
* Calls: StateValue(),IsActable(),IsSelectable(),LastAction(),
* GetAllActionsByState()
* Programmer's Notes:
*
* ******************************************************************************/
private void dgrdEmpInbox_ItemDataBound(object sender, DataGridItemEventArgs e)
...{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
...{
int intStatusId = Convert.ToInt32(e.Item.Cells[3].Text);
CheckBox chkSelect = (CheckBox)e.Item.Cells[0].FindControl("chkSelect");
DropDownList cmbAction = (DropDownList)e.Item.Cells[5].FindControl("cmbAction");
chkSelect.Attributes.Add("onclick","javascript:return ClickchkSelect('"+chkSelect.ClientID+"','"+cmbAction.ClientID+"');");
// e.Item.Cells[3].Text = StateFactory.StateValue(intStatusId);
// cmbAction.Enabled = StateFactory.IsActable(intStatusId,EnumRole.Employee);
// chkSelect.Enabled = StateFactory.IsSelectable(intStatusId,EnumRole.Employee);
switch(intStatusId)
...{
case 1: //StateNew
chkSelect.Enabled = true;
cmbAction.Items.Clear();
cmbAction.Items.Add(new ListItem("n/a"));
cmbAction.Enabled = false;
e.Item.Cells[3].Text = "New";
break;
case 2: //With Manager for discussion
case 8:
chkSelect.Enabled = false;
cmbAction.Items.Clear();
cmbAction.Items.Add(new ListItem("n/a"));
cmbAction.Enabled = false;
e.Item.Cells[3].Text = "With Manager for Discussion";
break;
case 3: //With Employee for Review
chkSelect.Enabled = true;
cmbAction.Enabled = true;
cmbAction.Items.Clear();
cmbAction.Items.Add(new ListItem("--Select--","-1"));
cmbAction.Items.Add(new ListItem("Agree To Plan","0"));
cmbAction.Items.Add(new ListItem("Abandon","1"));
cmbAction.Items.Add(new ListItem("Sign-Off","2"));
e.Item.Cells[3].Text = "With Employee for Review";
break;
case 4: //With Manager For Sign-Off
chkSelect.Enabled = false;
cmbAction.Items.Clear();
cmbAction.Items.Add(new ListItem("Agree To Plan"));
cmbAction.Enabled = false;
e.Item.Cells[3].Text = "With Manager for Sign-Off";
break;
case 5: //With Employee For Sign-off
chkSelect.Enabled = true;
cmbAction.Enabled = true;
cmbAction.Items.Clear();
cmbAction.Items.Add(new ListItem("--Select--","-1"));
cmbAction.Items.Add(new ListItem("Sign-Off","2"));
e.Item.Cells[3].Text = "With Employee for Sign-Off";
break;
case 6: //Signed-Off
chkSelect.Enabled = false;
cmbAction.Items.Clear();
cmbAction.Items.Add(new ListItem("SignOff"));
cmbAction.Enabled = false;
e.Item.Cells[3].Text = "SignedOff";
break;
case 7:
chkSelect.Enabled = false;
cmbAction.Items.Clear();
cmbAction.Items.Add(new ListItem("Abandon"));
cmbAction.Enabled = false;
e.Item.Cells[3].Text = "Abandoned";
break;
}
}
}
#endregion
ClientMethods#region ClientMethods
/**//********************************************************************************
* Purpose: Count the number of Aspirations being operated on at one time
* Parameters: 1)object sender,EventArgs e
* Returned Value: void
* Calls:
* Programmer's Notes:
*
* ******************************************************************************/
// public void chk_CheckedChanged(object sender, System.EventArgs e)
// {
// int intSelectedNum = 0;
//
// foreach (DataGridItem objItem in dgrdEmpInbox.Items)
// {
// CheckBox chkSelect = (CheckBox) objItem.Cells[0].FindControl("chkSelect");
//
// if(chkSelect.Checked)
// {
// int intAspSeqNo = Convert.ToInt32(objItem.Cells[7].Text.ToString());
//
// InfyIS.CCM.Business.Entity.Employee emp = (InfyIS.CCM.Business.Entity.Employee)HttpContext.Current.Session["MyAccount"];
// AspirationCollection aspCol = emp.AspirationCollection;
// Aspiration aspSelected = aspCol.Item(intAspSeqNo);
// if(aspSelected == null)
// {
// string strErrorMsg = ExceptionHandler.SoleInstance.GetMessage(215);
// Page.RegisterStartupScript("","<script>window.alert('"+ strErrorMsg +"');" +
// "window.navigate('../Employee/emp_inbox.aspx?Category=counselling&Command=emp_inbox');</script>");
// return;
// }
// if(aspSelected.IntStatusId > (int)EnumState.NewState)
// {
// btnSave.Enabled = true;
// btnDelete.Enabled = false;
// btnEdit.Enabled = false;
// }
// else
// {
// btnSave.Enabled = false;
// btnDelete.Enabled = true;
// btnEdit.Enabled = true;
// }
// intSelectedNum++;
// }
//
// }
// if(intSelectedNum == 0)
// {
// btnSave.Enabled = false;
// btnDelete.Enabled = false;
// btnEdit.Enabled = false;
// }
//
// }
#endregion
/**//********************************************************************************
* Purpose: Redirect to User's home page when CCM home link is clicked.
* Parameters: 1)object sender,EventArgs e
* Returned Value: void
* Calls:
* Programmer's Notes:
*
* ******************************************************************************/
private void hyplHomeLink_Click(object sender, EventArgs e)
...{
InfyIS.CCM.Business.Entity.Employee employee = (InfyIS.CCM.Business.Entity.Employee)HttpContext.Current.Session["MyAccount"];
if(employee != null)
Response.Redirect(employee.AccessTable.StrDefaultPage);
else
...{
Session.Add("ErrorMsg",ExceptionHandler.SoleInstance.GetMessage(5));
Response.Redirect("../CCMHome.aspx");
}
}
protected void dgrdEmpInbox_Page(object source, DataGridPageChangedEventArgs e)
...{
InfyIS.CCM.Business.Entity.Employee empMy = (InfyIS.CCM.Business.Entity.Employee)HttpContext.Current.Session["MyAccount"];
AspirationFcd objAspFcd = new AspirationFcd();
objAspFcd.SetCurrentUserDetails(empMy);
aspDataSource = objAspFcd.GetEmpAspirationListFcd();
PageReload();
dgrdEmpInbox.CurrentPageIndex = e.NewPageIndex;
if(this.aspDataSource != null)
...{
// AspirationCollection dataSource = (AspirationCollection)Session["AspirationCollectionForPaging"];
if(aspDataSource.Count > 0)
...{
pnlDatagrid.Visible = true;
pnlError.Visible = false;
dgrdEmpInbox.Visible = true;
dgrdEmpInbox.DataSource = aspDataSource;
dgrdEmpInbox.DataBind();
}
else
...{
pnlDatagrid.Visible = false;
pnlError.Visible = true;
btnEdit.Enabled = false;
}
}
}
private void PageReload()
...{
if(aspDataSource.Count > 0)
...{
pnlDatagrid.Visible = true;
pnlError.Visible = false;
dgrdEmpInbox.Visible = true;
dgrdEmpInbox.DataSource = aspDataSource;
dgrdEmpInbox.DataBind();
}
else
...{
pnlDatagrid.Visible = false;
pnlError.Visible = true;
btnEdit.Enabled = false;
}
}
}
}
<%...@ Register TagPrefix="CCM" TagName="Footer" Src="../UserControls/Footer.ascx" %>
<%...@ Page language="c#" Codebehind="AppraiseeMain_New.aspx.cs" AutoEventWireup="false" Inherits="ISCCMWebApp.Employee.AppraiseeMain" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Employee Inbox</title>
<script language="JavaScript">...
window.history.forward(1);
</script>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="../stylesheet/Style.css" type="text/css" rel="stylesheet">
<LINK href="../stylesheet/ISstyle.css" type="text/css" rel="stylesheet">
<script language="javascript">...
function ClickchkSelect(strChk,strCmb)
...{
if(document.getElementById(strCmb).disabled==true&&document.getElementById(strChk).checked==true)
...{
var del = parseInt(document.getElementById('DelFlag').value)+1;
document.getElementById('DelFlag').value = del.toString();
}
if(document.getElementById(strCmb).disabled!=true&&document.getElementById(strChk).checked==true)
...{
var ndel = parseInt(document.getElementById('NotDelFlag').value)+1;
document.getElementById('NotDelFlag').value = ndel.toString();
}
if(document.getElementById(strCmb).disabled==true&&document.getElementById(strChk).checked==false)
...{
var del = parseInt(document.getElementById('DelFlag').value)-1;
document.getElementById('DelFlag').value = del.toString();
}
if(document.getElementById(strCmb).disabled!=true&&document.getElementById(strChk).checked==false)
...{
var ndel = parseInt(document.getElementById('NotDelFlag').value)-1;
document.getElementById('NotDelFlag').value = ndel.toString();
}
}
function ClickbtnDelete()
...{
var countNotDel = parseInt(document.getElementById('NotDelFlag').value);
var countDel = parseInt(document.getElementById('DelFlag').value);
if(countNotDel>0)
...{
window.alert("One or more of the aspirations you select can not be deleted. You can only delete the ones with 'New' status!");
return false;
}
else if(countDel <= 0)
...{
window.alert("Please select at least one aspiration to delete!");
return false;
}
else
...{
if(window.confirm('Do you want to delete the aspirations you selected?'))
return true;
else
return false;
}
}
function ClickbtnEdit()
...{
var countNotDel = parseInt(document.getElementById('NotDelFlag').value);
var countDel = parseInt(document.getElementById('DelFlag').value);
if(countNotDel>0)
...{
window.alert("One or more of the aspirations you select can not be edited. You can only edit the ones with 'New' status!");
return false;
}
else if(countDel <= 0)
...{
window.alert("Please select at least one aspiration to edit!");
return false;
}
else
return true;
}
function ClickbtnSave()
...{
var countNotDel = parseInt(document.getElementById('NotDelFlag').value);
var countDel = parseInt(document.getElementById('DelFlag').value);
if(countDel>0)
...{
window.alert("One or more of the aspirations you select can not be saved.");
return false;
}
else if(countNotDel <= 0)
...{
window.alert("Please select at least one aspiration to save!");
return false;
}
else
return true;
}
function ClickbtnAdd()
...{
maxNo = parseInt(document.getElementById("AddFlag").value);
if(maxNo<=0)
...{
alert("You have reached the maximum number of active aspiration.");
return false;
}
else
...{
document.getElementById("AddFlag").value = maxNo.toString();
window.open('../Employee/AppraiseeAspiration.aspx?Query=emp_asp_new','','height=400,width=780,left=80,top=200,channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0');
return false;
}
}
</script>
</HEAD>
<body class="bodyTEXT" MS_POSITIONING="GridLayout">
<form id="FormCCM" runat="server">
<CCM:HEADER id="EmpHeader" runat="server"></CCM:HEADER>
<table style="WIDTH: 976px; HEIGHT: 384px" height="384" cellSpacing="0" cellPadding="0"
width="976" border="0">
<tr height="5%">
<td>
<!--Header Space -->
<table id="header" height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td>
<table cellSpacing="0" cellPadding="0">
<tr>
<td class="secondnavGREEN"></td>
<td class="secondnavSEPERATE" align="center"><A class="secondnavLINKON" href="../Employee/AppraiseeMain_New.aspx">Aspirations</A>
</td>
<td><IMG class="secondnavSEPERATE" src="../images/seperator.gif" border="0">
</td>
<td class="secondnavSEPERATE" align="center"><A class="secondnavLINKOFF" href="../Employee/AppraiseeCareerPlan.aspx">Career
Planning </A>
</td>
<td><IMG class="secondnavSEPERATE" src="../images/seperator.gif" border="0">
</td>
<td class="secondnavSEPERATE" align="center"><A class="secondnavLINKOFF" href="../DashBoard/PerformanceData.aspx">My
Dashboard </A>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<!--Information Space -->
<table id="information" height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr vAlign="top">
<!--Internal Right Space -->
<td style="BORDER-TOP: silver 1px dotted" align="center" width="85%">
<table id="rightside" width="100%">
<tr>
<td>
<table id="internalRightHeader" cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td style="HEIGHT: 18px"><asp:linkbutton id="lnkbtnHomeLink" runat="server" CssClass="breadcrumbLINK"><FONT size="1">CCM</FONT></asp:linkbutton><FONT size="1">></FONT>
<A class="breadcrumbLINK" href="../Employee/emp_inbox.aspx?Category=counselling&Command=emp_inbox">
<FONT size="1">Employee</FONT></A><FONT size="1">></FONT> <FONT size="1">Aspirations</FONT>
</td>
<td style="HEIGHT: 18px" align="right"><IMG src="../images/help_FineGround_0nmwhres3t3vo4dboir2qje21_FGN_V01.gif" border="0">
<IMG class="secondnavSEPERATE" src="../images/seperator.gif" border="0"> <IMG onmouseover="this.style.cursor='hand'" onclick="window.print()" src="/ISCCMWebApp/images/print.gif"
border="0">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table id="internalRightBody" height="80%" width="100%" border="0">
<!--Body Space -->
<tr height="100%" width="100%">
<td><asp:panel id="pnlError" Width="100%" Runat="server">
<TABLE class="errorTable" style="WIDTH: 960px; HEIGHT: 34px" borderColor="#cc0000" width="960">
<TR>
<TD><IMG src="../images/error.gif" border="0">
<asp:Label id="lblError" CssClass="tableTEXT" Runat="server" Width="920px" Visible="True">No aspirations to display</asp:Label></TD>
</TR>
</TABLE>
</asp:panel></td>
</tr>
<tr height="100%" width="100%">
<td align="center"><asp:panel id="pnlDatagrid" Runat="server" Visible="False">
<asp:datagrid id="dgrdEmpInbox" runat="server" CssClass="datagridStyle" Width="100%" Visible="False"
PagerStyle-CssClass="" OnPageIndexChanged="dgrdEmpInbox_Page" AllowPaging="True" AutoGenerateColumns="False">
<AlternatingItemStyle CssClass="listtableGREYSTRIP"></AlternatingItemStyle>
<ItemStyle CssClass="bodyText"></ItemStyle>
<HeaderStyle Height="30px" CssClass="listtableHEADLINE"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Select">
<HeaderStyle Width="5%"></HeaderStyle>
<ItemTemplate>
<asp:CheckBox id="chkSelect" Runat="server" AutoPostBack="false"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:HyperLinkColumn Target="_blank" DataNavigateUrlField="IntAspirationId" DataNavigateUrlFormatString="../Employee/AppraiseeView.aspx?intAspSeqNo={0}"
DataTextField="StrAspirationContent" HeaderText="Aspiration">
<HeaderStyle Width="40%"></HeaderStyle>
<ItemStyle CssClass="hyperlink"></ItemStyle>
</asp:HyperLinkColumn>
<asp:BoundColumn DataField="StrDateOfCreation" HeaderText="Date Raised">
<HeaderStyle Width="10%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="IntStatusId" HeaderText="Status">
<HeaderStyle Width="15%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="StrMgrId" HeaderText="Currently With">
<HeaderStyle Width="10%"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Action">
<HeaderStyle Width="5%"></HeaderStyle>
<ItemTemplate>
<asp:DropDownList id="cmbAction" CssClass="DropDownListStyle" Runat="server" AutoPostBack="False"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="StrLastActed" HeaderText="Last Acted">
<HeaderStyle Width="10%"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn Visible="False" DataField="IntAspirationId"></asp:BoundColumn>
</Columns>
<PagerStyle Position="TopAndBottom" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
</asp:panel></td>
</tr>
</table>
<br>
<p align="center"><asp:button id="btnAddNew" runat="server" CssClass="tableBUTTON" Text="Add New Aspiration..."></asp:button><asp:button id="btnSave" runat="server" CssClass="tableBUTTON" Text="Save"></asp:button><asp:button id="btnEdit" runat="server" CssClass="tableBUTTON" Text="Edit"></asp:button><asp:button id="btnDelete" runat="server" CssClass="tableBUTTON" Text="Delete"></asp:button></p>
<input
id=AddFlag type=hidden value="<%=strMaxNo%>"
> <input id="NotDelFlag" type="hidden" value="0"> <input id="DelFlag" type="hidden" value="0">
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<CCM:FOOTER id="footer" runat="server"></CCM:FOOTER></form>
</body>
</HTML>