• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 474
  • Last Modified:

asp.net/ajax: unable to locate root directory on httphandler webpage?!?

Hello.

I'm using DotNetBlogEngine as my infrastructure for an asp.net blog website.  DotNetBlogEngine creates "fake" pages for all blog articles and category pages.  The problem is, when I integrate ajax into one of these "fake" httphandler pages, and then execute the ajax (a button click event in this case), I get errors related to being unable to locate the root directory....

 If you check out my site at http://97.74.54.51/default.aspx (not much to look at.  Just wanted to upload to show the error) , then click the square, blue button on the top right called "Click Here", you'll notice you can click it over and over with no problem.  The content in the blue bar successfully switches back and forth.

Now, however, if you click on the "General" link under "Categories" on the left hand side of the page, this page leads to the error I'm having.  If you click the blue square again on this General page, it works fine the 1st click however the 2nd click should return an invalid image URL when trying to display the original phone advertisement again.  Notice the URL of this page is called "category/General.aspx"?  This page doesn't actually exist.  It's a "fake" page DotNetBlogEngine creates via httphandlers.  Now, if you right click on the invalid image, the URL it displays is "category/images/templateimages/ad.jpg" .  The correct path should not have "category" in it.  

 My imagepath in my image control looks like the following:
ImageUrl="~/Images/TemplateImages/ad.jpg"

Any idea what may be causing this to not look in the root directory?

Thanks.
0
Goalie3533
Asked:
Goalie3533
  • 2
1 Solution
 
lotusnotesnewbieCommented:
Could you tell what script you are writing in Click Here? Are you changing the ImageURL manually anywhere in the code?
0
 
Goalie3533Author Commented:
Hi lotusnotesnewbie.  Thanks for the reply.

I've attached the code I use to execute this (also included my scriptmanager).  Strange thing is I'm not doing too many crazy things.  I just basically have two panels.  One's always visible & the other's invisible when the button (lnkOpen_Close) get clicked.

I'd greatly appreciate any extra help or advice you can offer.

Thanks again.
         <asp:ScriptManager 
            ID="ScriptManager1" 
            runat="server" 
            EnablePartialRendering="true" 
            LoadScriptsBeforeUI="false" 
            ScriptMode="Release" />
 
<asp:LinkButton ID="lnkOpenClose" runat="server" OnClick="lnkOpenClose_Click" Width="136" Height="145" CssClass="OpenCloseButton"></asp:LinkButton>
 
<asp:UpdatePanel ID="OnPageMenuUpdatePanel" runat="server" UpdateMode="Conditional">
<Triggers>
     <asp:AsyncPostBackTrigger
          ControlID="lnkOpenClose"
          EventName="Click" />                        
</Triggers>  
<ContentTemplate>
     <asp:Panel ID="pnlDefault" runat="server" Visible="true">
         <table width="100%">
              <tr>
                   <td align="center" valign="middle">
                        <asp:Image ID="imgAd" runat="server"    
                        ImageUrl="~/images/templateimages/ad.jpg" />
                   </td>
              </tr>
         </table>
     </asp:Panel>                                                    
     <asp:Panel ID="pnlMenuOptions" runat="server" Visible="false">
            ....PANEL CONTENT HERE....          
     </asp:Panel>
 
------------------------------------------
c# code:
    protected void lnkOpenClose_Click(object sender, EventArgs e)
    {
        if (pnlMenuOptions.Visible == true)
        {
              pnlMenuOptions.Visible = false;
              pnlDefault.Visible = true;
        }
        else
        {
              pnlMenuOptions.Visible = true;                           
              pnlDefault.Visible = false;
        }
     }

Open in new window

0
 
Goalie3533Author Commented:
I was able to resolve this error with a solution from someone else.  Here's the solution they posted:

I was able to reproduce the problem you're having on my local machine.

The problem is that when you're on the category page, the first time you do an UpdatePanel button click, the async postback is correctly being done to "category/BlogEngineNET.aspx", but the response coming back to the page includes a new 'formAction' with a value like '../default.aspx?id=19770e74-9ec9-4cde-b2ab-e5051aaaf348'.  Then the next time you do an UpdatePanel button click, the async postback is being incorrectly done to ../default.aspx?id=19770e74-9ec9-4cde-b2ab-e5051aaaf348.

I did this Google search and found one solution that solved the problem (there may be other solutions too -- didn't search for very long).  The solution I found was here.  If you add JeffreyZhao's code somewhere in your page, it fixes it so the async postbacks are done to the correct url.  I added his code right before the closing <body> tag.

<script type="text/javascript">
//<![CDATA[
    Sys.Application.add_load(function()
    {
        var form = Sys.WebForms.PageRequestManager.getInstance()._form;
        form._initialAction = form.action = window.location.href;
    });
//]]>    
</script>  
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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