请按一下按钮刷新我的网页怎么办? [英] Please how do I refresh a my webpage at a button click?

查看:57
本文介绍了请按一下按钮刷新我的网页怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请如何通过点击按钮刷新我的网页?



i想要在我的数据库中提交记录后立即在我的GridView中显示我的表单。



i希望页面自动刷新。



please how do i refresh a my webpage at a button click?

i want to my form to show in my GridView immediately after submitting the records in my data base.

i want the page to refresh itself automatically.

protected void BtnAddTraining_Click(object sender, EventArgs e)
    {
   bool exist = false;
    string sqcommand = "SELECT count(*) FROM fl_poltype WHERE poltype=@poltype";
    using (SqlCommand cmd = new SqlCommand(sqcommand, cn))
    {
        cn.Open();
        cmd.Parameters.AddWithValue("poltype", TxtPolicyCode.Text);
        exist = (int)cmd.ExecuteScalar() > 0;
    }
    //clear the filed if exist else, insert record
    if (exist)
    {
        LblError.Text = "user already exist";
        TxtPolicyCode.Focus();
        TxtPolicyCode.Text = string.Empty;
        return;

    }
    else
    {
        try
        {

            string insertCommand = "INSERT Into fl_poltype(poltype,poldesc,maxloan,income_account,liability_account,expense_account,vat_account) values(@poltype,@poldesc,@maxloan,@income_account,@liability_account,@expense_account,@vat_account)";
            SqlCommand cmd = new SqlCommand(insertCommand, cn);

            cmd.Parameters.AddWithValue("@poltype", TxtPolicyCode.Text);
            cmd.Parameters.AddWithValue("@poldesc", TxtPolicyName.Text);
            cmd.Parameters.AddWithValue("@maxloan", TxtMaxLoan.Text);
            cmd.Parameters.AddWithValue("@income_account", ddlIncomeCode.SelectedValue);
            cmd.Parameters.AddWithValue("@liability_account", ddlIncomeCode.SelectedValue);
            cmd.Parameters.AddWithValue("@expense_account", ddlLiabilityCode.SelectedValue);
            cmd.Parameters.AddWithValue("@vat_account", ddlVatCode.SelectedValue);



            cmd.ExecuteNonQuery();
            LblError.Text = "SUCCESSFULLY ADDED";
            cleared();
            
            cn.Close();
        }
        catch (Exception ex)
        {
            string log = ex.Message;
        }
        finally
        {
            cn.Close();
        }
    }     

    }

推荐答案

重新绑定gridview之后更新数据库(你没有显示你如何绑定它,所以我们不能告诉你如何做到这一点),或者另一种方法是做



Response.Redirect(yourpagename.aspx);



插入数据后。这将导致页面重新加载,并且如果用户在之后刷新页面,或者从后续页面返回页面,将避免重复发布问题。
Either re-bind your gridview after updating the database (you haven't shown how you bind it in the first place so we can't tell you how to do that), or an alternative is to do

Response.Redirect("yourpagename.aspx");

after inserting the data. That will causes the page to reload fresh and will avoid duplicate posting issues if the user refreshes the page after, or goes "back" to the page from a subsequent one.


这篇关于请按一下按钮刷新我的网页怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆