My ASP.Net Page doesn't post form data to another second page

René 21 Reputation points
2022-07-08T12:49:04.577+00:00
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Registration.aspx.vb" Inherits="Test.Registration" %>  
  
<!DOCTYPE html>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  
    <title></title>  
  
  <!-- Google Fonts -->  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Roboto:300,300i,400,400i,500,500i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">  
  
  <!-- Vendor CSS Files -->  
  <link href="assets/vendor/aos/aos.css" rel="stylesheet" />  
  <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" />  
  <link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet" />  
  <link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet" />  
  <link href="assets/vendor/glightbox/css/glightbox.min.css" rel="stylesheet" />  
  <link href="assets/vendor/swiper/swiper-bundle.min.css" rel="stylesheet" />  
  
  <!-- Template Main CSS File -->  
  <link href="assets/css/style.css" rel="stylesheet" />  
                            <script>  
                                function check() {  
                                    //For dem Absenden des Formulars sollen einige Variablen  
                                    //überprüft werden.  
                                    //Zuerst herausfinden, ob ein Textfeld leer ist.  
                                    var x;  
                                    x = 0;  
                                    var f = document.getElementById("frmRegistration")  
                                    for (x; x < f.length; x++) {  
                                        if (f[x].name == 'txtAnzahlLizenzen') {  
                                            if (f[x].value == '') {  
                                                alert('Bitte geben Sie die Anzahl Lizenzen an.');  
                                                return (false);  
                                            }  
                                        }  
  
                                        if (f[x].name == 'cmbEdition') {  
                                            if (f[x].value == '') {  
                                                alert('Bitte geben Sie die gewünschte Edition an.');  
                                                return (false);  
                                            }  
                                        }  
  
                                        if (f[x].name == 'txtAnzahlLizenzen') {  
                                            if (f[x].value == '') {  
                                                alert('Bitte geben Sie die gewünschte Anzahl Lizenzen an.');  
                                                return (false);  
                                            }  
                                        }  
  
                                        if (f[x].name == 'txtVorname') {  
                                            if (f[x].value == '') {  
                                                alert('Bitte geben Sie Ihren Vornamen ein.');  
                                                return (false);  
                                            }  
                                        }  
  
                                        if (f[x].name == 'txtNachname') {  
                                            if (f[x].value == '') {  
                                                alert('Bitte geben Sie Ihren Nachnamen ein.');  
                                                return (false);  
                                            }  
                                        }  
  
                                        if (f[x].name == 'txtStrasse') {  
                                            if (f[x].value == '') {  
                                                alert('Bitte geben Sie Ihre Strasse ein.');  
                                                return (false);  
                                            }  
                                        }  
  
                                        if (f[x].name == 'txtPLZ') {  
                                            if (f[x].value == '') {  
                                                alert('Bitte geben Sie die PLZ ein.');  
                                                return (false);  
                                            }  
                                        }  
  
                                        if (f[x].name == 'txtOrt') {  
                                            if (f[x].value == '') {  
                                                alert('Bitte geben Sie Ihren Ort ein.');  
                                                return (false);  
                                            }  
                                        }  
  
                                        if (f[x].name == 'txtMail') {  
                                            if (f[x].value == '') {  
                                                alert('Bitte geben Sie Ihre Mailaadresse ein.');  
                                                return (false);  
                                            }  
                                            //Jetzt wird die EMail-Adresse nach Leerzeichen durchsucht.  
                                            //-1 bedeutet, dass kein Leerzeichen gefunden wurde.  
                                            if (f[x].value.search(/ /) != '-1') {  
                                                alert('Die E-Mail Adresse darf keine Leerzeichen enthalten!');  
                                                return (false);  
                                            }  
                                            //Am Schluss soll noch einmal das Format ueberprüft werden.  
                                            s = f[x].value.split(/@/);  
                                            if ((s.length != 2) || s[0] == '' || s[1] == '') {  
                                                alert('E-Mail Adressen haben das Format "Benutzer@Domain",\n'  
                                                    + 'z.B.: "******@provider.ch"');  
                                                return (false);  
                                            }  
                                        }  
                                    }  
                                }  
                            </script>  
</head>  
<body>  
    <form id="frmRegistration" runat="server" method="post" enctype="multipart/form-data" onsubmit="return check();">  
        <main id="main">  
            <!-- ======= News Section ======= -->  
            <section id="programmdetails" class="news section-bg">   
              <div class="container" data-aos="fade-up">  
  
                    <div class="section-title">   
                        <h3>PW-Soft, die ultimative Fahrzeugverwaltung <br /><span>Registrierung- und Lizenzierung</span></h3>  
                        <p>   
                        Bitte tragen Sie Ihre Daten mindestens in den mit Sternchen markierten Pflichtfelder ein, damit wir Ihre Bestellung bearbeiten können.  
                        </p>  
                    </div>  
                    <div class="row" style="margin-bottom:20px;">  
                     <div class="col-lg-6 col-md-5">  
                                <asp:Label ID="lblKey" runat="server" Text="Registrations-Schlüssel"></asp:Label>  
                        </div>  
                        <div class="col-lg-5 col-md-5">  
                                <asp:TextBox ID="txtKey" Enabled="false" runat="server"></asp:TextBox>  
                        </div>  
                    </div>  
                    <div class="row" style="margin-bottom:20px;">  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblVersion" runat="server" Text="Version" style="margin-right:10px;"></asp:Label>  
                        </div>  
                        <div class="col-lg-2 col-md-2">  
                            <asp:TextBox ID="txtVersion" Enabled="true" runat="server" Width="100px"></asp:TextBox>  
                        </div>  
                        <div class="col-lg-2 col-md-2">  
                            <asp:Label ID="lblEdition" runat="server" Text="Edition" style="margin-right:10px;"></asp:Label>  
                            <asp:Label ID="lblRequired1" runat="server" Text="*" style="color:red;"></asp:Label>  
                        </div>  
                        <div class="col-lg-2 col-md-2">  
                            <asp:DropDownList ID="cmbEdition" runat="server">  
                                <asp:ListItem Selected="True"></asp:ListItem>  
                                <asp:ListItem Value="Standard"></asp:ListItem>  
                                <asp:ListItem Value="Professional"></asp:ListItem>  
                                <asp:ListItem Value="Enterprise"></asp:ListItem>  
                                <asp:ListItem Value="Full"></asp:ListItem>  
                            </asp:DropDownList>  
  
                        </div>  
                    </div>  
                    <div class="row" style="margin-bottom:20px;">  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblAnzLizenzen" runat="server" Text="Anzahl Lizenzen"></asp:Label>  
                            <asp:Label ID="lblRequired2" runat="server" Text="*" style="color:red;"></asp:Label>  
                        </div>  
                        <div class="col-lg-2 col-md-5">  
                            <asp:TextBox ID="txtAnzahlLizenzen" Enabled="true" runat="server" Width="50px"></asp:TextBox>  
                        </div>  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblUpgradeVon" runat="server" Text="Upgrade von" style="margin-right:10px;"></asp:Label>  
                        </div>  
                        <div class="col-lg-2 col-md-5">  
                            <asp:TextBox ID="txtUpgradeVon" Enabled="true" runat="server" Width="100px"></asp:TextBox>  
                        </div>  
                    </div>  
                    <div class="row">  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblGutscheincode" runat="server" Text="Gutscheincode" style="margin-right:10px;"></asp:Label>  
                        </div>  
                        <div class="col-lg-3 col-md-5">  
                            <asp:TextBox ID="txtGutscheincode" Enabled="true" runat="server" Width="150px"></asp:TextBox>  
                        </div>  
                    </div>  
              </div>  
            </section>               
              
            <!-- ======= News Section ======= -->  
            <section id="Userdaten" class="news section-bg">   
                <div class="container" data-aos="fade-up">  
                    <div class="row" style="margin-bottom:20px;">  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblFirma" runat="server" Text="Firma"></asp:Label>  
                        </div>  
                        <div class="col-lg-3 col-md-5">  
                            <asp:TextBox ID="txtFirma" Enabled="true" runat="server" Width="250px"></asp:TextBox>  
                        </div>  
                    </div>  
                    <div class="row" style="margin-bottom:20px;">  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblAnrede" runat="server" Text="Anrede"></asp:Label>  
                        </div>  
                        <div class="col-lg-3 col-md-5">  
                            <asp:DropDownList ID="cmbAnrede" runat="server">  
                                <asp:ListItem Selected="True"></asp:ListItem>  
                                <asp:ListItem Value="Herr"></asp:ListItem>  
                                <asp:ListItem Value="Frau"></asp:ListItem>  
                                <asp:ListItem Value="Firma"></asp:ListItem>  
                            </asp:DropDownList>  
                        </div>  
                    </div>  
                    <div class="row" style="margin-bottom:20px;">  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblVorname" runat="server" Text="Vorname"></asp:Label>  
                            <asp:Label ID="lblRequired3" runat="server" Text="*" style="color:red;"></asp:Label>  
                        </div>  
                        <div class="col-lg-3 col-md-5">  
                            <asp:TextBox ID="txtVorname" Enabled="true" runat="server" Width="150px"></asp:TextBox>  
                        </div>  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblNachname" runat="server" Text="Nachname"></asp:Label>  
                            <asp:Label ID="lblRequired4" runat="server" Text="*" style="color:red;"></asp:Label>  
                        </div>  
                        <div class="col-lg-2 col-md-5">  
                            <asp:TextBox ID="txtNachname" Enabled="true" runat="server" Width="150px"></asp:TextBox>  
                        </div>  
                    </div>  
                    <div class="row" style="margin-bottom:20px;">  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblStrasse" runat="server" Text="Strasse"></asp:Label>  
                            <asp:Label ID="lblRequired5" runat="server" Text="*" style="color:red;"></asp:Label>  
                        </div>  
                        <div class="col-lg-2 col-md-5">  
                            <asp:TextBox ID="txtStrasse" Enabled="true" runat="server" Width="350px"></asp:TextBox>  
                        </div>  
                    </div>  
                    <div class="row" style="margin-bottom:20px;">  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblPLZ" runat="server" Text="PLZ"></asp:Label>  
                            <asp:Label ID="lblRequired6" runat="server" Text="*" style="color:red;"></asp:Label>  
                        </div>  
                        <div class="col-lg-3 col-md-5">  
                            <asp:TextBox ID="txtPLZ" Enabled="true" runat="server" Width="70px"></asp:TextBox>  
                        </div>  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblOrt" runat="server" Text="Ort"></asp:Label>  
                             <asp:Label ID="lblRequired7" runat="server" Text="*" style="color:red;"></asp:Label>  
                        </div>  
                        <div class="col-lg-2 col-md-5">  
                            <asp:TextBox ID="txtOrt" Enabled="true" runat="server" Width="250px"></asp:TextBox>  
                        </div>  
                    </div>  
                    <div class="row" style="margin-bottom:20px;">  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblLand" runat="server" Text="Land"></asp:Label>  
                        </div>  
                        <div class="col-lg-3 col-md-5">  
                                <asp:DropDownList ID="cmbLand" runat="server">  
                                <asp:ListItem Selected="True"></asp:ListItem>  
                                <asp:ListItem Value="Schweiz"></asp:ListItem>  
                                <asp:ListItem Value="Deutschland"></asp:ListItem>  
                                <asp:ListItem Value="Österreich"></asp:ListItem>  
                                <asp:ListItem Value="Frankreich"></asp:ListItem>  
                                <asp:ListItem Value="Belgien"></asp:ListItem>  
                                <asp:ListItem Value="Niederlande"></asp:ListItem>  
                                <asp:ListItem Value="Dänemark"></asp:ListItem>  
                                <asp:ListItem Value="Schweden"></asp:ListItem>  
                                <asp:ListItem Value="Norwegen"></asp:ListItem>  
                            </asp:DropDownList>  
                        </div>  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblTelefon" runat="server" Text="Telefon"></asp:Label>  
                        </div>  
                        <div class="col-lg-3 col-md-5">  
                            <asp:TextBox ID="txtTelefon" Enabled="true" runat="server" Width="150px"></asp:TextBox>  
                        </div>  
                    </div>  
                    <div class="row" style="margin-bottom:20px;">  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblMail" runat="server" Text="E-Mail"></asp:Label>  
                            <asp:Label ID="lblRequired8" runat="server" Text="*" style="color:red;"></asp:Label>  
                        </div>  
                        <div class="col-lg-3 col-md-5">  
                            <asp:TextBox ID="txtMail" Enabled="true" runat="server" Width="350px"></asp:TextBox>  
                        </div>  
                    </div>  
                    <div class="row" style="margin-bottom:20px;">  
                        <div class="col-lg-2 col-md-5">  
                            <asp:Label ID="lblKommentar" runat="server" Text="Kommentar"></asp:Label>  
                        </div>  
  
                        <div class="col-lg-2 col-md-5">  
                            <asp:TextBox ID="txtKommentar" Enabled="true" runat="server" Width="350px" TextMode="MultiLine" Rows="10" style="min-height:100px;"></asp:TextBox>  
                        </div>  
                    </div>  
                    <div class="row" style="margin-bottom:20px;">  
                        <div class="col-lg-2 col-md-5">  
  
                            <asp:Button ID="cmdBestellen" runat="server" Text="Bestellung speichern" PostBackUrl="Zahlung.aspx" />  
  
                        </div>  
                    </div>  
                </div>  
            </section>  
        </main>  
    </form>  
      <!-- Vendor JS Files -->  
  <script src="assets/vendor/aos/aos.js"></script>  
  <script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>  
  <script src="assets/vendor/glightbox/js/glightbox.min.js"></script>  
  <script src="assets/vendor/isotope-layout/isotope.pkgd.min.js"></script>  
  <script src="assets/vendor/purecounter/purecounter.js"></script>  
  <script src="assets/vendor/swiper/swiper-bundle.min.js"></script>  
  <script src="assets/vendor/waypoints/noframework.waypoints.js"></script>  
  
  <!-- Template Main JS File -->  
  <script src="assets/js/main.js"></script>  
  <script src="assets/js/jquery.min.js"></script>  
</body>  
</html>  

The Page is under this URL avalaible
Registration.aspx

The CodeBehind Code from the second page fires, but have nothing in the Response.Form Object.

Public Class Zahlung
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
    Dim Key As String = Request.Form("txtKey")  
    Response.Write(Key)  
End Sub  

End Class

Whats the problem of postbackurl with some CSS Styesheets? In Zahlung.aspx there is nothing in the Request.Form.

Thanks a lot for your help or any suggestions

Greetings René

Developer technologies ASP.NET Other
{count} votes

Accepted answer
  1. Yijing Sun-MSFT 7,096 Reputation points
    2022-07-11T05:55:34.693+00:00

    Hi @René ,
    You find the actual path when you are using friendly url. So, I suggest you could use Server.Transfer. You could try to test use this demo.

    Page1,named Test2:

                <asp:Label ID="Label1" runat="server" Text="Company Name"></asp:Label>  
                <asp:TextBox ID="txtkey" runat="server"></asp:TextBox>  
                <asp:Button ID="cmdspichern" runat="server" Text="spichern" O nClick="cmdspichern_Click" />  
    

    Code-behind:

     Protected Sub cmdspichern_C lick(sender As Object, e As EventArgs)  
            S erver.Transfer("~/Test3.aspx")  
        End Sub  
    

    Page2,named Test3:

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
    

    Code-behind:

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
            If Not IsPostBack Then  
                Dim txtBoxtest As TextBox = CType(Page.PreviousPage.FindControl("txtKey"), TextBox)  
                TextBox1.Text = txtBoxtest.Text  
            End If  
        End Sub  
    

    You could check the microsoft article.

    Best regards,
    Yijing Sun


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

8 additional answers

Sort by: Most helpful
  1. René 21 Reputation points
    2022-07-09T17:36:17.027+00:00

    Dear Albert, thanks a lot for your time and support.

    I defined a testpage named test2.aspx as first page This is the code

    <!DOCTYPE html> <html> <head> <title>Customer Form</title> </head> <body> <form method="post" runat="server" > <fieldset> <legend>Add Customer</legend> <div> <label for="CompanyName">key:</label> <input type="text" name="txtkey" value="" /> </div> <div> <label>&nbsp;</label> <asp:Button ID="cmdSpeichern" runat="server" Text="Speichern" PostBackUrl="Test3.aspx" /> </div> </fieldset> </form> </body> </html>

    You can access the first page online on this url. http://www.centil-europe.ch/Registration/test2.aspx

    This is the code from the second page named test3.aspx <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Test3.aspx.vb" Inherits="Test.Test3" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="txtval" runat="server"></asp:TextBox> </div> </form> </body> </html>

    And this is the codebehind 219100-code-3.jpg

    No, the button in the first page has no code behind it. There is only the PostBackURL in the button html-code.

    Greetings René


  2. Albert Kallal 5,586 Reputation points
    2022-07-09T18:52:16.547+00:00

    A few things:

    First up, your sample page is 100% different, and does NOT EVEN use a standard control, and does not even have a "id" for the control we are trying to use?

    Also, WHY are you messing around with the default and basic template that is created by default? (that explains MUCH of your issues and problem here).

    So, lets create a new page Test2.aspx.

    Let the designer create that default markup for you (don't mess around with that!!!!). And why are you messing around with the default form div created for you? (again, no need to mess with that)

    Worse yet? In your original markup, you using a standard asp.net text box, NOW FOR SOME AMAZING reason, you are dropping in a html "input" control, and EVEN WORSE yet, you are NOT even giving that control a "id", but out of the blue all of a sudden using name? (why are you doing this?????).

    So, lets try this again:

    So, we create that new page, leave the default markup alone - use that default markup.

    So, we now have this in Test2

    219185-image.png

    so, really, the ONLY part you mess with is the new markup we placed inside of the default "div", as per above. As noted, use the standard asp.net controls, make sure they have a "id". In fact, just use drag + drop from the tool box - that way you have a hard time to mess this up.

    So, we have above.

    Now, for 2nd page? Lets just drag from toolbox in a text box. We have this:

    219068-image.png

    Again, no need to mess with the "form" and the automatic default layout - just use that.

    Now, our code behind, can be this:

    Public Class Test3  
        Inherits System.Web.UI.Page  
      
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
      
            If Not IsPostBack Then  
      
                Dim txtBoxtest As TextBox = Page.PreviousPage.FindControl("txtKey")  
                TextBox1.Text = txtBoxtest.Text  
      
            End If  
        End Sub  
      
    

    So, now lets try this:

    219186-image.png

    We click button, 2nd page loads, and we see/have this:

    219212-image.png

    As noted, for this simple test, I don't out of the blue would suggest you test using a html "input" control, and in fact your original markup used a standard plane jane asp.net text box (it should work).

    So, get this sample working. Then we can re-visit your original posted markup. but, looking at your first sample page, it should work. but, get the sample working.

    Then perhaps create a new test page - put in your markup by bits and parts (don't mess with the form "id" - no need to. So, just paste inside of the default "form" tag that the designer creates for you by default.

    0 comments No comments

  3. René 21 Reputation points
    2022-07-09T21:33:19.2+00:00

    Dear Albert

    Yes that's right, I had tried different things.
    Now I have deleted the Test2.aspx page and created it again. Added label, text field and button.

    However, PreviousPage is always nothing.in page test3.aspx

    Here is the new code of Test2.aspx

    <%@ Page Language="vb" AutoEventWireup="true" CodeBehind="Test2.aspx.vb" Inherits="Test.Test2" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    </head>
    <body>
    <form id="frmmain" method="post" runat="server">
    <div>
    <asp:Label ID="lbl1" runat="server" Text="key"></asp:Label>
    <asp:TextBox ID="txtkey" runat="server"></asp:TextBox>
    <asp:Button ID="cmd1" runat="server" Text="send" PostBackUrl="Test3.aspx" />
    </div>
    </form>
    </body>
    </html>

    Basically, it does not matter which parameters are used, the error is always that PreviusPage is nothing.

    Not even in the own page Test2 it is possible to read and save the posted values. Not even with standard page and controls.

    It seems like there is basically something missing in the development environment that would also need to be published for this to work properly on the web server. On the code side, I have tried everything imaginable.

    Greetings René

    0 comments No comments

  4. René 21 Reputation points
    2022-07-10T09:40:10.687+00:00

    Dear Albert

    I updated Visual Studio 2019 with the latest version last night. The test pages are now working on the web server. In the LocalHost still comes the same error. This is not so tragic, I can test on the web server too, but is not so comfortable.
    Thanks for the help. And sorry for posting the wrong HTML code. As for the LocalHost, that could be an OS issue, which is still Windows 7 Professional. However, Visual Studio had no problem during the installation and yes installs the LocalHost during the installation process as well. Difficult to estimate what is the problem in the localhost. Do you possibly or any of the readers have an idea?

    Thanks for the inputs and examples.
    Greetings, René


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.