submit form and redirection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alexjimenez
    New Member
    • Dec 2008
    • 6

    submit form and redirection

    Hi, i am newbie in ASP

    I try to redirect this form after submit to another page....what should i do?

    Strings of form :

    Code:
    <%@ Page Language="C#" Debug="False" %>
    <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %>
    <%@ import Namespace="System.Web.Mail" %>
    <script runat="server">
    
        public void Page_Load() {
          if (!IsPostBack)
                content_form.Visible = true ;
          else  {
                content_result.Visible = true ;
                content_form.Visible = false ;
               }
    
        }
    
        void submit_click(object sender, ImageClickEventArgs e)
              {
                content_form.Visible = false ;
                MailMessage msg = new MailMessage();
                string recipient = "ajimenez@yahoo.com" ;
    
                          
    
                msg.To = recipient ;
                msg.Subject = "Kaba Web Site E-Plex Software reg (Access Control)" ;
                msg.BodyFormat = MailFormat.Html ;
    
    
                string message = "Please process as required. Thank You. <br>"  ;
                message += "----------------------------------------------------------- <br><br>";
               // message += "Reason you are contacting us?" + type_of_info.SelectedValue +" <br><br>" ;
                message += "Name: " + firstname.Text +  " <br><br><br>" ;
                message += "Company: "  + companyname.Text + " <br>" ;
                if( title.SelectedItem.Value != "" )
                    message += "Title : " + title.SelectedItem.Value.ToString() + " <br><br><br><br>";
                    
                message += "Email : " + email.Text + " <br>" ;
                
                message += "City : " + city.Text + " <br>" ;
                message += "State/Province : " + state_province.SelectedItem.Value + " <br> ";
                if ( zip.Text != "" )
                    message += "Zip/Postal Code: " + zip.Text + " <br> ";
                if( phone.Text != "" )
                    message += "Phone : " + phone.Text + " <br>";
                if( fax.Text != "" )
                    message += "Fax : " + fax.Text + " <br>";
                    
                
    
    
    
    
        
    			String yes_wants_more_information_on_kaa = Request.Form["yes_wants_more_information_on_kaa"];
    			String yes_mailinglist = Request.Form["yes_mailinglist"];
    
    			message += "<b>Wants this (if listed): </b><br>";
     			
     			if (yes_wants_more_information_on_kaa != "")
     			message += yes_wants_more_information_on_kaa + "<br>";
     			
    			if (yes_mailinglist != "")
     			message += yes_mailinglist + "<br>";
     			
    
               
                if( comments.Text != "" )
                    message += "Additional details/comments: <br>" ;
                    message += "<p class=\"content_site\" >" +  comments.Text + " </p><br>" ;
    
    
                msg.From = email.Text;
                msg.Body = message ;
                SmtpMail.SmtpServer="10.254.250.48" ;
                SmtpMail.Send(msg) ;
    
    
    // *** NEED TO REDIRECT WITH SPECIAL CODE?
    // Response.redirect "http://www.yahoo.com"
                content_result.Text = "";
                
    
                content_result.Visible = true ;
              }
    
    </script>


    Code to submit :

    Code:
    <asp:ImageButton id="submit" onclick="submit_click" runat="server" AlternateText="SUBMIT" ImageAlign="left" ImageUrl="/common/submit.gif"></asp:ImageButton>
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    In the code that you've posted, you're sending an email once you've clicked a link button on your page...and then you want to redirect the user to another page.

    What is the problem with using Response.Redire ct()?
    What do you mean by: "I want to redirect with special code"?
    What is this "special code" supposed to do?

    -Frinny

    Comment

    • alexjimenez
      New Member
      • Dec 2008
      • 6

      #3
      I put ResponseRedirec t as in :


      # content_result. Text = "";
      #
      #
      # content_result. Visible = true ;
      # Response.redire ct "http://www.yahoo.com"
      And this does not work, it wont redirect :( i dont know how to do a redirection after Submit.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        I really don't know why this would be working for you?
        Where are you redirected to?

        I have tested your code (minus the email sending part) and it works fine:

        I added a link button to the page:
        [code=asp]
        <asp:LinkButt on ID="doRedirect " runat="server" Text="Redirect To Yahoo"></asp:LinkButton>
        [/code]

        I redirect the user to Yahoo.com when the button is clicked:
        [code=vbnet]
        Private Sub doRedirect_Clic k(ByVal sender As Object, ByVal e As System.EventArg s) Handles doRedirect.Clic k
        Response.Redire ct("http://yahoo.com", True)
        End Sub
        [/code]

        Note that I'm supplying a "True" parameter to the Response.Redire ct() method. This indicates that the page should no longer be processed after the user has been redirected...th is avoids any Tread.Abortion exceptions.

        Maybe if you uncomment the code responsible for redirecting the user.....it might work?

        -Frinny

        Comment

        • alexjimenez
          New Member
          • Dec 2008
          • 6

          #5
          Not working :( ... i really dont understand

          Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

          Compiler Error Message: CS1002: ; expected

          Source Error:

          Line 82: content_result. Visible = true ;
          Line 83:
          Line 84: Private Sub doRedirect_Clic k(ByVal sender As Object, ByVal e As System.EventArg s) Handles doRedirect.Clic k
          Line 85: Response.Redire ct("http://yahoo.com", True)
          Line 86: End Sub

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #6
            OK, Frinny was just giving you an example of using Response.Redire ct....and in her example she is using VB.NET, not C# like you are.

            In the code you provided you are using it incorrectly.
            Originally posted by Line 79 of your code example
            Response.redire ct "http://www.yahoo.com"
            this is incorrect. In C# you have to use parenthesis around method parameters, and end every statement with a semicolon (;). Also, C# is case-sensitive: Response.Redire ct is different than Response.redire ct.

            Put this code in at the point you want to redirect:
            Code:
            [noparse]Response.Redirect("http://www.bytes.com");[/noparse]
            And change the bytes URL to wherever you need it to be.

            Also note that the code after you redirect is pointless, since you will be taken to another page. You don't need to change anything on the page once you leave.

            Comment

            • alexjimenez
              New Member
              • Dec 2008
              • 6

              #7
              Thank you all!

              THANK YOU ALL *IT WORKS WITH Code provided by insertAlias Moderator, i wasnt sure it was c# and i dont know nothing about ASP or .Net or C# ...this was super confusing for me


              Thanks alot ! to all of you

              BYTES.COM Rocks ! this is Great ! wow you programmers rocks! i wish i had your brain transplanted into mine with all your syntax knowledge ;)
              Last edited by alexjimenez; Dec 23 '08, 09:36 PM. Reason: for better understanding of message

              Comment

              • Curtis Rutland
                Recognized Expert Specialist
                • Apr 2008
                • 3264

                #8
                Glad to help, and always happy to get the feedback. Feel free to come back any time =D

                Comment

                Working...