Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Asp.net如何使用验证控制代码_C#_.net_Asp.net_Validation_Ado.net - Fatal编程技术网

C# Asp.net如何使用验证控制代码

C# Asp.net如何使用验证控制代码,c#,.net,asp.net,validation,ado.net,C#,.net,Asp.net,Validation,Ado.net,实际上,我正在设计我的网页,因为我已经输入了图书id和 书的名字。键入然后单击按钮书本可用转到另一页然后不可用显示错误消息书本不可用我的项目(图书馆管理系统)Asp.net sql server如何验证页面以及如何设置验证控件以及如何设置验证控件代码。。。给我完整的细节 My code using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq;

实际上,我正在设计我的网页,因为我已经输入了图书id和
书的名字。键入然后单击按钮书本可用转到另一页然后不可用显示错误消息书本不可用我的项目(图书馆管理系统)Asp.net sql server如何验证页面以及如何设置验证控件以及如何设置验证控件代码。。。给我完整的细节

My code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;


public partial class Bookcheck : System.Web.UI.Page
{
      public Int64 Sid;
    protected void Page_Load(object sender, EventArgs e)
    {
        string Id;
        Id = Request.QueryString.Get(0);

    if (!(IsPostBack == true))
    {
        if (Request.QueryString.Get(1) == "G")
        {
            Sid = Convert.ToInt64(Id);
            if (PopulatedRecord (Sid ) == false)
            {

            }
        }
    }
}
private Boolean PopulatedRecord(Int64 Id)
{
    DataSet DS;
    DS = new DataSet();
    SqlCommand cmd = new SqlCommand();
    SqlDataAdapter da = new SqlDataAdapter();
    SqlConnection Cnn = new SqlConnection();
    string connectionstring;
    connectionstring = @"Datasource=DEVI\SQLEXPRESS;Intial catalog=librarymanagement;Integrated Security=SSPI";
    Cnn.ConnectionString = connectionstring;
    if (Cnn.State != ConnectionState.Open)
        Cnn.Open();
    cmd.Connection = Cnn;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "usbinsertdatainto";
    cmd.Parameters.Clear();
    cmd.Parameters.AddWithValue("@bookId",txtid );
    da.SelectCommand = cmd;
    try
    {
        da.Fill(DS);
    }
    catch (Exception ex)
    {
        throw new ApplicationException(
            "!!! An Error Occured While Update Record In Dtl_SecurityCapital_Upload." + ex.Message);
        lblerror.Visible = true;
        lblerror.Text = "!!! An Error Occured While " + ex.Message.ToString();
        return false;
    }
    if (DS.Tables[0].Rows.Count > 0)
    {
        txtid.Text = DS.Tables[0].Rows[0]["bookId"].ToString();
        txtnb.Text = DS.Tables[0].Rows[0]["Nameofthebook"].ToString();
    }
    cmd.Dispose();
    Cnn.Close();
    Cnn.Dispose();
    return true;
}


}
        protected void  Button2_Click(object sender, EventArgs e)
         {
        if(Page.IsValid )
        {
        Response.Redirect ("issueofbook.aspx?bookid="+txtid.Text  

                                             +"&Nameofthebook="+txtnb.Text);
          }
      }
    }      

                   Error
                               Line 59:             throw new ApplicationException(
                               Line 60:                 "!!! An Error Occured While  
                                                      Update                              

                               Record In Dtl_SecurityCapital_Upload." + ex.Message);
                                Line 61:             lblerror.Visible = true;
                                   Line 62:             lblerror.Text = "!!! An Error 
                                                Occured While " +                          
                                                             ex.Message.ToString();
第63行:返回false

亲爱的, 使用
RequiredFieldValidator
()检查文本框是否为空。 或 使用JavaScript检查文本框是否为空

标记:

<asp:TextBox ID="txtNo" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"  ErrorMessage="No Required " ControlToValidate="txtNo" />
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Name Required " ControlToValidate="txtName" />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

@muhammad akhtar感谢您以下错误即将出现
第59行:抛出新的ApplicationException(第60行:“!!!在Dtl_SecurityCapital_Upload中更新记录时出错。”+ex.Message);第61行:lblerror.Visible=true;第62行:lblerror.Text=“!!!在“+ex.Message.ToString()时发生错误;第63行:返回false如果(!(IsPostBack==true))Lol!
protected void Button1_Click(object sender, EventArgs e)
{
    if (Page.IsValid)
    {
        Response.Redirect("~/Newpage.aspx?no=" + txtNo.Text + "&name=" + txtName.Text); 
    }
}