我无法删除随图像标签自动生成的span标签。
Asp.net代码:
if (!IsPostBack)
{
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
SiteManagementService siteMng = new SiteManagementService();
LogedUserDTO logedUser = siteMng.GetLogedUserByUserId(Session["UserLoginID"].ToString().Trim());
LabelUser.Text = logedUser.FullName + " | " + logedUser.Company.CompanyDesc;
**LabelImage.Text = "<img src=\"" + siteMng.GetUserImageUrl() + logedUser.ProfileImage + "\" class='img-avatar' />";**
LabelDatetime.Text = DateTime.Now.ToString();
Session["UserAccessLevel"] = logedUser.UserGroupId;
Session["UserCompanyId"] = logedUser.CompanyId;
RepeaterMenu.DataSource = siteMng.GetMenuByUserGroup(logedUser.UserGroupId);
RepeaterMenu.DataBind();
LabelMasterFooter.Text = "© 2013 " + ResourceData.CompanyName + ". All rights reserved.";
}
前端代码:
<asp:Label ID="LabelImage" runat="server" ></asp:Label>
生成的HTML代码:
<span id="ContentPlaceHolderHeader_LabelImage"><img src="UploadedFiles/ProPicturs/Img_1711.JPG" class="img-avatar"></span>
我想要的代码仅仅是
<img src="UploadedFiles/ProPicturs/Img_1711.JPG" class="img-avatar">
答案 0 :(得分:0)
如果只想使用图片标签,则asp.net中有一个Image标签
protected string image_tag; // add this var in your page class and set it as protected
...
if (!IsPostBack)
{
Page.Response.Cache.SetCacheability(HttpCacheability.NoCache);
SiteManagementService siteMng = new SiteManagementService();
LogedUserDTO logedUser = siteMng.GetLogedUserByUserId(Session["UserLoginID"].ToString().Trim());
LabelUser.Text = logedUser.FullName + " | " + logedUser.Company.CompanyDesc;
image_tag = "<img src=\"" + siteMng.GetUserImageUrl() + logedUser.ProfileImage + "\" class='img-avatar' />";
LabelDatetime.Text = DateTime.Now.ToString();
Session["UserAccessLevel"] = logedUser.UserGroupId;
Session["UserCompanyId"] = logedUser.CompanyId;
RepeaterMenu.DataSource = siteMng.GetMenuByUserGroup(logedUser.UserGroupId);
RepeaterMenu.DataBind();
LabelMasterFooter.Text = "© 2013 " + ResourceData.CompanyName + ". All rights reserved.";
}
您可以尝试在.aspx页面中使用。
<%= image_tag %>
代替
<asp:Label ID="LabelImage" runat="server" ></asp:Label>
答案 1 :(得分:0)
标签控件将向页面添加HTML元素。作为div
或span
元素。所以这个
<asp:Label ID="Label1" runat="server" CssClass="MyLabel">
Content...
</asp:Label>
成为这个
<span id="Label1" class="MyLabel">
Content...
</span>
但是PlaceHolder不会生成它自己的html元素。所以下面的代码
<asp:PlaceHolder ID="PlaceHolder1" runat="server">
Content...
</asp:PlaceHolder>
会生成
Content...
但是有一些缺点,因为PlaceHolder没有CssClass
属性。