How to hide Literal in Codebehind within a ListView - c#

I currently have a panel within a listview, displaying a bunch of literals. There is a column I need to hide in the codebehind of the page. How would I go about this? The panel that contains these literal fields has UpdateMode on always.
<div class="col-md-2 col-sm-3 col-sm-offset-0 col-xs-4 col-xs-offset-0 col-md-offset-0 text-truncate ">
<p class="key">
<asp:Literal ID="Literal4" runat="server" Text='' />
</p>
<p class="text-truncate">
<asp:Literal ID="Literal7" runat="server" Text=' <%# Eval("Status") %>' />
</p>
</div>

If you are aiming to hide them from the view, you can use the code behind as displayed in this answer
Literal4.Visible = false;

Related

Need to add 'for' attibutes to labels inside a ListView control of an ASP.NET page

I have something like this
<asp:ListView ID="lvOptions" runat="server"">
<LayoutTemplate>
<p>Select an option<span>*</span></p>
<div class="row">
<asp:Literal runat="server" ID="groupPlaceHolder"></asp:Literal>
</div>
<div class="row">
<div class="w100">
<label>
Other types:</label>
<asp:DropDownList ID="ddlOtherTypes" runat="server" DataTextField="Description" DataValueField="Id"
AutoPostBack="true" Enabled="false"
</asp:DropDownList>
</div>
</div>
</LayoutTemplate>
<GroupTemplate>
<asp:Literal runat="server" ID="itemPlaceHolder"></asp:Literal>
</GroupTemplate>
<ItemTemplate>
<span class="wrap-w50">
<asp:RadioButton runat="server" ID="rdbOption" AutoPostBack="true" />
<label>
<%# Eval("Description") %></label>
</span>
</ItemTemplate>
</asp:ListView>
And I got here two labels, one fot the Other types DropDownList, and another for each RadioButton.
For this labels, I need to add a "for" attribute, and I need the clientID but, if I try to write the attibute like:
for="<%= ddlOtherTypes.ClientID %>"
for="<%= rdbOption.ClientID %>"
I got the error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Any suggestions please?
Thank you in advance.

Is it possible to add a hyperlink to ASP LinkButton

I have a link button that I want to put a hyperlink to that a popup div is called when the button is clicked.
The asp linkbutton is declared as such:
<TD Class="SpreadSheet"<ASP:LinkButtonID="lbtnViewUsers_Edit" Text="Edit" Runat="Server" onclick="#Upload"/></TD>
and the popup to be called is
<div id="Upload" class="overlay" runat="server">
<div class="popup">
<h2>Edit User &nbsp </h2>
<a class="close" href="#">×</a>
<div class="content">
<!-- content -->
</div>
</div>
</div>
Is there a way to put a sort of href = "#Upload" to the link button?
What you are looking for is a model pop. Asp.net Ajax tool kit has one, you can learn more about it at here . I created a simple sample of how to use this model pop-up. Bear in mind you first have to add the tool kit to your asp.net project (you can use nuget package manager for this) and register the control to page using
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
use the properties of Model pop extender to show and save your per record data.
<asp:Panel ID="pnlpopup" runat="server" Width="400px">
<asp:Panel ID="headerPanel" runat="server">Header text Here </asp:Panel>
<div class="form-group">
<asp:Label ID="Label1" runat="server" Text="lable 1"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</div>
</asp:Panel>
<div class="form-group">
Other data values here
<asp:LinkButton ID="lbEdit" runat="server">Edit</asp:LinkButton>
</div>

Get hidden field value in code behind

How can I get the value of the hiddenfield in code behind?
<telerik:RadRotator ID="RadRotator1" RotatorType="AutomaticAdvance" ScrollDirection="Up"
ScrollDuration="4000" runat="server" Width="714"
ItemWidth="695" Height="260px" ItemHeight="70" FrameDuration="1" InitialItemIndex="-1"
CssClass="rotator">
<ItemTemplate>
<div class="itemTemplate" style="background-image: url('IMAGES3/<%# this.GetDayOfWeek(XPath("pubDate").ToString()) %>.png');">
<div class="dateTime">
<div class="time">
<%# (this.GetTimeOnly(XPath("pubDate").ToString())) %>
</div>
<div class="date">
<%# (this.GetDateOnly(XPath("pubDate").ToString()))%>
</div>
</div>
<div class="title">
<span>
<%# System.Web.HttpUtility.HtmlEncode(XPath("title").ToString())%>
</span>
</div>
<div class="buttonDiv">
<asp:Button ID="Button1" class="button" runat="server" Text="View" OnClientClick="OnClick" />
THIS HIDDENFIELD >>>>> <asp:HiddenField id="rssLink" runat="server" value='<%= System.Web.HttpUtility.HtmlEncode(XPath("link").ToString()%>' />
</div>
<div class="description">
<span>
<%# System.Web.HttpUtility.HtmlEncode(XPath("description").ToString())%>
</span>
</div>
</div>
</ItemTemplate>
</telerik:RadRotator>
The hidden field is inside a RadRotator and I am battling to get the value of it in code behind.
You can use it's Value property
var value = this.rssLink.Value;
Edit: for the telerik control it looks like you'll need to use FindControl on the Databind - there's an article here.
when you write something like that in your aspx file you will see that in the designer file you've got a generated property with as name the id of the field you used.
So in the code behind you can use this property because the classes are partial
var value = this.rssLink.Value;
like said before
string hiddenFieldValue = rssLink.Value;
If the Hidden field has the runat="server" attribute then you should be able to access it from the server side using 2 ways:
1- using the value property.
2- using Request.Forms["hiddenFieldName"]
Check this link

How can I access the textbox value

<asp:DataList id="ItemsList"
BorderColor="black"
CellPadding="5"
CellSpacing="5"
RepeatDirection="Vertical"
RepeatLayout="Table"
RepeatColumns="3"
runat="server">
<ItemTemplate>
<a href="#" data-inline="true" data-role="button"
data-icon="star" data-iconpos="right">
<input type="text" id="txtTry" style="width: 20%" runat="server"
value="" data-mini="true"
<%# DataBinder.Eval(Container.DataItem, "StringValue") %>
</a>
</ItemTemplate>
</asp:DataList>
how can I access the value of the text box of each button in the CS. How can I access it.This is not tough but I didn't use it yet.
You need to change HTML controls <input>
to the ASP.NET controls, for example:
<asp:TextBox ID="txtTry" runat="server"></asp:TextBox>
Then later in your .cs file you can change the value of the textbox:
...
txtTry.Text = "foo";
...
yes change the html to Asp.net text box. Then you can get via method mentioned by oleksii
Even with input html text try the below sample It should normally be done with
Request.Form["elementName"]
For example, if you have
<input type="text" name="try" /> then you can use Request.Form["try"] to access its value.

display:none; on a Placeholder?

I have a placholder that I dont just want to use Visible="false" on, becouse it reserv some space on the page. I dont want the space reservation. How can I do that? Maybe use somethingels?
<asp:DataList ID="ImageList" runat="server" RepeatDirection="Horizontal" EditItemStyle-VerticalAlign="Top"
RepeatColumns="4">
<ItemTemplate>
<asp:PlaceHolder ID="phImage" runat="server" Visible="false">
<div class="prodImagesBorder"> "SOME STUFF with auto length and width"
<div class="prodImages"> "SOME STUFF"
<div class="thumbnail"> "SOME STUFF"
</div>
</div>
</div>
</asp:PlaceHolder>
</ItemTemplate>
</asp:DataList>
Codebehind:
if(ImageTabel.Rows[i]["ImgUrl"].ToString() != lblOldImgUrl.Text)
{
PlaceHolder phImage = (PlaceHolder)ImageList.Items[i].FindControl("phImage");
phImage.Visible=true;
}
A PlaceHolder does not render a tag - it's just a container for other server controls. So there's no tag on which you can set display:none.
elements with the CSS style display:None will take up no space. if you apply it to div.prodImagesBorder, it should completely hide that element.

Categories

Resources