DropDownList选定索引更改事件触发后刷新页面 [英] Refresh Page after DropDownList Selected Index Changed Event Fired

查看:74
本文介绍了DropDownList选定索引更改事件触发后刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.....
当我选择value ="Pdf"时,它会成功执行,但是在此之后,当要选择Value ="Word"事件时,不会触发(也写成autopostback ="true")


以下是任何人都知道的代码.... z回复......




hi.....
when i selected value="Pdf" it executes successfully but after that when am going to select Value="Word" event is not fired (also written autopostback="true")


below is the code any body knows pl....z Reply......




protected void ddl_chanched(object sender, EventArgs e)
       {

               if (DropDownList1.SelectedValue == "Pdf")
               {
                   Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                   PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                   pdfDoc.Open();
                   using (MemoryStream stream = new MemoryStream())
                   {
                       Chart1.SaveImage(stream, ChartImageFormat.Png);
                       iTextSharp.text.Image chartImage = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
                       string lbl1 = Label1.Text.ToString();
                       pdfDoc.Add(new Paragraph(lbl1));
                       chartImage.ScalePercent(75f);
                       pdfDoc.Add(chartImage);
                       pdfDoc.Close();

                       Response.ContentType = "application/pdf";
                       Response.AddHeader("content-disposition", "attachment;filename=Chart.pdf");
                       Response.Cache.SetCacheability(HttpCacheability.NoCache);
                       Response.Write(pdfDoc);

                       Response.End();








                   }


           }
           else if (DropDownList1.SelectedValue == "Word")
           {

                   Page.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
                   string tmpChartName = "test2.jpg";
                   string imgPath = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName;

                   Chart1.SaveImage(imgPath);
                   string imgPath2 = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName);

                   Response.Clear();
                   Response.ContentType = "application/vnd.ms-word";
                   Response.AddHeader("Content-Disposition", "attachment; filename=test.doc;");
                   StringWriter stringWrite = new StringWriter();
                   HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
                   string headerTable = @"<table><tr><td><img src='" + imgPath2 + @"' \></td></tr></table>";
                   Response.Write(headerTable);
                   Response.Write(stringWrite.ToString());
                   Response.End();
               }
           }
           }

推荐答案

您的下拉菜单正在触发该事件.唯一的事情是它不在word块(else...if块)内.可能是因为字符串匹配.可能是您在小写情况下给出了价值,而在不同情况下进行了检查.在这种情况下,请始终使用断点并尝试单步执行代码.
试试这个:
Your dropdown is firing the event. Only thing is it is not going inside word block(else...if block). It may be because of string matching. May be you have given value in small case and checking in different case. In this kind of situations always use breakpoint and try stepping through the code.
Try this:
protected void ddl_chanched(object sender, EventArgs e)
{    
    if (DropDownList1.SelectedValue.ToUpper == "PDF")
    {
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        using (MemoryStream stream = new MemoryStream())
        {
            Chart1.SaveImage(stream, ChartImageFormat.Png);
            iTextSharp.text.Image chartImage = iTextSharp.text.Image.GetInstance(stream.GetBuffer());
            string lbl1 = Label1.Text.ToString();
            pdfDoc.Add(new Paragraph(lbl1));
            chartImage.ScalePercent(75f);
            pdfDoc.Add(chartImage);
            pdfDoc.Close(); 
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=Chart.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Write(pdfDoc);                        
            Response.End();
        }       
    }
    else if (DropDownList1.SelectedValue.ToUpper() == "WORD")
    {       
        Page.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
        string tmpChartName = "test2.jpg";
        string imgPath = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName;

        Chart1.SaveImage(imgPath);
        string imgPath2 = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName);

        Response.Clear();
        Response.ContentType = "application/vnd.ms-word";
        Response.AddHeader("Content-Disposition", "attachment; filename=test.doc;");
        StringWriter stringWrite = new StringWriter();
        HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        string headerTable = @"<table><tr><td><img src="" + imgPath2 + @""></img></td></tr></table>";
        Response.Write(headerTable);
        Response.Write(stringWrite.ToString());
        Response.End();
    }
    DropDownList1.AutoPostBack = true;
} 



希望对您有所帮助.
--Amit



Hope it helps.
--Amit


当时您的Dropdown所选索引发生更改时,将触发第一个page_load事件,因此将断点放在page_load事件中,并检查此处是否将所选索引设置为0或下拉列表中的第一个值.
When your Dropdown selected index change at that time first page_load event fired so put the break point at page_load event and check if here you set selected index become 0 or first of the dropdown values.



问题是由于在每个条件块上都结束了响应对象.没有地方可以返回true来使控件回发.
Hi,
The problem is because of response object that ends on every block of condition . There is no place to return true to make control do post-back.


这篇关于DropDownList选定索引更改事件触发后刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆