Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.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# 单击动态链接按钮的事件未触发_C#_Html_Asp.net - Fatal编程技术网

C# 单击动态链接按钮的事件未触发

C# 单击动态链接按钮的事件未触发,c#,html,asp.net,C#,Html,Asp.net,我正在应用程序中创建一个工作列表页面。我有一个要求,比如求职者点击查找工作按钮,工作就会被列出。我正在创建用于显示作业的动态表。我有一个动态链接按钮,供求职者在申请他选择的工作时使用 aspx页面 <script type="text/javascript"> function RedirectTo(id) { window.location.href = 'ApplyJobsByCandidate.aspx?id=' + id;

我正在应用程序中创建一个工作列表页面。我有一个要求,比如求职者点击查找工作按钮,工作就会被列出。我正在创建用于显示作业的动态表。我有一个动态链接按钮,供求职者在申请他选择的工作时使用

aspx页面

   <script type="text/javascript">
        function RedirectTo(id) {
            window.location.href = 'ApplyJobsByCandidate.aspx?id=' + id;
            return false;
        }
</script>

   <table>
                 <tr>
                     <td>
                         <asp:DropDownList ID="ddlFilter" runat="server" CssClass="searchMainbtn" ForeColor="White" OnSelectedIndexChanged="ddlFilter_SelectedIndexChanged" AutoPostBack="true">
                         </asp:DropDownList>                    

                     </td>
                     <td>
                         <asp:Button ID="btnFindJobs" runat="server" Text="Find Jobs" CssClass="searchMainbtn" Width="103px" OnClick="btnFindJobs_Click" />
                     </td>
                     <td>
                         <asp:Label runat="server" Width="388px" ></asp:Label>
                     </td>
                     <td>
                          <asp:Label runat="server" ID="lblName" ForeColor="Crimson" Width="205px"></asp:Label>
                     </td>
                     <td>
                         <asp:LinkButton runat="server" ID="lbLogOut" Text="Log Out" OnClick="lbLogOut_Click" ForeColor="White" Font-Underline="false" CssClass="searchMainbtn"  Width="103px" Height="20px"></asp:LinkButton>
                     </td>
                 </tr>
             </table>

<div> <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder></div>
   if (!Page.IsPostBack)
                {
                    fillDropDownList();

                    lblError.Visible = false;
                    hlError.Visible = false;        
                }

                if (Page.IsPostBack)
                {

                    lblError.Visible = false;
                    hlError.Visible = false;        
                    industryName = ddlFilter.SelectedItem.Text.ToString();
                    lblJobName.Text = industryName.ToUpper() + " JOBS";
                    this.Rows = getTableRows();
                    this.Columns = Int32.Parse("1");       
                }
public void fillDropDownList()
{
    SqlDataAdapter da = new SqlDataAdapter("select * from [OfinityJobSearch].[dbo].[tm_TargetedIndustry]", con);
    DataTable dt = new DataTable();
    da.Fill(dt);
    ddlFilter.DataSource = dt;
    ddlFilter.DataTextField = "s_IndustryName";
    ddlFilter.DataValueField = "s_ID";
    ddlFilter.DataBind();
    ddlFilter.Items.Insert(0, "Filter Jobs");
    da.Dispose();
    con.Close();
}

protected void btnFindJobs_Click(object sender, EventArgs e)
    {

        this.Rows = getTableRows();
        this.Columns = Int32.Parse("1");
        if (this.Rows == 0)
        {
            CreateANullTable();
        }
        else
        {
            PlaceHolder1.Controls.Clear();
             getJobAdsBasedonFilter();
        }

    }

  public void getJobAdsBasedonFilter()
  {

    SqlCommand cmd = new SqlCommand();
    int ID = 0;

    try
    {
        cmd.Connection = con;

        cmd.CommandText = "SELECT TOP(10) s_JobDesignation,s_JobDescription,s_NoOfVacancies,s_DatePosted,s_JobId FROM [OfinityJobSearch].[dbo].[tx_ListOfJobs] WHERE s_IndustryName='" + industryName + "' ORDER BY s_JobId ASC ";
        cmd.CommandType = CommandType.Text;


        if (cmd.Connection.State == ConnectionState.Closed)
            cmd.Connection.Open();

        using (SqlDataReader reader = cmd.ExecuteReader())    
        {              
            if (reader.HasRows)
            {                    
                while (reader.Read())
                {    
                    JobDesignation = reader.GetString(0);
                    JobDescription = reader.GetString(1);
                    NoOfVacancies = Convert.ToString(reader.GetInt32(2));
                    DatePosted = Convert.ToString(reader.GetDateTime(3)).Replace("00:00:00", "");
                    jobId = reader.GetString(4);
                    int tblRows = 1;
                    int tblCols = 1;

                    Table tbl = new Table();
                    PlaceHolder1.Controls.Add(tbl);
                    for (int i = 0; i < tblRows; i++)
                    {
                        readerrowcount = readerrowcount + 1;
                        TableRow tr = new TableRow();
                        tr.CssClass = "rowStyle1";
                        for (int j = 0; j < tblCols; j++)
                        {
                            TableCell tc = new TableCell();
                            tc.CssClass = "cellStyle1";
                           System.Web.UI.WebControls.Label txtBox = new System.Web.UI.WebControls.Label();
                           txtBox.Text = "Job ID:" + jobId + "<br />" + "Job Designation:" + JobDesignation + "<br />" + "Job Description:" + JobDescription + "<br />" + "Vacancies:" + NoOfVacancies + "<br />" + "Ad Posted On:" + DatePosted + "<br />"+"";
                           tc.Controls.Add(txtBox);
                           tr.Cells.Add(tc);
                           System.Web.UI.WebControls.LinkButton lbView = new System.Web.UI.WebControls.LinkButton();
                           lbView.Text = "<br />" + "Apply for this Job";
                           lbView.Click += new EventHandler(lbView_Click);
                           lbView.OnClientClick = "return RedirectTo('" + id + "');";
                           lbView.ID = "linkButton" + readerrowcount;       
                           tc.Controls.Add(lbView);
                           tr.Cells.Add(tc);                         
                        }

                        tbl.Rows.Add(tr);

                    }
                    ViewState["dynamictable"] = true; 
                  } reader.NextResult();

            }

        } 

    }
    catch (SqlException exception)
    {
        MessageBox.Show(exception.Message, "warning!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning);
    }
    finally
    {

        if(cmd.Connection.State==ConnectionState.Open)
        cmd.Connection.Close();
        cmd.Dispose();
    }
} 

    protected void lbView_Click(object sender, EventArgs e)
    {

    }

函数重定向到(id){
window.location.href='ApplyJobsByCandidate.aspx?id='+id;
返回false;
}
aspx.cs页面

   <script type="text/javascript">
        function RedirectTo(id) {
            window.location.href = 'ApplyJobsByCandidate.aspx?id=' + id;
            return false;
        }
</script>

   <table>
                 <tr>
                     <td>
                         <asp:DropDownList ID="ddlFilter" runat="server" CssClass="searchMainbtn" ForeColor="White" OnSelectedIndexChanged="ddlFilter_SelectedIndexChanged" AutoPostBack="true">
                         </asp:DropDownList>                    

                     </td>
                     <td>
                         <asp:Button ID="btnFindJobs" runat="server" Text="Find Jobs" CssClass="searchMainbtn" Width="103px" OnClick="btnFindJobs_Click" />
                     </td>
                     <td>
                         <asp:Label runat="server" Width="388px" ></asp:Label>
                     </td>
                     <td>
                          <asp:Label runat="server" ID="lblName" ForeColor="Crimson" Width="205px"></asp:Label>
                     </td>
                     <td>
                         <asp:LinkButton runat="server" ID="lbLogOut" Text="Log Out" OnClick="lbLogOut_Click" ForeColor="White" Font-Underline="false" CssClass="searchMainbtn"  Width="103px" Height="20px"></asp:LinkButton>
                     </td>
                 </tr>
             </table>

<div> <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder></div>
   if (!Page.IsPostBack)
                {
                    fillDropDownList();

                    lblError.Visible = false;
                    hlError.Visible = false;        
                }

                if (Page.IsPostBack)
                {

                    lblError.Visible = false;
                    hlError.Visible = false;        
                    industryName = ddlFilter.SelectedItem.Text.ToString();
                    lblJobName.Text = industryName.ToUpper() + " JOBS";
                    this.Rows = getTableRows();
                    this.Columns = Int32.Parse("1");       
                }
public void fillDropDownList()
{
    SqlDataAdapter da = new SqlDataAdapter("select * from [OfinityJobSearch].[dbo].[tm_TargetedIndustry]", con);
    DataTable dt = new DataTable();
    da.Fill(dt);
    ddlFilter.DataSource = dt;
    ddlFilter.DataTextField = "s_IndustryName";
    ddlFilter.DataValueField = "s_ID";
    ddlFilter.DataBind();
    ddlFilter.Items.Insert(0, "Filter Jobs");
    da.Dispose();
    con.Close();
}

protected void btnFindJobs_Click(object sender, EventArgs e)
    {

        this.Rows = getTableRows();
        this.Columns = Int32.Parse("1");
        if (this.Rows == 0)
        {
            CreateANullTable();
        }
        else
        {
            PlaceHolder1.Controls.Clear();
             getJobAdsBasedonFilter();
        }

    }

  public void getJobAdsBasedonFilter()
  {

    SqlCommand cmd = new SqlCommand();
    int ID = 0;

    try
    {
        cmd.Connection = con;

        cmd.CommandText = "SELECT TOP(10) s_JobDesignation,s_JobDescription,s_NoOfVacancies,s_DatePosted,s_JobId FROM [OfinityJobSearch].[dbo].[tx_ListOfJobs] WHERE s_IndustryName='" + industryName + "' ORDER BY s_JobId ASC ";
        cmd.CommandType = CommandType.Text;


        if (cmd.Connection.State == ConnectionState.Closed)
            cmd.Connection.Open();

        using (SqlDataReader reader = cmd.ExecuteReader())    
        {              
            if (reader.HasRows)
            {                    
                while (reader.Read())
                {    
                    JobDesignation = reader.GetString(0);
                    JobDescription = reader.GetString(1);
                    NoOfVacancies = Convert.ToString(reader.GetInt32(2));
                    DatePosted = Convert.ToString(reader.GetDateTime(3)).Replace("00:00:00", "");
                    jobId = reader.GetString(4);
                    int tblRows = 1;
                    int tblCols = 1;

                    Table tbl = new Table();
                    PlaceHolder1.Controls.Add(tbl);
                    for (int i = 0; i < tblRows; i++)
                    {
                        readerrowcount = readerrowcount + 1;
                        TableRow tr = new TableRow();
                        tr.CssClass = "rowStyle1";
                        for (int j = 0; j < tblCols; j++)
                        {
                            TableCell tc = new TableCell();
                            tc.CssClass = "cellStyle1";
                           System.Web.UI.WebControls.Label txtBox = new System.Web.UI.WebControls.Label();
                           txtBox.Text = "Job ID:" + jobId + "<br />" + "Job Designation:" + JobDesignation + "<br />" + "Job Description:" + JobDescription + "<br />" + "Vacancies:" + NoOfVacancies + "<br />" + "Ad Posted On:" + DatePosted + "<br />"+"";
                           tc.Controls.Add(txtBox);
                           tr.Cells.Add(tc);
                           System.Web.UI.WebControls.LinkButton lbView = new System.Web.UI.WebControls.LinkButton();
                           lbView.Text = "<br />" + "Apply for this Job";
                           lbView.Click += new EventHandler(lbView_Click);
                           lbView.OnClientClick = "return RedirectTo('" + id + "');";
                           lbView.ID = "linkButton" + readerrowcount;       
                           tc.Controls.Add(lbView);
                           tr.Cells.Add(tc);                         
                        }

                        tbl.Rows.Add(tr);

                    }
                    ViewState["dynamictable"] = true; 
                  } reader.NextResult();

            }

        } 

    }
    catch (SqlException exception)
    {
        MessageBox.Show(exception.Message, "warning!", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning);
    }
    finally
    {

        if(cmd.Connection.State==ConnectionState.Open)
        cmd.Connection.Close();
        cmd.Dispose();
    }
} 

    protected void lbView_Click(object sender, EventArgs e)
    {

    }
if(!Page.IsPostBack)
{
fillDropDownList();
lblError.Visible=false;
hlError.Visible=false;
}
如果(第IsPostBack页)
{
lblError.Visible=false;
hlError.Visible=false;
industryName=ddlFilter.SelectedItem.Text.ToString();
lblJobName.Text=industryName.ToUpper()+“作业”;
this.Rows=getTableRows();
this.Columns=Int32.Parse(“1”);
}
公共无效fillDropDownList()
{
SqlDataAdapter da=newsqldataadapter(“从[OfinityJobSearch].[dbo].[tm_TargetedIndustry]]中选择*”,con);
DataTable dt=新的DataTable();
da.填充(dt);
ddlFilter.DataSource=dt;
ddlpilter.DataTextField=“s_IndustryName”;
ddlFilter.DataValueField=“s_ID”;
ddlFilter.DataBind();
ddlpilter.Items.Insert(0,“筛选作业”);
da.Dispose();
con.Close();
}
受保护的无效btnFindJobs\u单击(对象发送方,事件参数e)
{
this.Rows=getTableRows();
this.Columns=Int32.Parse(“1”);
如果(this.Rows==0)
{
CreateANullTable();
}
其他的
{
占位符1.Controls.Clear();
getJobAdsBasedonFilter();
}
}
public void getJobAdsBasedonFilter()
{
SqlCommand cmd=新的SqlCommand();
int ID=0;
尝试
{
cmd.Connection=con;
cmd.CommandText=“从[OfinityJobSearch].[dbo].[tx_ListOfJobs]中选择前(10)个s_作业名称、s_作业描述、s_NoofAcacacacacacies、s_DatePosted、s_作业ID,其中s_IndustryName=”“+IndustryName+“‘按s_作业ID ASC排序’;
cmd.CommandType=CommandType.Text;
if(cmd.Connection.State==ConnectionState.Closed)
cmd.Connection.Open();
使用(SqlDataReader=cmd.ExecuteReader())
{              
if(reader.HasRows)
{                    
while(reader.Read())
{    
JobDesignation=reader.GetString(0);
JobDescription=reader.GetString(1);
noofvacarces=Convert.ToString(reader.GetInt32(2));
DatePosted=Convert.ToString(reader.GetDateTime(3)).Replace(“00:00:00”,”);
jobId=reader.GetString(4);
int-tblRows=1;
int-tblCols=1;
表tbl=新表();
占位符1.控件.添加(待定);
对于(int i=0;i“+”职务指定:“+Job指定+”
“+”职务描述:“+Job描述+”
“+”职位空缺:“+Noofvacances+”
“+”广告发布于:“+DatePosted+”
“+”; tc.Controls.Add(txtBox); tr.Cells.Add(tc); System.Web.UI.WebControls.LinkButton lbView=new System.Web.UI.WebControls.LinkButton(); lbView.Text=“
”+“申请这份工作”; lbView.Click+=新建事件处理程序(lbView\u Click); lbView.OnClientClick=“返回重定向到(“+id+”);”; lbView.ID=“linkButton”+readerrowcount; tc.Controls.Add(lbView); tr.Cells.Add(tc); } tbl.行.添加(tr); } ViewState[“dynamictable”]=true; }reader.NextResult(); } } } 捕获(SqlException异常) { MessageBox.Show(exception.Message,“warning!”,MessageBoxButtons.AbortRetryIgnore,MessageBoxIcon.warning); } 最后 { if(cmd.Connection.State==ConnectionState.Open) cmd.Connection.Close(); cmd.Dispose(); } } 受保护的无效lbView\u单击(对象发送方,事件参数e) { }
问题是,当求职者单击“查找工作”按钮时,工作列表中会列出,但“申请此工作”按钮根本不会启动。

请帮忙。

你可以试试这个<