Click here to Skip to main content
15,895,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form that a user can enter different data into it every time the submit button is clicked. The issue is that it is in a loop. This is what I want but I wanted to add something else. When the user clicks on the submit button I would like to display an alert message that ask, " Do you have another to enter?" with the buttons yes and no on it. If the user clicks yes the message goes away and the page refreshes with a blank form. If the user clicks no the user is redirected to the home page. Can someone show me how this is done?

C#
protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
        con.Open();
 
        SqlCommand cmd = new SqlCommand("Insert into Table50 (INST_ID, TOTAL_REVE, DATE, FINYR, INSTRUCTIO, RESEARCH, ACADEMIC_S, NET_AID, AUXILIARY_, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT) values (@INST_ID, @TOTAL_REVE, @DATE, @FINYR, @INSTRUCTIO, @RESEARCH, @ACADEMIC_S, @NET_AID, @AUXILIARY_, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LONGTERMDEBT)Insert into Table55 (INST_ID, TOTAL_REVE, DATE, FINYR, INSTRUCTIO, RESEARCH, ACADEMIC_S, NET_AID, AUXILIARY_, OTHEREXP, TOTASSETS, TOTLIABILITY, NoNEXPPERMRESASSETS, UNRNETASSETS, TOTALREV, TUITFEES, CURRDEBT, LONGTERMDEBT) values (@INST_ID, @TOTAL_REVE, @DATE, @FINYR, @INSTRUCTIO, @RESEARCH, @ACADEMIC_S, @NET_AID, @AUXILIARY_, @OTHEREXP, @TOTASSETS, @TOTLIABILITY, @NoNEXPPERMRESASSETS, @UNRNETASSETS, @TOTALREV, @TUITFEES, @CURRDEBT, @LONGTERMDEBT)", con);
 
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
        cmd.Parameters.AddWithValue("@TOTAL_REVE", TextBoxTRR.Text);
        cmd.Parameters.AddWithValue("@INSTRUCTIO", TextBoxInstr.Text);
        cmd.Parameters.AddWithValue("@RESEARCH", TextBoxResPs.Text);
        cmd.Parameters.AddWithValue("@ACADEMIC_S", TextBoxAcadSSSIS.Text);
        cmd.Parameters.AddWithValue("@NET_AID", TextBoxNGAS.Text);
        cmd.Parameters.AddWithValue("@AUXILIARY_", TextBoxAuxE.Text);
        cmd.Parameters.AddWithValue("@OTHEREXP", TextBoxAOE.Text);
        cmd.Parameters.AddWithValue("@TOTASSETS", TextBoxTA.Text);
        cmd.Parameters.AddWithValue("@TOTLIABILITY", TextBoxTL.Text);
        cmd.Parameters.AddWithValue("@NoNEXPPERMRESASSETS", TextBoxNPRNA.Text);
        cmd.Parameters.AddWithValue("@EXPENDABLE", TextBoxETRNA.Text);
        cmd.Parameters.AddWithValue("@UNRNETASSETS", TextBoxTUNA.Text);
        cmd.Parameters.AddWithValue("@TOTALREV", TextBoxTR.Text);
        cmd.Parameters.AddWithValue("@TUITFEES", TextBoxTFN.Text);
        cmd.Parameters.AddWithValue("@CURRDEBT", TextBoxCD.Text);
        cmd.Parameters.AddWithValue("@LONGTERMDEBT", TextBoxLTD.Text);
        cmd.Parameters.AddWithValue("@FINYR", lblYEAR.Text);
        cmd.Parameters.AddWithValue("@DATE", TextBoxDATE.Text);
 
        cmd.ExecuteNonQuery();
        con.Close();
 
        if (Page.IsValid)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('You Have Successfully Submitted the Financial Profile');", true);
        }
Posted

1 solution

Client side alert wont work prior to the Server side Redirection.

You can achieve it using redirection in the JS function itself .

Try like

Add alert message.
Check if user clicks OK.
If user clicks yes

use
location.reload()
which reloads/refreshes the page.

if User clicks Cancel

use
location.href='anotherpage.aspx';


Sample code :

Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "if(confirm('You Have Successfully Submitted the Financial Profile?') == true){ location.reload();}else{location.href='anotherpage.aspx';}", true);


Hope this helps
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900