页面按钮点击后回发 [英] the Page is Post back on button click

查看:82
本文介绍了页面按钮点击后回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void Button3_Click(object sender, EventArgs e)
{
   bool isAnythingChecked = false;
 
   foreach (GridViewRow row in GridView1.Rows)
   {
      CheckBox chk = (CheckBox)row.FindControl("chk1");
      string empname = row.Cells[1].Text;
      string leaveid = row.Cells[2].Text;
      if (chk != null && chk.Checked)
      {
         isAnythingChecked = true;
          try
          {
              //Create sql connection and command
              string strConnect;
              strConnect = "Data Source=BALA;Initial Catalog=employees;Persist Security Info=True;User ID=sa;Password=mips123";
              SqlConnection Connection = new SqlConnection(strConnect);
              string strUpdate = "Update Leave set status = 'Approved' WHERE (LeaveID =" + leaveid + ") AND (EmpID = (Select EmpID from Emp where (Empname='" + empname + "')))";
              SqlCommand command = new SqlCommand(strUpdate, Connection);
              Connection.Open();
              command.ExecuteNonQuery();
              Connection.Close();
              Getuser1();

          }
          catch (Exception exc)
          {

          }

      }
   }
    
   if (!isAnythingChecked)
   {
      Label2.Text = "Please select atlease one record";
   }

Note:-
       how to avoid page postback on button click ,please help me friends

推荐答案

嗯,问题是什么。

Page肯定会回复按钮点击(或任何此类事件或服务器端控件)。您需要使用isPostBack在Page_Load中处理您的代码



Well, what is the question.
Page will definitely post back on button click (or any such event or server side control). You need to handle your code in Page_Load using isPostBack

protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
//First time page load
}
else
{
// subsequent page load
}





希望有所帮助

Milind



Hope that helps
Milind


你好 mbsaravanan575



将您的内容放入更新面板



它可以帮助您。





谢谢
Hello mbsaravanan575,

Put your Content inside Update Panel

It May Help You.


Thanks


这篇关于页面按钮点击后回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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