everytime click submit button need to refresh page in order to do next submit

Last post 05-14-2008 5:51 PM by dongzhe53. 12 replies.

Sort Posts:

  • everytime click submit button need to refresh page in order to do next submit

    05-14-2008, 12:44 PM
    • Loading...
    • dongzhe53
    • Joined on 05-14-2008, 12:38 PM
    • Posts 10

    I got a question. when I was creating a web form, I have a submit button, once button clicked, some info in textbox will insert to database. All these insert work, but after I did first submit and trying to type new info to do submit will not work. I need to refresh page first before I do second submit. Is anybody here can give me some suggestion?

     

  • Re: everytime click submit button need to refresh page in order to do next submit

    05-14-2008, 1:41 PM
    • Loading...
    • vinz
    • Joined on 10-05-2007, 11:47 AM
    • Cebu Philippines
    • Posts 8,379

    Can we see the codes for submit? 


    Regards,
    Vincent Maverick Durano

    Please post questions to the forums, where others may benefit.I do not offer free assistance by e-mail. Thank you!



  • Re: everytime click submit button need to refresh page in order to do next submit

    05-14-2008, 1:47 PM
    • Loading...
    • dongzhe53
    • Joined on 05-14-2008, 12:38 PM
    • Posts 10

             protected void Submit_Click(object sender, EventArgs e)
            {
              
                    // create a new SqlConnection object with the appropriate connection string

                    SqlConnection sqlConn = new SqlConnection();
                    sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;

                    SqlConnection updatesql = new SqlConnection();
                    updatesql.ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;

                    SqlConnection selectsql = new SqlConnection();
                    selectsql.ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;

                    SqlConnection insertsql = new SqlConnection();
                    insertsql.ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;

                    SqlConnection connection = new SqlConnection();
                    connection.ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;
                    SqlCommand MyCommand;
                      SqlCommand insertCommand;
                      SqlCommand updateCommand;


                      selectsql.Open();
             
                      // do some operations ...
                      string cmdStr = "SELECT * FROM BusinessName WHERE MerchantEmail='" + MerchantEmailTextBox.Text + "'";
                      SqlDataAdapter dataAdapter = new SqlDataAdapter(cmdStr, selectsql);
                      DataSet ds = new DataSet();
                      dataAdapter.Fill(ds, "MyDataSet");
                      selectsql.Close();
                      // just count the no of rows
                      int RowCount = ds.Tables[0].Rows.Count;
                      Label2.Text = "" + RowCount;
                      // if zero rows returned than no such user exists
                      if (RowCount == 0)
                      {

                              //nothing match in our business database
                              Label1.Text = "Nothing Match ";
                              insertsql.Open();
                              //we need to insert this new merchant and send email to it.
                              string cmd1 = "INSERT INTO BusinessName(MerchantEmail, EmailSent, Unsubscribe, EmailRequest) VALUES('" + MerchantEmailTextBox.Text + "','1','1','1')";
                              insertCommand = new SqlCommand(cmd1, insertsql);
                              insertCommand.ExecuteNonQuery();
                              insertsql.Close();
                              sendEmail();

                              //End of inserting and email sending



                      }

                      else if (RowCount == 1)
                      {
         
                              // also save other information if required

                              int emailsent = (int)(ds.Tables[0].Rows[0][1]);
                              int emailrequest = (int)(ds.Tables[0].Rows[0][3]);

                              //matched something in the business database
                              Label1.Text = "Something matched " + emailsent + " " + emailrequest;
                              if (emailsent == 0)//we can send email to merchant
                              {
                                  //send email
                                  sendEmail();
                                  emailsent = 1;
                                  string cmd3 = "UPDATE BusinessName SET EmailSent = '" + emailsent + "' WHERE MerchantEmail='" + MerchantEmailTextBox.Text + "'";

                                  connection.Open();
                                  SqlCommand updateconncommand = new SqlCommand(cmd3, connection);
                                  updateconncommand.ExecuteNonQuery();
                                  connection.Close();
                              }
                              else//emailsent is 1, we can not send email
                              {
                                  //Start of updating
                                  //email-request's value need to be increased at here

                                  emailrequest++;

                                  //   Label1.Text = "Email Sent: "+emailsent +" and Email Request: "+emailrequest;

                                  string cmd2 = "UPDATE BusinessName SET EmailRequest = '" + emailrequest + "' WHERE MerchantEmail='" + MerchantEmailTextBox.Text + "'";
                                  updatesql.Open();
                                  updateCommand = new SqlCommand(cmd2, updatesql);
                                  updateCommand.ExecuteNonQuery();
                                  updatesql.Close();

                                  //end of updating
                              }
          



                      }

                             

                    DateTime date = DateTime.Now;
                    sqlConn.Open();
                    string cmd = "INSERT INTO Nomination (NominationDate, CoName, CoPhone, CoEmail, CoContact, CoProvince, CoCountry, MFirstName, MLastName, MEmail, MDistIDNum, MDomain) VALUES ('" + date + "','" + MerchantTextBox.Text + "','" + MerchantPhoneTextBox.Text + "','" + MerchantEmailTextBox.Text + "','" + MerchantContactNameTextBox.Text + "','" + MerchantProvinceTextBox.Text + "','" + MerchantCountryTextBox.Text + "','" + MemFirstNameTextBox.Text + "','" + MemLastNameTextBox.Text + "','" + MemEmailTextBox.Text + "','" + RepNumTextBox.Text + "','" + RepWebTextBox.Text + "')";
                    MyCommand = new SqlCommand(cmd, sqlConn);
                    MyCommand.ExecuteNonQuery();

                    Label3.Text = "Inserting..........";

                    sqlConn.Close();

            
            }

     

     

    Here is my code. I don't know where are wrong. Thanks to give some suggestion. 

  • Re: everytime click submit button need to refresh page in order to do next submit

    05-14-2008, 1:54 PM
    • Loading...
    • vinz
    • Joined on 10-05-2007, 11:47 AM
    • Cebu Philippines
    • Posts 8,379

    Have you try debugging your codes by setting a break point on the Submit_Click event to see if it hits in that event the second time? If not then debug it so that you can figure out of what is happening there... 


    Regards,
    Vincent Maverick Durano

    Please post questions to the forums, where others may benefit.I do not offer free assistance by e-mail. Thank you!



  • Re: everytime click submit button need to refresh page in order to do next submit

    05-14-2008, 2:12 PM
    • Loading...
    • mp_lights
    • Joined on 07-05-2005, 8:43 AM
    • United States
    • Posts 34

    Did you clear all the fields before clicking the submit for the second time? From your code i see that your are checking for the values if they are same or not from the ones existing in the database.

    Thanks,

    Mathew 

     

  • Re: everytime click submit button need to refresh page in order to do next submit

    05-14-2008, 2:40 PM
    • Loading...
    • dongzhe53
    • Joined on 05-14-2008, 12:38 PM
    • Posts 10

     I tried to  clear info in textbox .but not work.  and Yes, I am checking for the values if they are same  or not from the ones existing in the database and then do further action...

     I still can not solve this problem...
     

  • Re: everytime click submit button need to refresh page in order to do next submit

    05-14-2008, 2:41 PM
    • Loading...
    • dongzhe53
    • Joined on 05-14-2008, 12:38 PM
    • Posts 10

    I had set break point on the submit_click event, and at the second time, it's not hit the event.... 

  • Re: everytime click submit button need to refresh page in order to do next submit

    05-14-2008, 3:27 PM
    • Loading...
    • dongzhe53
    • Joined on 05-14-2008, 12:38 PM
    • Posts 10

     I also put break point at Page_Load(....

    I found second time when I click submit button, even Page_Load is not going to be hit.

    Any suggestions? Thanks. 

  • Re: everytime click submit button need to refresh page in order to do next submit

    05-14-2008, 3:59 PM
    • Loading...
    • vinz
    • Joined on 10-05-2007, 11:47 AM
    • Cebu Philippines
    • Posts 8,379

    dongzhe53 :

    I had set break point on the submit_click event, and at the second time, it's not hit the event....

    Thats weird.. Can you post your aspx codes here too? 


    Regards,
    Vincent Maverick Durano

    Please post questions to the forums, where others may benefit.I do not offer free assistance by e-mail. Thank you!



  • Re: everytime click submit button need to refresh page in order to do next submit

    05-14-2008, 4:17 PM
    • Loading...
    • dongzhe53
    • Joined on 05-14-2008, 12:38 PM
    • Posts 10

     <table style="width: 500px; height: 439px">
        <tr>
            <td colspan="2"><b>Nominated Merchant</b></td>
            <td></td>
        </tr>
        <tr>
            <td><asp:Label runat="server" ID="Merchant">Merchant Name:</asp:Label></td>
            <td style="width: 187px"><asp:TextBox runat="server" ID="MerchantTextBox"></asp:TextBox></td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="MerchantTextBox"
                    CssClass="ValidationMessage" ErrorMessage="Merchant Name is required">*</asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td><asp:Label runat="server" ID="MerchantPhone">Merchant Ph No.:</asp:Label></td>
            <td style="width: 187px"><asp:TextBox runat="server" ID="MerchantPhoneTextBox"></asp:TextBox></td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="MerchantPhoneTextBox"
                    CssClass="ValidationMessage" ErrorMessage="Merchant Phone Number is required">*</asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="MerchantPhoneTextBox"
                    CssClass="ValidationMessage" ErrorMessage="Please enter Merchant's Phone Number correctly"
                    ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}">*</asp:RegularExpressionValidator><span
                        style="color: #ff0066">(xxx)xxx-xxxx
                or
                        <br />
                        &nbsp; &nbsp; &nbsp; xxx-xxx-xxxx</span></td>
        </tr>
        <tr>
            <td><asp:Label runat="server" ID="MerchantContactName">Merchant Contact Name:</asp:Label></td>
            <td style="width: 187px"><asp:TextBox runat="server" ID="MerchantContactNameTextBox"></asp:TextBox></td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="MerchantContactNameTextBox"
                    ErrorMessage="Merchant Contact Name is required">*</asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td><asp:Label runat="server" ID="MerchantEmail">Merchant Email:</asp:Label></td>
            <td style="width: 187px"><asp:TextBox runat="server" ID="MerchantEmailTextBox"></asp:TextBox></td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="MerchantEmailTextBox"
                    CssClass="ValidationMessage" ErrorMessage="Merchant Email is required">*</asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="MerchantEmailTextBox"
                    ErrorMessage="Please enter your e-mail correctly" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
                <span style="color: #ff0066">xxx@xxx.com</span></td>
        </tr>
        <tr>
            <td><asp:label runat="server" ID="MerchantProvince">Merchant State/Province</asp:label></td>
            <td style="width: 187px"><asp:TextBox runat="server" ID="MerchantProvinceTextBox"></asp:TextBox></td>
            <td></td>
        </tr>
        <tr>
            <td>
                <asp:Label runat="server" ID="MerchantCountry">Merchant Country</asp:Label>
            </td>
            <td style="width: 187px"><asp:TextBox runat="server" ID="MerchantCountryTextBox"></asp:TextBox></td>
            <td></td>
        </tr>
        
        <tr>
        <td colspan="2"><b>Nominating Member</b></td>
        </tr>
        <tr>
            <td><asp:Label runat="server" ID="MemFirstName">Member First Name:</asp:Label></td>
            <td style="width: 187px"><asp:TextBox runat="server" ID="MemFirstNameTextBox"></asp:TextBox></td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="MemFirstNameTextBox"
                    CssClass="ValidationMessage" ErrorMessage="Member First Name is required">*</asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td><asp:Label runat="server" ID="MemLastName">Member Last Name:</asp:Label></td>
            <td style="width: 187px"><asp:TextBox runat="server" ID="MemLastNameTextBox"></asp:TextBox></td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="MemLastNameTextBox"
                    CssClass="ValidationMessage" ErrorMessage="Member Last Name is required">*</asp:RequiredFieldValidator></td>
        </tr>
        <tr>
            <td style="height: 40px"></td>
            <td colspan="2" style="height: 40px">
                <span style="font-size: 10pt">
                
                disclaimer "Nominating Member name will be included in the Nomination&nbsp; Email. </span>
            </td>
        </tr>
        <tr>
            <td><asp:Label runat="server" ID="MemEmail">Member Email:</asp:Label></td>
            <td style="width: 187px"><asp:TextBox runat="server" ID="MemEmailTextBox"></asp:TextBox></td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="MemEmailTextBox"
                    ErrorMessage="Member Email is required">*</asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="MemEmailTextBox"
                    CssClass="ValidationMessage" ErrorMessage="Please enter Merchant's email correctly"
                    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
                <span style="color: #ff0066">xxx@xxx.com</span></td>
        </tr>

        <tr>
            <!-- Start info for representation-->
            <td><asp:Label runat="server" ID="RepNum">4-Digit OWU Rep ID #:</asp:Label></td>
            <td style="width: 187px"><asp:TextBox runat="server" ID="RepNumTextBox"></asp:TextBox></td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="RepNumTextBox"
                    CssClass="ValidationMessage" ErrorMessage="Rep ID is required">*</asp:RequiredFieldValidator></td>
        </tr>

            <td><asp:Label runat="server" ID="RepWeb">Member Domain Address:</asp:Label></td>
            <td style="width: 187px"><asp:TextBox runat="server" ID="RepWebTextBox"></asp:TextBox></td>
            <td></td>
            <!-- End info for representation-->
        </tr>

        
    </table>
    <br />
    <div>
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        &nbsp; &nbsp; &nbsp;<asp:Button runat="server" ID="Submit" Text="Submit" OnClick="Submit_Click" />&nbsp;&nbsp;
        &nbsp; &nbsp;
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
        <br />
        <asp:Label ID="Label1" runat="server" Height="29px" Text="Label" Width="171px"></asp:Label><br />
        <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
        <br />
        <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" CssClass="ValidationMessage"
            HeaderText="Please enter valid values in the following fields." Width="321px" />
    </div>

     

     

    HERE is my ascx code.

  • Re: everytime click submit button need to refresh page in order to do next submit

    05-14-2008, 4:30 PM
    • Loading...
    • vinz
    • Joined on 10-05-2007, 11:47 AM
    • Cebu Philippines
    • Posts 8,379

    I suspect that its because of the RequireFieldValidators.. Be sure that you input the correct and right formats before you submit so that the validation control will not trigger.. once it will trigger then it will stop you for doing some interactions on the page... You may also try removing all your Validation controls for you to test it..


    Regards,
    Vincent Maverick Durano

    Please post questions to the forums, where others may benefit.I do not offer free assistance by e-mail. Thank you!



  • Re: everytime click submit button need to refresh page in order to do next submit

    05-14-2008, 5:37 PM
    • Loading...
    • dongzhe53
    • Joined on 05-14-2008, 12:38 PM
    • Posts 10

     RequireFieldValidators are nothing wrong. I removed all of them, but still as same as before.

    I did test again. And I found when I am open the form , nothing hit the Page_Load event and whenever I do the first click on the submit button. stop point will help(hit at the Page_Load). and I let it continue. when I finished the first click. The second click doesn't do anything, not hit Page_Load or other points at all.  

  • Re: everytime click submit button need to refresh page in order to do next submit