Click event not firing for dynamic link button
I am creating a Job Listing page in my application. I have a requirement
like the job seeker clicks on FIND JOBS Button, the jobs are listed. I am
creating dynamic tables for displaying the jobs. I have a dynamic link
button for each table for the job seeker for APPLY FOR THE JOB of his
choice.
The aspx page
<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>
The aspx.cs page
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)
{
}
The problem is when the job seeker clicks on FIND JOBS BUTTON, the jobs
are listed but the APPLY FOR THIS JOB is not firing at all.
Please help.
No comments:
Post a Comment