Skip to content
Advertisement

How to cancel _doPostBack

i have a problem that i cannot solve. i just want to click one button then trigger C# code to write entered string to sql and open other aspx web site. however after writing string to sql, page is being refreshed codes are below

                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                    <a href="A3_Maturity.aspx" id="StarttoEvaluate" runat="server" class="btn btn-primary"  onserverclick="StarttoEvaluate_Click" >Enter</a>
                </div>

C#

    protected void StarttoEvaluate_Click(object sender, EventArgs e)
    {


        
    protected void StarttoEvaluate_Click(object sender, EventArgs e)
    {


        
        SqlCommand comd = new SqlCommand("insert into A3_Coaching (name) values (@p1)", con.connection());
        comd.Parameters.AddWithValue("@p1", A3name.Value.ToString());
        comd.ExecuteNonQuery();
        con.connection().Close();


    }

Advertisement

Answer

You can have the redirection in your server side code. After doing all the server side work you can add below line:

Response.Redirect("A3_Maturity.aspx");
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement