Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1250
  • Last Modified:

ASP.NET problem

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
0
lordiano
Asked:
lordiano
  • 3
  • 2
1 Solution
 
ThogekCommented:
Adding
    SmartNavigation="true"
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>
    </select>

    <iframe id="MyIFrame" name="MyIFrame" src="Blank.html"></iframe>
0
 
lordianoAuthor Commented:
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> ?
0
 
lordianoAuthor Commented:
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.
0
 
ThogekCommented:
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.
0
 
lordianoAuthor Commented:
thanks a lot Thogek!
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now