Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gianluca 56 posts 79 karma points
    Jul 15, 2010 @ 12:26
    Gianluca
    0

    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.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 15, 2010 @ 12:37
    Thomas Höhler
    0

    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

  • Gianluca 56 posts 79 karma points
    Jul 15, 2010 @ 12:42
    Gianluca
    0

    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.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 15, 2010 @ 13:06
    Thomas Höhler
    0

    can you post the complete html of the form?

  • Gianluca 56 posts 79 karma points
    Jul 15, 2010 @ 13:36
    Gianluca
    0

    here you go: (just the important bit)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
      <head> 
    
        <!-- Page Title --> 
        <title>Company</title> 
    
        <!-- CSS --> 
        <link rel="stylesheet" type="text/css" href="/css/Company.css" /> 
        <link rel="stylesheet" type="text/css" href="/css/Company-menu.css" /> 
        <link rel="stylesheet" type="text/css" href="/css/Company-homepage.css" /> 
        <link rel="stylesheet" type="text/css" href="/css/Company-main-sections.css" /> 
    
        <script type="text/javascript" src="/scripts/JQuery.js"></script> 
        <script type="text/javascript" src="/scripts/Menu.js"></script> 
    
        <!-- Meta Data --> 
        <meta name="description" content="" /> 
        <meta name="keywords" content="" /> 
      </head> 
    
      <body> 
        <form method="post" action="/it/homepage/family/product-5.aspx?" onsubmit="javascript:return WebForm_OnSubmit();" id="Form1"> 
    <div class="aspNetHidden"> 
    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> 
    <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /> 
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUENTM4MWQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFZ2N0bDAwJGN0bDAwJGN0bDAwJGN0bDAwJENvbnRlbnRQbGFjZUhvbGRlckRlZmF1bHQkQ2hpbGRDb250ZW50JFBhZ2VDb250ZW50JFByb2R1Y3RDb250YWN0Rm9ybV81JGJ0blNlbmT2P+O8wGlr25CxTmK5OFfbecApNAmAeDSlnA/59iHjvA==" /> 
    </div> 
    
    <script type="text/javascript"> 
    //<![CDATA[
    var theForm = document.forms['Form1'];
    if (!theForm) {
        theForm = document.Form1;
    }
    function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }
    //]]>
    </script> 
    
    
    <script src="/WebResource.axd?d=_XSQWPNQ26AdmubU4kY94g2&amp;t=634080733653201636" type="text/javascript"></script> 
    
    
    <script src="/WebResource.axd?d=8crn5yzpkvGdaC7cDK5LWezhCRdwjzX5_tDmLoPJPxI1&amp;t=634080733653201636" type="text/javascript"></script> 
    <script type="text/javascript"> 
    //<![CDATA[
    function WebForm_OnSubmit() {
    if (typeof(ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) return false;
    return true;
    }
    //]]>
    </script> 
    
        <div id="container"> 

     

    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:

    <body> 
        <form id="Form1" runat="server">
        <div id="container"> 

    I have also tried, but without success:

    <body> 
        <form id="Form1" runat="server" method="post">
        <div id="container"> 

    Thanks in advance,

    Cheers,

    Gianluca.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 15, 2010 @ 14:39
    Thomas Höhler
    0

    I was more interested in the button

  • Gianluca 56 posts 79 karma points
    Jul 15, 2010 @ 14:51
    Gianluca
    0

    Oh, ok! Sorry about that.

     

    Here you go:

    <asp:ImageButton
                runat="server" ID="btnSend" src="/media/assets/invia2.gif" Style="width: auto;
                height: auto; margin-left: 208px" OnClick="btnSend_Click"></asp:ImageButton>

    and in the Codebehind (btnSend_Click) there is (short-version): 

     if (!Page.IsValid)
                return;
    
            SmtpClient mySMTPClient = new SmtpClient();
    ...
    return;

    Is this ok?

    Cheers,

    Gianluca.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 15, 2010 @ 15:07
    Thomas Höhler
    0

    Uhh, seems everything ok, cannot see where the problem is. Sorry

  • RuneO 36 posts 116 karma points
    Aug 03, 2010 @ 13:05
    RuneO
    0

    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

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 03, 2010 @ 13:29
    Matt Brailsford
    0

    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

  • Gianluca 56 posts 79 karma points
    Aug 03, 2010 @ 16:03
    Gianluca
    0

    @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.

  • RuneO 36 posts 116 karma points
    Aug 03, 2010 @ 16:13
    RuneO
    0

    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

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 03, 2010 @ 16:33
    Matt Brailsford
    0

    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;
                               
                        }
                    }
                    value = str.TrimEnd('?');
                    current.Items["ActionAlreadyWritten"] = true;
                }
            }
            base.WriteAttribute(name, value, fEncode);
        }
    }

    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:

    <browsers>
      <browser refID="Default">
        <controlAdapters>
          <adapter controlType="System.Web.UI.HtmlControls.HtmlForm"
                   adapterType="YourNamespace.FormRewriterControlAdapter" />
        </controlAdapters>
      </browser>
    </browsers>

    (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

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 03, 2010 @ 16:39
    Matt Brailsford
    0

    I've added an issue to codeplex if you want to vote it up

    http://umbraco.codeplex.com/workitem/28395

    Matt

  • Raymond Fraikin 2 posts 22 karma points
    Aug 10, 2010 @ 00:26
    Raymond Fraikin
    0

    Hi Matt,

    Could you point out where / how to create this fix ? (which file for example / new ?)

    Thnx
    Raymond

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 10, 2010 @ 09:29
    Matt Brailsford
    0

    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

  • Raymond Fraikin 2 posts 22 karma points
    Aug 10, 2010 @ 14:36
    Raymond Fraikin
    0

    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

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 10, 2010 @ 14:41
    Matt Brailsford
    0

    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

  • RuneO 36 posts 116 karma points
    Aug 19, 2010 @ 10:40
    RuneO
    0

    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

     

Please Sign in or register to post replies

Write your reply to:

Draft