0

.net question

i have a asp:LinkButton, when clicked it hits the code behind, creates a session and it calls a javascript function to open a new tab with PDF document

this is the button :

 <asp:LinkButton runat="server" CssClass="lnkBtn" ID="btnViewPDF" >
 <img alt="" src="External_Files/images/view_pdf_icon.png" />
  <span>View PDF</span></asp:LinkButton>

code behind :

      Protected Sub btnViewPDF_Click(sender As Object, e As System.EventArgs)
       Handles btnViewPDF.Click

    Session("mina") = hfChartImg.Value
    Page.ClientScript.RegisterStartupScript(Me.GetType(), "_viewPDF", 
       "changeUrl();",     True)
     End Sub

and this is the js function that opens the new tab with the pdf

  function changeUrl(){

      var url = 'CIP_frmCIPEventExplorePdf.aspx?ViewPDF=1&intCIPEventID=' + 
      $('#intCIPEventID').val();
       parent.showNewTab(url, 'CIP Chart - PDF', 'CIP');

     }

this code worked fine till i had to use to wrapp my page content asp:ScriptManager and asp:UpdatePanel

here is what my code looks like now

  <body class="frame_content">
          <form id="CIP_frmCIPEventExplore" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"
              EnablePartialRendering="true"></asp:ScriptManager>
       <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div class="dataview_title" >
          ..............................
            ..........................

       </asp:Panel>
        </ContentTemplate>
            </asp:UpdatePanel>  
       </form>

       </body>

Question when i put a break point at the session line the code doesn't call the javascript function anymore, it hits the line and then the END SUB can any one tell me please where is my problem ?

Borophyll
  • 1,099
  • 2
  • 15
  • 24
Mina Gabriel
  • 23,150
  • 26
  • 96
  • 124

2 Answers2

0

Try this.. I encountered a similar problem where using RegisterStartupScript() would not work. The following worked for me:

<form id="CIP_frmCIPEventExplore" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>   
           ...
        </ContentTemplate>
    </asp:UpdatePanel>
</form>
<script type="text/javascript">
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(function (s, e) {
        changeUrl();
    });
</script>

See: Run javascript function after Postback

Community
  • 1
  • 1
Borophyll
  • 1,099
  • 2
  • 15
  • 24
0

This is a fairly common problem you have to use new method provided by scripmanger So in you code instead of this

Page.ClientScript.RegisterStartupScript

you have to use

ScriptManager.RegisterClientScriptBlock

Have a look at this

http://msdn.microsoft.com/en-us/library/bb350750.aspx

Guru Kara
  • 6,272
  • 3
  • 39
  • 50
  • it did the trick but how can i pastback the original page , what it does now it generate the pdf page with the chart and then it keeps loading the other one , i think if i can do a refresh on this one this will help ,thanks – Mina Gabriel Jul 13 '12 at 12:41
  • Sorry, i coudnt get your question. – Guru Kara Jul 16 '12 at 08:54