Welcome to WebmasterWorld Guest from 34.238.189.171

Forum Moderators: ocean10000

Message Too Old, No Replies

Server.Transfer and Button Click() not playing nicely

     
1:19 pm on Sep 8, 2009 (gmt 0)

New User

10+ Year Member

joined:June 17, 2009
posts: 28
votes: 0


Hi everyone,

This is going to be a long one so please bear with me.

I've built a site where Global.asax matches the url to my Sitemap and loads in the corresponding .aspx page accordingly.

So: blog/blogcommentform.aspx loads in managed_content/pages/28/page28.aspx

There's a long explanation for this but it's basically so we can use our existing content management tool.
(The long explanation: http://www.webmasterworld.com/microsoft_asp_net/3935014.htm [webmasterworld.com])

My problem occurs when I have a form on the page. If the form is submited using a submit button, there isn't a problem (I've set the preserveForm value to "true"), but when I try and submit the data through a button click it just won't work.


protected void CommentSubmit_Click(object sender, EventArgs e)
{
Response.Write("BUTTON CLICKED");
}

displays nothing.

I've built and tested the form outside of my main project so am confident that the problem's not in the form, but is caused by the server.transfer.

I don't quite understand when the CommentSubmit occurs. Is it when the page reloads? Or before?

Any indicators as to where I should start looking would be very helpful.

Thanks,
Kate

[edited by: Ocean10000 at 1:41 pm (utc) on Sep. 8, 2009]
[edit reason] Fixing Link [/edit]

1:39 pm on Sept 8, 2009 (gmt 0)

New User

10+ Year Member

joined:June 17, 2009
posts: 28
votes: 0


Ah - I should have said, I needed to hard-code the url in the form action to get it to go to the right place. Left to its own devices it loaded managed_content/pages/28/page28.aspx and worked perfectly.

Further googling revealed this MS bug: [support.microsoft.com...]

So, I *think* I am going to let it load in page28.aspx and do some url rewriting instead.

Oh joy.

6:00 pm on Sept 8, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


I haven't the time to test at the moment, but after reading the MS bug report, it looks like replacing
Server.Transfer(string.Format("/pages/{0}/page{0}.aspx", node));
with
this.Context.RewritePath(string.Format("/pages/{0}/page{0}.aspx", node));
in your global.asax might do the trick
8:07 am on Sept 9, 2009 (gmt 0)

New User

10+ Year Member

joined:June 17, 2009
posts:28
votes: 0


It worked! That's brilliant Marcel, thanks.

I'll have to remember that Server.Transfer and forms do not mix in future...

11:06 am on Sept 9, 2009 (gmt 0)

New User

10+ Year Member

joined:June 17, 2009
posts: 28
votes: 0


OK, it's worked, but....

Now all the images and links on the master page which contained "~" and runat=server are bouncing out of my virtual directory. I have pages on many levels so the links / images need to come from the root of the site.

I have looked at using VirtualPathUtility to stop this, but don't know where to start.

[msdn.microsoft.com...]

Ideally I don't want to have to call a method for every image / link etc on the site.

I think I read somewhere that VirtualPathUtility would sort of tell the "~" where to go to, but I might be confusing myself.

Not sure if this should be a new thread...? Sorry.

11:30 am on Sept 9, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


Links to images and such from the root of the website should also work without the tilde, ie. "/dir/img.jpg" instead of "~/dir/img.jpg" (even if they have the runat="server" attribute)

You might notice that the links and images are broken when debugging after changing this, to remedy this you can change the 'Virtual Path' property of the project to '/'. (Click on the project in the solution explorer and then change the settings in the Properties box.)

12:49 pm on Sept 9, 2009 (gmt 0)

New User

10+ Year Member

joined:June 17, 2009
posts: 28
votes: 0


My site is in a virtual directory so the url is labs.webdevelopment/dotnettemplate - making the img scr start with "/" means it's looking in the labs.webdevelopment, not in the dotnettemplate.

At some point I will have nested sites (/dotnettemplate/yearlyreview etc) using this template, which is why I want to avoid hard coding in the full path.

1:15 pm on Sept 9, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


oh sorry, you mentioned the the root of the site, so I assumed the root of the website instead of the web application.

It might be an idea to take a step back and see if there may be better options open to you such as true URL rewriting or maybe System.Web.Routing [msdn.microsoft.com]

1:21 pm on Sept 9, 2009 (gmt 0)

New User

10+ Year Member

joined:June 17, 2009
posts:28
votes: 0


Hehe - that was just what I was thinking. I seem to be making more and more edits to accommodate differing the URL / page location. Maybe it's time to admit defeat.

Thanks for your help.

2:55 pm on Sept 10, 2009 (gmt 0)

New User

10+ Year Member

joined:June 17, 2009
posts: 28
votes: 0


Right, admitting defeat wasn't an option.

I've decided that I'm going to carry on with this version of my .NET template for a while, and then look at improving / rebuilding internal cms / moving to .NET MVC at a later date (when my .NET skills are a little better!).

Anyway, I'm here because the problem I had was caused by a true that should have been false.

Changing:


this.Context.RewritePath(string.Format("~/managed_content/pages/{0}/page{0}.aspx", GlobalVariables.PageID),true);

to:

this.Context.RewritePath(string.Format("~/managed_content/pages/{0}/page{0}.aspx", GlobalVariables.PageID),false);

worked!

Should have read this a bit more closely: [msdn.microsoft.com...]

Ta, Kx

3:43 pm on Sept 10, 2009 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


Thanks for the extra info, I hadn't really looked further into it, but I've also learnt something new today.