隐藏归档值未在asp.net中维护

时间:2015-01-07 07:00:02

标签: c# asp.net binary-data bytestream

我正在使用ASP.Net下载Image,我使用以下代码:

代码:

Main Method:
protected void btndownload_Click(object sender, EventArgs e)
        {

            FlyerBean objFlyerBean = SaveFlyer();

            if (objFlyerBean == null)
                return;

            BindData(objFlyerBean);

            string downLoadUrl = CommonUtil.GetBaseUrl() + "Preview/flyerview.aspx?FID=" + objFlyerBean.Id + "&Token=" + objFlyerBean.UserId + "&Size=" + 

objFlyerBean.PreviewSize;

            int previewWidth = -1;
            int previwHeight = -1;

            switch (objFlyerBean.PreviewSize)
            {
                case "8-5X11":
                    previewWidth = 885;
                    previwHeight = 980;
                    break;

                case "5X7":
                    previewWidth = 524;
                    previwHeight = 814;
                    break;

                case "4X6":
                    previewWidth = 428;
                    previwHeight = 696;
                    break;


            }




            Thread th = new Thread(delegate()
            {
                byte[] imgbyte = objScrenShotHelper.GenerateScreenshot(downLoadUrl, previewWidth, previwHeight);

                Response.ContentType = "image/png";

                Response.AppendHeader("content-disposition", "attachment; filename=" + DateTime.Now.Ticks + ".png");                
                Response.BinaryWrite(imgbyte);

            });
            th.SetApartmentState(ApartmentState.STA);
            th.Start();
            th.Join();
        }

Inner Methods:
  private FlyerBean SaveFlyer()
        {
            FlyerBean objFlyerBean = new FlyerBean();
            objFlyerBean.Id = string.IsNullOrEmpty(hfFlyerId.Value) ? 0 : Convert.ToInt64(hfFlyerId.Value);
            objFlyerBean.Header = flyerHeader.Text.Trim();

            objFlyerBean.Caption = flyerCaption.Text.Trim();

            objFlyerBean.ChannelId = string.IsNullOrEmpty(hfSelectedChannelId.Value) ? 0 : Convert.ToInt32(hfSelectedChannelId.Value);
            objFlyerBean.ChannelColor = hfchannelColor.Value;
            objFlyerBean.FlyerImageSize = hfFlyerSize.Value;
            objFlyerBean.FlyerLogoImageSize = hfFlyerLogoSize.Value;
            if (!string.IsNullOrEmpty(hfImgePath.Value))
            {
                objFlyerBean.ImagePath = hfImgePath.Value;
                objFlyerBean.ImageName = hfImageName.Value;
            }

            if (!string.IsNullOrEmpty(hflogoPath.Value))
            {
                objFlyerBean.BusinessLogo = hflogoPath.Value;
                objFlyerBean.LogoName = hflogoName.Value;
            }

            objFlyerBean.BusinessName = flyerBusinessName.Text.Trim();

            objFlyerBean.BackGroundColor = hfbgcolor.Value;
            objFlyerBean.PreviewSize = hfViewSize.Value;
            objFlyerBean.FieldsOrder = hfFieldOrder.Value;


            objFlyerBean.UserId = new Guid(Session["user_id"].ToString());

            FlyerBean Result = objFlyerHelper.SaveFlyer(objFlyerBean);
            hfFlyerId.Value = "0";

            if (Result == null)
                return Result;

            if (Result.Id > 0)
            {
                hfFlyerId.Value = Result.Id.ToString();
                ViewState["flyerId"] = hfFlyerId.Value;


            }

            return Result;
        }




 private void BindData(FlyerBean objFlyerBean)
        {
            if (objFlyerBean != null)
            {
                SetBreadCrumb(true);

                hfFlyerId.Value = objFlyerBean.Id.ToString();
                hfHeader.Value = objFlyerBean.Header;
                hfCaption.Value = objFlyerBean.Caption;

                hfImgePath.Value = objFlyerBean.ImagePath;
                hfImageName.Value = objFlyerBean.ImageName;

                hfSelectedChannelId.Value = objFlyerBean.ChannelId.ToString();
                hfchannelColor.Value = objFlyerBean.ChannelColor;

                hfFlyerSize.Value = objFlyerBean.FlyerImageSize;
                hfFlyerLogoSize.Value = objFlyerBean.FlyerLogoImageSize;

                hflogoPath.Value = objFlyerBean.BusinessLogo;
                hflogoName.Value = objFlyerBean.LogoName;

                hfBusinessName.Value = objFlyerBean.BusinessName;

                hfbgcolor.Value = objFlyerBean.BackGroundColor;

                perviewImg.ImageUrl = objFlyerBean.ImagePath;
                previewLogo.ImageUrl = objFlyerBean.BusinessLogo;

                hfViewSize.Value = objFlyerBean.PreviewSize;

                string orderval = "";
                foreach (FlyerElementOrderBean objorder in objFlyerBean.ElementOrderList)
                {
                    if (string.IsNullOrEmpty(orderval))
                    {
                        orderval = orderval + (objorder.ElementOrder - 1);
                    }
                    else
                    {
                        orderval = orderval + "," + (objorder.ElementOrder - 1);
                    }
                }

                hfFieldOrder.Value = orderval;

            }
            else
            {

                SetBreadCrumb(false);

                hfFlyerId.Value = "0";

                hfHeader.Value = "Sign up for Special Offers";
                hfCaption.Value = "and receive a FREE soda with purchase!";
                hfSelectedChannelId.Value = "-2";
                hfchannelColor.Value = "#f68700";
                hfbgcolor.Value = "#ffffff";
                hfFlyerSize.Value = "m";
                hfFlyerLogoSize.Value = "m";

                hfImgePath.Value = CommonUtil.GetBaseUrl() + "images/PrevieImgDefault.png";
                hflogoPath.Value = CommonUtil.GetBaseUrl() + "images/PreviewLogo.png";
                hfImageName.Value = "PrevieImgDefault.png";
                hflogoName.Value = "PreviewLogo.png";
                hfBusinessName.Value = "Pizza by Joe";
                hfViewSize.Value = "8-5X11";
                hfFieldOrder.Value = "0,1,2,3";

            }
        }

但问题是,在执行相同操作时,我在页面上使用的所有隐藏值的值都已丢失。谁能告诉我这个或任何替代方案背后的问题我可以使用。提前致谢。

0 个答案:

没有答案