locked
How to fire dynamic link buttons in modalpopupextender RRS feed

  • Question

  • User912265481 posted

    Hi guys I have the following on my aspx page:

    <asp:UpdatePanel ID="updPnlWorkOrder" runat="server">
                            <ContentTemplate>
                                <asp:HiddenField ID="HiddenField6" runat="server" />
                                <cc1:ModalPopupExtender ID="modalPopupExtender6" runat="server" BackgroundCssClass="modalBackground"
                                    DynamicServicePath="" Enabled="True" PopupControlID="pnlConfirmation6" TargetControlID="HiddenField6"
                                    DropShadow="True">
                                </cc1:ModalPopupExtender>
                                <asp:Panel ID="pnlConfirmation6" runat="server" Style="display: none; color: Black;
                                    background-color: White; border-width: 2px; border-color: Black; border-style: solid;
                                    padding: 20px; width: 650px;">
                                    <span style="; float: right; bottom: 28px; left: 30px;">
                                        <asp:ImageButton ID="ImageButton4" runat="server" CausesValidation="false" ImageUrl="../../Images/Close_Box_Red.png"
                                            OnClick="ImageButton1_OnClick" />
                                    </span>
                                    <table>
                                        <tr>
                                            <td id = "tdListProjs" runat = "server" colspan="2" style=" padding:50px 0px 50px 0px">
                                            "The following Work Orders exist already: "
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <asp:Button ID="btnCancelWorkOrder" CssClass="button" runat="server" Text="Cancel"
                                                    OnClick="btnCancelWorkOrder_Click" />
                                            </td>
                                            <td>
                                                <asp:Button ID="btnCreateWorkOrder" CssClass="button" runat="server" Text="Create"
                                                    OnClick="btnCreateWorkOrder_Click" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                &nbsp;
                                            </td>
                                        </tr>
                                    </table>
                                </asp:Panel>
                            </ContentTemplate>
                        </asp:UpdatePanel>
    

    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.

    Wednesday, March 12, 2014 11:52 AM

Answers

  • User1208776063 posted

    foxhoundafk

    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 

    protected void page_load(object sender, EventArgs e)
    {
      if(IsPostBack)
      {
        CreateProjectLinks(some dataset);
      }
    }

    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>

    <td id = "tdListProjs" runat = "server" colspan="2" style=" padding:50px 0px 50px 0px">
     "The following Work Orders exist already: " <asp:DataList runat="server" ID="dlProjects" RepeatDirection="Horizontal"> <ItemTemplate> <asp:HyperLink NavigateUrl='<%# string.Format("ViewProject.aspx?ProjectId={0}", Eval("projectNumber")) %>' Text='<%# string.Concat(Eval("ProjectName"),"(#", Eval("projectNumber"), ")") %>' runat="server" /> &nbsp; </ItemTemplate> </asp:DataList> </td>
    protected void CreateProjectLinks(DataSet ds)
            {
                dlProjects.DataSource = ds.Tables[0];
                dlProjects.DataBind();
            }
    

    You can get ProjectId from Querystring in the viewproject as Request.QueryString["ProjectId"]; 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 13, 2014 3:11 AM

All replies

  • User1208776063 posted

    foxhoundafk

    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 

    protected void page_load(object sender, EventArgs e)
    {
      if(IsPostBack)
      {
        CreateProjectLinks(some dataset);
      }
    }

    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>

    <td id = "tdListProjs" runat = "server" colspan="2" style=" padding:50px 0px 50px 0px">
     "The following Work Orders exist already: " <asp:DataList runat="server" ID="dlProjects" RepeatDirection="Horizontal"> <ItemTemplate> <asp:HyperLink NavigateUrl='<%# string.Format("ViewProject.aspx?ProjectId={0}", Eval("projectNumber")) %>' Text='<%# string.Concat(Eval("ProjectName"),"(#", Eval("projectNumber"), ")") %>' runat="server" /> &nbsp; </ItemTemplate> </asp:DataList> </td>
    protected void CreateProjectLinks(DataSet ds)
            {
                dlProjects.DataSource = ds.Tables[0];
                dlProjects.DataBind();
            }
    

    You can get ProjectId from Querystring in the viewproject as Request.QueryString["ProjectId"]; 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 13, 2014 3:11 AM
  • User912265481 posted

    Wow thank you so much for such an extensive answer, it really was helpful and highly appreciated!!! Laughing

    Thursday, March 13, 2014 7:46 AM