在Html中
<script language =Javascript >
function addFavourite(companyId,CompanyName)
...{
thisframe.document.location.href ="/Security/AddFavourite.ASPx?relationId="+companyId+"&relationType=company&Subject="+CompanyName+"";
alert(tthisframe.document.location.href );
}
</script>
<a href="Javascript:addFavourite(''<%=CompanyId%>'',''<%=FullName%>'');">收藏此公司</a><iframe id="thisframe" frameborder="0" width="0" height="0"></iframe>
在addFavourite.ASPx.cs中
private void Page_Load(object sender, System.EventArgs e)
...{
if(Context.User.Identity.IsAuthenticated )
...{
relationId=Request["relationId"];
relationType = Request["relationType"];
Subject=Request["Subject"];
Tangsoft.Business.Application.Entities.FavouriteData ds=new Tangsoft.Business.Application.EntitIEs.FavouriteData();
Tangsoft.Business.Application.Entities.FavouriteData.FavouritesRow dr=(Tangsoft.Business.Application.EntitIEs.FavouriteData.FavouritesRow)ds.Favourites.NewRow();
dr.FavouriteId=System.Guid.NewGuid();
dr.RelationId=new Guid(relationId);
dr.RelationType=this.relationType.ToString();
dr.Subject=this.Subject.ToString();
dr.CreatedByUserId=System.Guid.NewGuid();
dr.CreationTime=DateTime.Now;
dr.IsDeleted=false;
try
...{
ds.Favourites.Rows.Add(dr);
}
catch(Exception ex)
...{
string msg= ex.Message ;
}
ServiceInterfaces.FavouriteService.Save(ds);
Page.RegisterClIEntScriptBlock("alert","<script language=Javascript>alert(''該信息已經成功加入您的收藏夾!'')</script>");
}
else
...{
Page.RegisterClIEntScriptBlock("alert","<script language=Javascript>alert(''請先登錄!'')</script>");
}