Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AJAX not running on Load event

Status
Not open for further replies.

dpdg

Programmer
May 23, 2005
148
0
0
US
I'm using .net framework 4.0. I have an asp.net site that uses a menu to call a JS function which fires an update panel to load the content area with text -- it works fine. But now the Context.RewritePath method doesn't fire in the Global.asax file.

If I put the page name after the domain name the page_load even doesn't fire and it goes to "The resource cannot be found." error page.

1) Is there any way that I can get the Rewrite method to run when I click on a menu item?

2) Also is there a way to load the default.aspx page and run the ajax method when I enter the URL and press enter? Example:


It worked fine before I implemented the AJAX functionality, but after that it won't post back. I'd like it load the Default.aspx page the first time but after that I would just run the ajax functionality and change the url in the address bar.

I guess I'm wanting my cake and eat it too.

I was really getting tired of my WP blog (written in PHP) taking 15 to 25 seconds to load a page and doing everything I could to get it to run faster. So I decided to write my own blog using AJAX and asp.net.

The post loads instantly with AJAX but I have a lot of bookmarks out there (2 years worth) saved to people's bookmarks bar and if they run click it to go back to my site they'll get a "The resource cannot be found" error.

Is there anyway to get my asp.net site to run the way I want it to?

Here's the code on my default.aspx page:
Code:
   <asp:ScriptManager ID="ScriptManager1" runat="server" />
  <div style="display:none">
    <asp:Button ID="Button1" Text="Submit" OnClick="Button1_Click" runat="server"  />
    <asp:HiddenField ID="HiddenField1" runat="server"  />
  </div>
  <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <Triggers>
      <asp:AsyncPostBackTrigger ControlID="Button1" />
    </Triggers>
    <ContentTemplate>
      <asp:Label ID="PostTitle" runat="server" Font-Size="Large"></asp:Label>
      <asp:LinkButton CssClass="showcomments" ID="lnkShowComments" runat="server">Show Comments</asp:LinkButton>
      <br />
      <asp:Label ID="Content" runat="server" Width="95%" 
      Font-Names="verdana" Font-Size="8pt" Font-Bold="false" ></asp:Label>
    </ContentTemplate>
  </asp:UpdatePanel>

And here's the javascript function the fires it:

Code:
	function GetContent(t) {
		document.getElementById("HiddenField1").value = t;
		var button = document.getElementById("Button1");
		button.click();
	}

Thanks!

Doug
 
Doug,
You could come at this another way.
Look at trapping a 404 in your global.asax (Application_Error). Then just redirect them to the default page.

Lodlaiden

You've got questions and source code. We want both!
Oh? That? That's not an important password. - IT Security Admin (pw on whiteboard)
 
Thanks! That worked out perfect!
 
Now I'd like the rewrite method to run when I click a link that runs the javascript that triggers the updatepanel, so that the URL will change to the correct page name. But I would suppose that could only run on a postback... Is there any way I could do that?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top