ASP.Net代码背后的按钮与字体真棒图标

时间:2017-07-20 19:27:25

标签: asp.net twitter-bootstrap font-awesome code-behind

我的设计师给了我这个,效果很好:

<button class="btn btn-circle btn-success"><i class="fa fa-check"></i></button>

带有一些引导样式和字体真棒图标的标准html按钮。

但是,我在运行时动态地在表中创建按钮,并将它们添加到页面上的占位符。现在我正在努力争取显示字体真棒图标。我在网站上的其他地方使用它们,事情更简单,字体真棒图标工作正常。

有人可以建议我如何在运行时指定按钮上的图标吗?真实世界的图标将根据不同的业务逻辑而不同。

示例代码:

        void Sample()
    {
        phDirectors.Controls.Clear();
        var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
        var user = manager.FindById(Page.User.Identity.GetUserId());

        using (var context = new UserApplicationModelEntities())
        {
            var appId = new Guid(this.hdntbApplicationsId.Value);
            var application = context.tbApplications.FirstOrDefault(app => app.tbApplicationsId == appId);

            Table oTable = new Table();
            oTable.CssClass = "table table-striped";

            TableHeaderRow oHead = new TableHeaderRow();
            TableHeaderCell oHCell = new TableHeaderCell();
            TableRow oRow;
            TableCell oCell;

            oHCell.Text = "Name";
            oHead.Cells.Add(oHCell);
            oHCell = new TableHeaderCell();
            oHCell.Text = "Verify";
            oHead.Cells.Add(oHCell);

            oTable.Rows.Add(oHead);

            foreach (tbApplicationsDirectors oDirector in application.tbApplicationsDirectors)
            {
                oRow = new TableRow();

                oCell = new TableCell();
                oCell.Text = oDirector.FirstName;
                oRow.Cells.Add(oCell);

                oCell = new TableCell();
                Button oButton = new Button();

                oButton.ID = string.Format("{0}", oDirector.tbApplicationsDirectorsId);
                oButton.CssClass = "btn btn-circle btn-primary";
                if (oDirector.IDNumber == user.IDNumber)
                {
                    //oButton.Text = "GO";
                    oButton.Click += OButtonDirectorDetails_Click;
                    oButton.Enabled = true;
                }
                else if (oDirector.EmailSent && !oDirector.EmailVerified)
                {
                    //oButton.Text = "Resend";
                    oButton.Click += OButtonResend_Click;
                }
                else
                {
                    oButton.Enabled = false;
                }

                //I tried adding it as a literal, but to no avail.
                //Literal oIconLit = new Literal();
                //oIconLit.Text = "<i class=\"fa fa-check\"></i>";
                //oButton.Controls.Add(oIconLit);

                oCell.Controls.Add(oButton);
                oRow.Cells.Add(oCell);

                oTable.Rows.Add(oRow);
            }

            this.phDirectors.Controls.Add(oTable);

        }
    }

谢谢!

0 个答案:

没有答案