Not sure this is the right place to ask this, but there is not a forum section that is dedicated to custom and user controls.
Anyway, my question is quite straight forward: I have an ASP button in my user control. When I click it, the page gets reloaded and a question mark ('?') is added to the URL.
How can I avoid this? I am not using querystring...
If you have a ? in the url it seems that your form will be submitted as HTTP GET. So if you want to use PostBacks you have to add the attribute runat="server" to your form. If you are using http form submittion you can set the attribute method="POST" which will submit the form as HTTP POST
I can replicate the issue, and looking into it I think it might be a bug.
It comes down to the UrlRewritterFormWritter which is registerd in App_Browser/Form.Browser. It does look to do a check for the querystring, but something seems to be going wrong and it adds a querystring onto the forms action url.
I'd probably look at adding it to the issue log on codeplex. As I say, I've not yet worked out why it's doing it, but if you want to get rid of it now, you might be best extending the UrlRewritterFormWritter and implementing some custom logic, and changing the Form.Browser file to point to your class instead.
Matt: Thanks for your thourough reply - really interesting information you've come up with. Please let us know if you look more into this case (e.g. posts it on Codeplex). I really want to get this problem solved.
Gianluca: Sounds like a good idea - please post your solution if you get it working. This might be the solution for me as well - I don't think our client has time to wait for a possible bugfix.
I've managed to look into it a little further, and the problem seems to be with current.Items["VirtualUrl"]. I'm not sure how this gets set, but it seems to have a ? on the end.
Now you can fix this as follows. Create a new form adapter class like so:
public class FormRewriterControlAdapter : ControlAdapter { // Methods protected override void Render(HtmlTextWriter writer) { base.Render(new UrlRewriterFormWriter(writer)); } }
Then create a new UrlRewritterFormWritter like so
public class UrlRewriterFormWriter : HtmlTextWriter { // Methods public UrlRewriterFormWriter(TextWriter writer) : base(writer) { base.InnerWriter = writer; }
public UrlRewriterFormWriter(HtmlTextWriter writer) : base(writer) { base.InnerWriter = writer.InnerWriter; }
public override void WriteAttribute(string name, string value, bool fEncode) { if (name == "action") { HttpContext current = HttpContext.Current; if (current.Items["ActionAlreadyWritten"] == null) { string str = ""; if (!((current.Items["VirtualUrl"] == null) || string.IsNullOrEmpty(current.Items["VirtualUrl"].ToString()))) { str = current.Items["VirtualUrl"].ToString(); } else { str = current.Items["umbOriginalUrl"].ToString(); if (!string.IsNullOrEmpty(current.Request.Url.Query)) { str = str + current.Request.Url.Query;
Basically, this is exactly the same as the Umbraco UrlRewritterFormWritter , except I've added a TrimEnd('?') call to make it doesn't return a url with just a ? on the end.
Once youve got this, update App_Browser/Forms.browser as follows:
It kind of depends how you are working with Umbraco, but the simplest method would be to create the 2 classes and drop them into the App_Code folder, then just update the App_Browser/Forms.browser file to point to your new class.
Thanks for your prompt reply. I managed to figure it out with your directions. For anyone else who will try the solution, you will need these references in your classes: using System; using System.IO; using System.Web; using System.Web.UI; using System.Web.UI.Adapters;
Question mark added on submit
Hello everybody,
Not sure this is the right place to ask this, but there is not a forum section that is dedicated to custom and user controls.
Anyway, my question is quite straight forward: I have an ASP button in my user control. When I click it, the page gets reloaded and a question mark ('?') is added to the URL.
How can I avoid this? I am not using querystring...
Cheers,
Gianluca.
If you have a ? in the url it seems that your form will be submitted as HTTP GET. So if you want to use PostBacks you have to add the attribute runat="server" to your form. If you are using http form submittion you can set the attribute method="POST" which will submit the form as HTTP POST
hth, Thomas
Hi Thomas,
Thanks for your quick reply. However I don't think this is the case.
This is a bit of my Master.master page, which is the master page of all my website pages:
<body>
<form id="Form1" runat="server" method="post">
<div id="container">
As you can see there is runat="server" and also the method is explicitly set to "post".
No other masterpage defines a form... so I don't see why it should "GET" instead of "POSTing" data.
Am I wrong? Is the form definition correct?
Thanks,
Gianluca.
can you post the complete html of the form?
here you go: (just the important bit)
I have just checked again and there is no other "<form>" tag in this page.. just the one you see at the top of the code I've pasted.
Note that the form action is generated by umbraco/.net already with the "?" at the end. And I don't know why.
This is the Master.master code that outputs that bit:
I have also tried, but without success:
Thanks in advance,
Cheers,
Gianluca.
I was more interested in the button
Oh, ok! Sorry about that.
Here you go:
and in the Codebehind (btnSend_Click) there is (short-version):
Is this ok?
Cheers,
Gianluca.
Uhh, seems everything ok, cannot see where the problem is. Sorry
Hello Gianluca
Did you find a solution for your question mark problem?
I have the same problem on a site i'm working on right now and I have no idea what to do about it.
/Rune
I can replicate the issue, and looking into it I think it might be a bug.
It comes down to the UrlRewritterFormWritter which is registerd in App_Browser/Form.Browser. It does look to do a check for the querystring, but something seems to be going wrong and it adds a querystring onto the forms action url.
I'd probably look at adding it to the issue log on codeplex. As I say, I've not yet worked out why it's doing it, but if you want to get rid of it now, you might be best extending the UrlRewritterFormWritter and implementing some custom logic, and changing the Form.Browser file to point to your class instead.
Matt
@Rune: No, I still don't have a solution for this, though Matt gave us quite few information.
I'll try to follow Matt's advice and extend the UrlRewritterFormWritter. I'll let you know how I get along with that.
Cheers,
Gianluca.
Matt: Thanks for your thourough reply - really interesting information you've come up with. Please let us know if you look more into this case (e.g. posts it on Codeplex). I really want to get this problem solved.
Gianluca: Sounds like a good idea - please post your solution if you get it working. This might be the solution for me as well - I don't think our client has time to wait for a possible bugfix.
/Rune
I've managed to look into it a little further, and the problem seems to be with current.Items["VirtualUrl"]. I'm not sure how this gets set, but it seems to have a ? on the end.
Now you can fix this as follows. Create a new form adapter class like so:
Then create a new UrlRewritterFormWritter like so
Basically, this is exactly the same as the Umbraco UrlRewritterFormWritter , except I've added a TrimEnd('?') call to make it doesn't return a url with just a ? on the end.
Once youve got this, update App_Browser/Forms.browser as follows:
(Don't forget to update YourNamespace with whatever your namespace is)
I guess the real fix should be to work out why the ? is on the end of VirtualUrl, but this is a good enough fix that you can do yourself.
Matt
I've added an issue to codeplex if you want to vote it up
http://umbraco.codeplex.com/workitem/28395
Matt
Hi Matt,
Could you point out where / how to create this fix ? (which file for example / new ?)
Thnx
Raymond
Hi Raymond,
It kind of depends how you are working with Umbraco, but the simplest method would be to create the 2 classes and drop them into the App_Code folder, then just update the App_Browser/Forms.browser file to point to your new class.
Matt
Hi Matt,
Thanks for your prompt reply. I managed to figure it out with your directions.
For anyone else who will try the solution, you will need these references in your classes:
using System;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.Adapters;
Thanks again Matt !
Grtz
Raymond
No problem,
I must be too used to Reflector suggeting the Using statements for me, so I didn't put them in =)
Glad you got it working though.
Matt
Hi Matt and everybody else
I finally got the time to look into Matts solution - and it works like a charm.
I've also noticed that Niels Hartvig has fixed and closed the case on Codeplex. The permanent solution will be available in v4.5.2.
But for now I'll go with Matts solution. Thanks for your help :-)
/Rune
is working on a reply...