Opening a new window using onclientclick event


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Opening a new window using onclientclick event

  1. #1
    Join Date
    Dec 2004
    Location
    México DF
    Posts
    127

    Opening a new window using onclientclick event

    Dear all,

    I have a button in my .aspx that successfully opens a pdf document in a new window using the following button:

    <asp:button id="btnReporte"
    text="Reporte"
    onclientclick="Navigate('.\\documentos\\83_15.pdf')"
    runat="server" />

    and the following javascript function:

    <script type="text/javascript">
    function Navigate(sRuta)
    {
    javascript:window.open(sRuta);
    }
    </script>

    As you can see the .pdf name is hardcoded. I need to make it a variable, which value is known when I load the .aspx containing the button control...

    Any tip on how I can accomplish that?

    Thank you in advance for your interest!

    mc

  2. #2
    Join Date
    Dec 2004
    Location
    México DF
    Posts
    127
    This is how I solved it:

    I inserted a hidden field in my .aspx page:

    <asp:HiddenField ID="hfRutaReporte1" runat="server" />

    Then in the pageload event I fill the value of this field using the value stored in a Session variable:

    Me.hfRutaReporte1.Value = Session("DocPath").ToString

    Finally, I read the content of the hidden field in my onclientcick event:

    <asp:button id="btnReporte1"
    text="Reporte"
    onclientclick="Navigate(document.form1.item('hfRutaReporte1').value)"
    runat="server" />

    If anyone is interested in the full code, please let me know and I will be happy to share an example.

    Thank you all!

    mc

  3. #3
    Join Date
    Dec 2004
    Location
    México DF
    Posts
    127
    I found a simpler, more elegant way to do the same without hidden fields.

    I just define the onclientclick event in my page load event:

    Me.btnReporte1.OnClientClick = "Navigate('" & Session("DocPath").ToString & "')"

    Hope this helps. If anyone needs more details I'll be happy to help.

    mc

Similar Threads

  1. Regarding closing a pop window
    By Usha.R in forum ASP.NET
    Replies: 1
    Last Post: 02-14-2006, 03:30 AM
  2. How long before the next version??
    By _CAG in forum .NET
    Replies: 146
    Last Post: 08-12-2002, 10:40 PM
  3. Re: App Object (fixes)
    By Rob Teixeira in forum .NET
    Replies: 129
    Last Post: 06-06-2002, 05:23 AM
  4. child window - is it or isn't it?
    By TC in forum VB Classic
    Replies: 8
    Last Post: 09-26-2000, 02:34 AM
  5. child window - is it or isn't it?
    By TC in forum VB Classic
    Replies: 0
    Last Post: 09-25-2000, 09:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center