Behind I create links automatically based on certain conditions:
protected void CreateProjectLinks(DataSet ds)
{
List<LinkButton> projLinks = new List<LinkButton>();
int rowCount = ds.Tables[0].Rows.Count;
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i<=rowCount - 1; i++)
{
var itemKey = ds.Tables[0].Rows[i]["projectNumber"].ToString();
var itemValue = ds.Tables[0].Rows[i]["projectName"].ToString();
LinkButton lnk = new LinkButton();
lnk.Text = itemValue + "(# " + itemKey + ")";
lnk.Click += new System.EventHandler(lnk_Click);
lnk.CommandArgument = itemKey;
projLinks.Add(lnk);
}
}
foreach (LinkButton lnkButton in projLinks)
{
tdListProjs.Controls.Add(lnkButton);
Label lblColon = new Label();
lblColon.Text = "; ";
tdListProjs.Controls.Add(lblColon);
}
}
protected void lnk_Click(object sender, EventArgs e)
{
LinkButton lnk = (LinkButton)(sender);
DBProject proj = new DBProject(Convert.ToInt32(lnk.CommandArgument));
Session["SelectedProject"] = proj;
Response.Redirect("ViewProject.aspx", true);
}
The modal pop up shows fine, but if I click any of the dynamic links, they will not redirect, instead the modal popup just closes. Any ideas on how to get the redirect to fire? Thanks.
they will not redirect, instead the modal popup just close
If you are creating the link buttons dynamically, they need to recreated for page postbacks. Try calling CreateProjectLinks() in PageLoad for postbacks such as
If you do not want to save the projects dataset in session/viewstate, I would recommend binding a datalist instead of creating dynamic buttons. Also, Response.Redirect may not work quite well with update panels, you may need to a postback trigger.
foxhoundafk
<td id = "tdListProjs" runat = "server" colspan="2" style=" padding:50px 0px 50px 0px">
"The following Work Orders exist already: "
</td>
Member
1 Points
2 Posts
How to fire dynamic link buttons in modalpopupextender
Mar 12, 2014 11:52 AM|foxhoundafk|LINK
Hi guys I have the following on my aspx page:
Behind I create links automatically based on certain conditions:
The modal pop up shows fine, but if I click any of the dynamic links, they will not redirect, instead the modal popup just closes. Any ideas on how to get the redirect to fire? Thanks.
Contributor
5590 Points
1297 Posts
Re: How to fire dynamic link buttons in modalpopupextender
Mar 13, 2014 03:11 AM|dotnetzoom|LINK
If you are creating the link buttons dynamically, they need to recreated for page postbacks. Try calling CreateProjectLinks() in PageLoad for postbacks such as
If you do not want to save the projects dataset in session/viewstate, I would recommend binding a datalist instead of creating dynamic buttons. Also, Response.Redirect may not work quite well with update panels, you may need to a postback trigger.
You can get ProjectId from Querystring in the viewproject as Request.QueryString["ProjectId"];
Member
1 Points
2 Posts
Re: How to fire dynamic link buttons in modalpopupextender
Mar 13, 2014 07:46 AM|foxhoundafk|LINK
Wow thank you so much for such an extensive answer, it really was helpful and highly appreciated!!!