ASP.NET problem

Posted on 2005-04-22
Last Modified: 2008-02-26
I have a ASPX page with 2 controls. 1 is IFrame control thats being used to display PDF files, 1 ListBox control with the PDF filenames.

Right now the ASPX page is configured so that whenever the ListBox SelectedIndex changes, it will postback and load the corresponding PDF file to the IFrame. I have set the loading of filenames for ListBox to !PostBack so that I only load the filenames at the initial page_load.

The problem i have right now is that whenever user changes the selection in the listbox, I can see the ListBox is being re-rendered again becaues it went away then came back a second later.

Is there a way to render the page so that the ListBox will not be rendered everytime a SelectedIndex event is fired??

Thank you very much
Question by:lordiano
    LVL 15

    Accepted Solution

    to the ASPX file's <%@ Page %> directive might get you what you're looking for.

    Alternatively, there's no real need to post back to the server at all, with something mundane like:

        <select onchange="var url = this.options[this.selectedIndex].value; if(url != '') document.getElementById('MyIFrame').src = url;">
            <option value="">Pick a document</option>
            <option value="PDF1.pdf">PDF #1</option>
            <option value="PDF2.pdf">PDF #2</option>
            <option value="PDF3.pdf">PDF #3</option>

        <iframe id="MyIFrame" name="MyIFrame" src="Blank.html"></iframe>

    Author Comment

    Is that gonna be done in the HTML JavaScript??
    I am not an expert in JavaScript. Can you maybe give me a more detailed explanation of where to insert the <Select> </Select> ?

    Author Comment

    One more thing is that I am using ListBox because I need to be able to load the filename dynamically at the start time.
    So I cannot really hardcode the Path (URL) to the PDF File.
    LVL 15

    Expert Comment

    The <select>...</select> is your dropdown.  Put it wherever you were going to put your ListBox (or <asp:DropDownList>) control.

    And yes, this is client-side JavaScript code fired from within the HTML.  All on the client -- no need to hit or wait on the server.

    The HTML code (<option> tags, etc.) can be written out dynamically, if necessary, either via simple Response.Write calls, or by instantiating server-side HTML objects and adding them to the page.  Or, it may be simpler, in that case, to combine the two methods:

        <asp:DropDownList ... id="ddlDocs">

        <iframe id="MyIFrame" name="MyIFrame" src="Blank.html"></iframe>

    and, in your programmatic code (or code-behind), in addition to doing whatever you do to add the document options (or list-items) to the DropDownList, call

        ddlDocs.Attributes.Add("onchange", "var url = this.options[this.selectedIndex].value; if(url != '') document.getElementById('MyIFrame').src = url;");

    This call could go in the Page_Load method (Load event), or in the Pre_Render event.

    Hope that helps.

    Author Comment

    thanks a lot Thogek!

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now