繁体   English   中英

点击事件未触发动态链接按钮

[英]Click event not firing for dynamic link button

我正在应用程序中创建“职位列表”页面。 我有一个要求,例如求职者单击“ 寻找工作”按钮,列出了工作。 我正在创建用于显示作业的动态表 我为求职者选择的每个申请表的每个表都有一个动态链接按钮

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>

aspx.cs页面

   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)
    {

    }

问题是当求职者单击“查找作业”按钮时,作业被列出, 但是“申请此作业”根本没有触发。

在此处输入图片说明

请帮忙。

你可以试试看

   LinkButton lnkButton = new LinkButton();
   lnkButton.ID = "lnkdynamicbutton"; 
   lnkButton.Text = "Apply for this job";
   lnkButton.Click += new System.EventHandler(lnkButton_Click);

protected void lnkButton_Click(object sender, EventArgs e)
{
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "<script>alert('You Clicked me!!!')</script>");
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM