CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2000
    Location
    Washington (state)
    Posts
    125

    [RESOLVED] Calling javascript function in ASP.NET produces UNWANTED directory listing...

    I have an ASP.NET (c# codebehind) in which a simple <a> tag invokes a javascript function... Calling this function will produce an unwanted directory listing even if the javascript does absolutely nothing... Obviously it intended to do something, but I have boiled this down to the simplest possible code in an effort to figure out what is causing this problem and to provide an example demonstrating the problem for this thread...

    How can I make this directory listing (or attempted directory listing) go away???

    Here is the code that produces this problem:
    Code:
    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="GN3.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    	<HEAD>
    		<title>How do I make this directory listing go away...</title>
    		<meta name="vs_defaultClientScript" content="JavaScript">
    		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    		<script type="text/javascript"> 
    			function Preview()
    			{
    			// do absolutely nothing
    			}
    		</script>
    	</HEAD>
    	<body>
    		<a href="" onclick="Preview()">Click here for an UNWANTED directory listing...</a>
    	</body>
    </HTML>

  2. #2
    Join Date
    Dec 2007
    Posts
    234

    Re: Calling javascript function in ASP.NET produces UNWANTED directory listing...

    I *think* you need to do something like this:

    Code:
    <a href="#" onclick="Preview(); return False;">
    The Return False prevents the click from actually registering. The "#" keeps it from trying to navigate to a new page or anything.

    -tg
    * I don't respond to private requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help - how to remove eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to???
    * On Error Resume Next is error ignoring, not error handling(tm). * Use Offensive Programming, not Defensive Programming.
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN
    MVP '06-'10

  3. #3
    Join Date
    Apr 2000
    Location
    Washington (state)
    Posts
    125

    Thumbs up Re: Calling javascript function in ASP.NET produces UNWANTED directory listing...

    Thank You TechGnome!!! That worked very well!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured