您的位置:首页 > 编程语言

关于DataBind和页面代码执行顺序

2007-05-14 18:32 337 查看
这是我在网上的第一篇技术文档。很可能这种内容已经被不少人研究过,显得过于简单了,不过当时却花了我整整一个下午,所以还是记录一下吧。

先从两个极其简单的问题开始。

问题一:如果页面上有一个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代码如下:


<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>



而Page_Load方法的代码如下:


void Page_Load(object sender, EventArgs e)




{


//调用逻辑结构层,返回集合


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)将代码括起即可


void Page_Load(object sender, EventArgs e)




{


if(!IsPostBack)




{


//调用逻辑结构层,返回集合


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的点击事件属于PostBack,它总会跳过if(!IsPostBack)代码块,因此可以避免DataGrid的重新绑定造成的控件值丢失。

这两个问题仍然显得很没技术含量,因为太常见了。但是,下面开始麻烦了:

仔细看DataGrid的HTML代码和上面那幅页面外观图上的页码,可知DataGrid设置了分页(10条记录一页),而且DataGrid里面还绑定了一个OnPageIndexChanged="dgrdEmpInbox_Page",用来响应翻页事件。

然而,翻页事件OnPageIndexChanged与Button点击事件一样,进入后台后会跳过if(!IsPostBack)这个代码块,但是翻页事件又必须依赖于DataGrid的绑定,即为了正确实现翻页,这一段代码


dgrdEmpInbox.DataSource = aspDataSource;


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;


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="Header" Src="../UserControls/EmpHeader.ascx" %>




<%...@ 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>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息