How to access asp:label text property from code behind? - c#

I have a user control with a bunch of asp:label controls and I need to access their text property from the code behind. Is there an easy way to do this? I tried using the ID.Text of the label, with no luck.
Here is the ascx code:
<div id="labelContainer">
<asp:Label ID="productDescription" class="productDescription fontCaps" runat="server"
Text="express" />
<br />
<asp:Label ID="serviceDescription" class="serviceDescription fontCaps" runat="server"
Text="express 24" />
<div id="shipFrom">
<label class="font8 fontCaps" style="margin-left: 15px;">
From:</label><asp:Label ID="companyName" class="font8 fontCaps" Style="margin-left: 5px;"
runat="server" Text="customer integration management" />
<label class="meeterLabel font8 fontCaps">
MEETER:</label>
<asp:Label ID="meeterNo" class="meeterNumber font8 fontCaps" runat="server" Text="34001" />
<br />
<div id="fromAddress">
<asp:Label ID="fromAddressLine1" class="font8 fontCaps" runat="server" Text="orbital park" />
<br />
<asp:Label ID="fromAddressLine2" class="font8 fontCaps" runat="server" Text="178-188 great west road" />
<br />
<asp:Label ID="fromTown" class="font8 fontCaps" runat="server" Text="hounslow" />
<br />
<asp:Label ID="fromCountry" class="font8 fontCaps" runat="server" Text="middlesex" />
<asp:Label ID="fromPostcode" class="font8 alignRight fontCaps" runat="server" Text="tw4 6js" />
</div>
<div id="toAddress">
<label class="font8 fontCaps">
To:</label><asp:Label ID="orgName" class="font10 addressTabs fontCaps" runat="server"
Text="organisation name" />
<label class="font10 fontCaps" style="margin-left: 100px;">
Tel: </label><asp:Label ID="phone" class="font10 fontCaps" runat="server" Text="0208 818 8000" />
<br />
<asp:Label ID="departmentName" class="font10 addressTabs2 fontCaps" runat="server"
Text="department name" />
<br />
<asp:Label ID="toAddressLine1" class="font10 addressTabs2 fontCaps" runat="server"
Text="address line 1" />
<br />
<asp:Label ID="toAddressLine2" class="font10 addressTabs2 fontCaps" runat="server"
Text="address line 2" />
<br />
<asp:Label ID="toTown" class="font11 addressTabs2 fontCaps" runat="server" Text="town" />
<br />
<asp:Label ID="toCountry" class="font11 addressTabs2 fontCaps" runat="server" Text="county" />
<br />
<asp:Label ID="toPostcode" class="font11 addressTabs2 fontCaps" runat="server" Text="ub5 1aj" />
</div>
<div id="serviceCodeContainer" style="text-align: left;">
<div id="svcCode">
<label style="color: #fff; font-size: 11pt; font-family: Arial; font-weight: bold;
vertical-align: text-top;">
Handling:</label>
<br />
<asp:Label ID="serviceCode" class="fontCaps" Style="margin-left: 18px; font-size: 18pt;"
Text="STD" runat="server" />
</div>
<asp:Label ID="dayTime" class="fontCaps alignFarRight alignTop fontBold font11" runat="server" />
<asp:Label ID="pieceCount" Text="1/1" class="fontCaps pieceCountRight pieceCountTop fontBold font20"
runat="server" />
<label class="font8 fontCaps">
Shipment No: </label><asp:Label ID="shipmentNo"
class="font8 fontCaps" runat="server" Text="123456" />
<br />
<label class="font8 fontCaps">
Consignee Ref: </label><asp:Label ID="consigneeRef" class="font8 fontCaps"
runat="server" Text="Your Customer Reference" />
<br />
<label class="font8 fontCaps">
Consignor Ref: </label><asp:Label ID="consignorRef" class="font8 fontCaps"
runat="server" Text="Your Reference" />
</div>
<div style="text-align: center; margin-bottom: 5px;">
<asp:Label ID="serviceCentre" Style="padding-right: 60px;" class="font20 fontBold fontCaps"
runat="server" Text="hayes" />
<asp:Label ID="hub" class="font20 fontBold fontCaps" runat="server" Text="hatfield" />
</div>
</div>
<div>
<div style="text-align: center; margin-bottom: 5px;">
<asp:Image ID="Image1" ImageUrl="~/images/barcode.jpg" runat="server" />
</div>
<div style="text-align: center; margin-top: 5px; margin-bottom: 5px;">
<asp:Label ID="routingCode" class="font8 fontBold fontCaps" runat="server" Text="2lgbub51aj+01000002" />
</div>
<div style="text-align: center;">
<asp:Image ID="licensePlateImg" ImageUrl="~/images/barcode2.jpg" runat="server" />
</div>
<div style="text-align: center; margin-top: 5px;">
<asp:Label ID="licensePlate" class="font8 fontBold fontCaps" runat="server" Text="(J)JD00 022 340 0100 0124" />
</div>
</div>
But when I try to access it from the code behind of the user control, I get no Text property.

You need to create property in user control like:
public string Label1Text
{
get { return this.label1.Text; }
}
// using
this.myusercontrol.Label1Text;
Or try to find label inside of user control:
((Label)this.myusercontrol.FindControl('label_id')).Text

I do it by creating properties on the user conrtrol
ascx code behind.
public string FirstName
{
get { return FirstNameTextBox.Text; }
set { FirstNameTextBox.text= value; }
}
in the aspx page you can access it as shown:
MyUserControl.FirstName= "Bob";
It's a lot cleaner to access it that way from the aspx than it is to set the TextBox as a public textbox in the Ascx and accessing the TextBox directly.

Expose a property in the user control, like this:
public string LabelText
{
get
{
return Label1.Text;
}
}
And reference the property in the code-behind, like this:
string labelText = UserControl1.LabelText;

Related

html button text not changing when gridview OnSelectedIndexChanged fired

After clicking the edit button of gridview btnSaveClass.text text change as expected but on the other hand btnSave.text text not changing
I have debugged certain portion of the code. And find that it's taking the changed text btnSave.InnerText = "Update"; in this line. But some how it loose the data. And some how it becomes same as it was.
//==========================================================This is The Markup=============================
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="col-md-4 col-sm-4 col-xs-12 form-group item margin">
<input type="text" class="form-control has-feedback-left" id="txtFName" maxlength="20" onkeypress="return isNameKey(event,this)" required="required" runat="server" placeholder="First Name" />
<span class="fa fa-user form-control-feedback left" aria-hidden="true"></span>
</div>
<div class="col-md-4 col-sm-4 col-xs-12 form-group item margin">
<input type="text" class="form-control has-feedback-left" id="txtLName" onkeypress="return isNameKey(event,this)" required="required" runat="server" maxlength="20" placeholder="Last Name" />
<span class="fa fa-user form-control-feedback left" aria-hidden="true"></span>
</div>
<div class="col-md-4 col-sm-4 col-xs-12 form-group item margin">
<input type="text" class="form-control has-feedback-left" id="txtConNumber" onkeypress="return isNumberKey(event,this)" maxlength="11" required="required" runat="server" placeholder="Contact Number" />
<span class="fa fa-mobile form-control-feedback left" aria-hidden="true"></span>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<div class="ln_solid"></div>
<div class="form-group ">
<div class="col-md-6 margin ">
//===================================================This button text not changing======================
<button type="button" id="btnSave" runat="server" class="btn btn-success" onserverclick="btnSaveOnClick">Save</button>
<button id="Button2" runat="server" type="button" class="btn btn-primary" onserverclick="btnRefreshOnClick">Refresh</button>
</div>
</div>
<div class="col-md-3 col-sm-3 col-xs-12 form-group item">
<asp:TextBox ID="txtRegInfo" required="required" CssClass="form-control has-feedback-left" placeholder="Student Official Id" MaxLength="50" runat="server"></asp:TextBox>
<span class="fa fa-registered form-control-feedback left" aria-hidden="true"></span>
</div>
<div class="col-md-3 col-sm-3 col-xs-12 form-group item " style="position: relative;">
<asp:UpdatePanel ID="UpdatePa" runat="server">
<ContentTemplate>
<div class="col-md-12 col-sm-12 col-xs-12 form-group item" style="margin: 0px; padding: 0px;" id="DivddlClassName" runat="server">
<asp:DropDownList ID="ddlClassName" runat="server" CssClass="col-md-12 form-control item has-feedback-left" AutoPostBack="true" OnSelectedIndexChanged="ddlClassNameOnSelectedIndexChanged">
</asp:DropDownList>
<span class="fa fa-tasks form-control-feedback left" aria-hidden="true"></span>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="col-md-3 col-sm-3 col-xs-12 form-group item">
<asp:TextBox ID="txtClassRoll" required="required" onkeypress="return isNumberKey(event,this)" MaxLength="5" CssClass="form-control has-feedback-left" placeholder="Class Roll" runat="server"></asp:TextBox>
<span class="fa fa-star form-control-feedback left" aria-hidden="true"></span>
</div>
<div class="col-md-3 col-sm-3 col-xs-12 form-group item">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<div class="col-md-12 col-sm-12 col-xs-12 form-group item" style="margin: 0px; padding: 0px;" id="ddlSectionDiv" runat="server">
<asp:DropDownList ID="ddlSection" runat="server" CssClass="col-md-12 form-control item has-feedback-left" AutoPostBack="true">
<asp:ListItem Value="0" Text="Select A Section"></asp:ListItem>
<asp:ListItem Value="1" Text="A"></asp:ListItem>
<asp:ListItem Value="2" Text="B"></asp:ListItem>
<asp:ListItem Value="3" Text="C"></asp:ListItem>
<asp:ListItem Value="4" Text="D"></asp:ListItem>
<asp:ListItem Value="5" Text="E"></asp:ListItem>
<asp:ListItem Value="6" Text="F"></asp:ListItem>
</asp:DropDownList>
<span class="fa fa-list-alt form-control-feedback left" aria-hidden="true"></span>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="clearfix"></div>
<div class="col-md-3 col-sm-3 col-xs-12 form-group item">
<asp:UpdatePanel ID="UpdatePanel4" runat="server">
<ContentTemplate>
<div class="col-md-12 col-sm-12 col-xs-12 form-group item" style="margin: 0px; padding: 0px;" id="ddlShiftNameDiv" runat="server">
<asp:DropDownList ID="ddlShiftName" runat="server" CssClass="col-md-12 form-control item has-feedback-left" AutoPostBack="true">
<asp:ListItem Value="0" Text="Select A Shift"></asp:ListItem>
<asp:ListItem Value="1" Text="Morning"></asp:ListItem>
<asp:ListItem Value="2" Text="Day"></asp:ListItem>
<asp:ListItem Value="3" Text="Evening"></asp:ListItem>
</asp:DropDownList>
<span class="fa fa-list-alt form-control-feedback left" aria-hidden="true"></span>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<div class="form-group ">
<div class="col-md-6 ">
//==========================================================================This button text changed as expected==============================================
<button type="button" data-target="#myModal" class="btn btn-success" id="btnSaveClass" runat="server" onserverclick="btnSaveClassInfoOnClick">Save</button>
<button id="btn" runat="server" type="button" class="btn btn-primary" onserverclick="btnRefreshOnClick">Refresh</button>
</div>
</div>
//========================================================================This is the gridview===============================
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<div class="col-md-12 text-center" style="padding: 10px; background-color: red; color: white; font-weight: bold" id="lblMsg" runat="server" visible="false">One Row has Deleted</div>
<asp:GridView ID="GvStudentIformation" runat="server" Width="100%" CssClass="table table-striped table-bordered table-hover jambo_table bulk_action"
AutoGenerateColumns="False" DataKeyNames="StdntID" AllowPaging="True" OnPageIndexChanging="GvStudentIformationOnPageIndexChanged"
OnRowDeleting="GvStudentInfoOnRowDeleting" OnSelectedIndexChanged="GvStudentInfoOnSelectedIndexChanged">
<HeaderStyle HorizontalAlign="Center" ForeColor="White" BackColor="#3F5367"></HeaderStyle>
<RowStyle CssClass="even pointer " HorizontalAlign="Center" BackColor="#E9F4F2"></RowStyle>
<Columns>
<asp:BoundField DataField="RegistrationNo" ItemStyle-HorizontalAlign="Center" HeaderText="Registration No"></asp:BoundField>
<asp:BoundField DataField="FullName" ItemStyle-HorizontalAlign="Center" HeaderText="Name"></asp:BoundField>
<asp:BoundField DataField="StdntID" HeaderText="Student Class Id">
<ItemStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
</asp:BoundField>
<asp:BoundField DataField="FirstName" HeaderText="First Name">
<ItemStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
</asp:BoundField>
<asp:BoundField DataField="LastName" HeaderText="Last Name">
<ItemStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
</asp:BoundField>
<asp:BoundField DataField="StdntClassID" HeaderText="Student Class Id">
<ItemStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
</asp:BoundField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="ButtonDelete" runat="server" CausesValidation="False" CommandName="Delete"><img src="../../images/delete.png" /></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Edit" ShowSelectButton="true" ButtonType="Image" SelectImageUrl="~/images/Edit.png" ItemStyle-Height="5px" ItemStyle-HorizontalAlign="Center"></asp:CommandField>
<asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Details">
<ItemTemplate>
<asp:HyperLink ID="btnDetails" runat="server" CausesValidation="False" ForeColor="black" NavigateUrl='<%# String.Format("../Admission/StudentDetails.aspx?StdntID={0}&StdntClassID={1}", Eval("StdntID"), Eval("StdntClassID")) %>'><i class="fa fa-eye"></i> Details</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<SelectedRowStyle BackColor="#CFF0E9" Font-Bold="True" ForeColor="#333333" BorderColor="#1ABC9C" />
<HeaderStyle BackColor="#3F5367" Font-Bold="True" ForeColor="White" HorizontalAlign="Left" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="white" />
<PagerStyle HorizontalAlign="Left" ForeColor="#3F5367" CssClass="gvPagers pad" />
<PagerSettings Mode="NumericFirstLast" PageButtonCount="4" FirstPageText="First" LastPageText="Last" />
<EmptyDataTemplate>
<div class="text-center">No records found.</div>
</EmptyDataTemplate>
</asp:GridView>
<asp:HiddenField ID="HdfstdId" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
//===========Here is the problem, First button text not changing but Second Button Text Changes as Expected=================
protected void GvStudentInfoOnSelectedIndexChanged(object sender, EventArgs e)
{
string id = GvStudentIformation.SelectedRow.Cells[0].Text.Trim().Replace(" ", "");
HdfstdId.Value = id;
txtFName.Value = GvStudentIformation.SelectedRow.Cells[3].Text.Trim().Replace(" ", "");
txtLName.Value = GvStudentIformation.SelectedRow.Cells[4].Text.Trim().Replace(" ", "");
btnSave.InnerText = "Update";
btnSaveClass.InnerText = "Update";
}
Exactly I used script for changing button Text. And that solved the issue.
function ButtonTextChange() {
document.getElementById('<%=btnInfoSave.ClientID %>').innerText = "Update";
}
Here I call The funtion.
ScriptManager.RegisterStartupScript(this, this.GetType(), "CallMyFunction", "ButtonTextChange();", true);

Filtering Gridview

when I filter the Gridview I lose the Footable function.
Strange behavior, if I click on the filter button, filter by brand and select the Pireli option, then click the update button.
I lose the Footable function, but if I then click the Update button again leaving the filter as Pireli the Footable function returns!!!!!
Seeing is believing if you navigate to the following url www.tyrescanner.net
Enter registration WR08SZE
Enter postcode KA227PR
Sorry for the jumping around here.
If you click on the filer Brand option and select Pireli, the Gridview will lose the Footable function, but if you click again on the Update button the Footable function returns!!!!!!!!
<asp:Content ID="Content1" ContentPlaceHolderID="Header" runat="server">
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-footable/0.1.0/css/footable.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-footable/0.1.0/js/footable.min.js"></script>
<%--Resizing Gridview--%>
<script>
$(function () {
AttachjQueryFootableToTable();
});
function AttachjQueryFootableToTable() {
$('[id*=GridView1]').footable();
}
</script>
<script>
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
AttachjQueryFootableToTable();
});
</script>
<div class="row">
<div class="col-md-8 col-md-pull-0 ">
<asp:Label ID="lblRegText" runat="server" Text="Tyre Size: " Style="font-weight: 700; font-size: x-large" Visible="True"></asp:Label>
<asp:Label ID="lbltyresize" runat="server" Style="font-weight: 700; font-size: x-large" Visible="True"></asp:Label>
<a href="http://tyrescanner.net/pages/edit-tyre-size.aspx">
<asp:Label ID="lblEdit" runat="server" Text=" Edit" Style="font-size: large" Visible="True"></asp:Label>
</a>
</div>
</div>
<br />
<div class="row">
<div class="col-sm-4 col-md-4">
<div class="container">
<button type="button" class="btn btn-info" data-toggle="collapse" data-target="#demo"><span class="glyphicon glyphicon-filter">Filter</span></button>
<div id="demo" class="collapse">
<div class="row">
<div class="col-md-2 col-sm-2" style="width: 130px">
<h5><strong>Brand</strong></h5>
<asp:DropDownList ID="SRDDLBrand" runat="server" DataSourceID="SqlDataSourceBrand" DataTextField="TyreBrands" DataValueField="TyreBrands" Height="35px" Width="105px" AppendDataBoundItems="True">
<asp:ListItem Text="Select All" Value=" " />
</asp:DropDownList>
</div>
<div class="col-md-2 col-sm-2" style="width: 130px">
<h5><strong>Season</strong></h5>
<asp:DropDownList ID="SRDDLTyreType" runat="server" DataSourceID="SqlDataSourceTyreType" DataTextField="TyreType" DataValueField="TyreType" Height="35px" Width="105px" AppendDataBoundItems="True">
<asp:ListItem Text="Select All" Value=" " />
</asp:DropDownList>
</div>
<div class="col-md-2 col-sm-2" style="width: 130px">
<h5><strong>Fuel Efficiency</strong></h5>
<asp:DropDownList ID="SRDDLFuelCat" runat="server" DataSourceID="SqlDataSourceFuelCategory" DataTextField="TyreCategory" DataValueField="TyreCategory" Height="35px" Width="105px" AppendDataBoundItems="True">
<asp:ListItem Text="Select All" Value=" " />
</asp:DropDownList>
</div>
<div class="col-md-2 col-sm-2" style="width: 130px">
<h5><strong>Wet Grip</strong></h5>
<asp:DropDownList ID="SRDDLWetGrip" runat="server" DataSourceID="SqlDataSourceWetGrip" DataTextField="TyreCategory" DataValueField="TyreCategory" Height="35px" Width="105px" AppendDataBoundItems="True">
<asp:ListItem Text="Select All" Value=" " />
</asp:DropDownList>
</div>
<br />
<p></p>
<div class="col-md-2 col-sm-2">
<asp:Button ID="bntFilter" runat="server" OnClick="bntFIlter_Click" Text="Update Results" CssClass="btn Jumbt btn-custom" Style="color: white" role="button" Height="44px" />
</div>
</div>
</div>
</div>
</div>
</div>
<br />
<asp:UpdatePanel UpdateMode="Conditional" ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:GridView ID="GridView1" CssClass="footable" runat="server" AutoGenerateColumns="False" Style="max-width: 130%" AutoPostback="Flash" DataKeyNames="ProductID,GarageID" DataSourceID="SqlDataSourceGridViewSearchResults"
EmptyDataText="Sorry we don’t have that tyre, please email us your requirements and we will add it to our Search engine – service#tyrescanner.net"
OnSelectedIndexChanging="GridView1_SelectedIndexChanging" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound" OnRowCreated="GridView1_RowCreated">
<Columns>
<%-- 0--%>
<asp:BoundField DataField="ProductID" HeaderText="ProductID" Visible="false" />
<%--1--%>
<asp:BoundField DataField="GarageID" HeaderText="GarageID" Visible="false" />
<%-- 2--%>
<asp:BoundField DataField="GarageTown" HeaderText="Garage Location"></asp:BoundField>
<%-- 3--%>
<asp:TemplateField HeaderText="Tyre Model">
<ItemTemplate>
<asp:Label ID="lblBrand" runat="server" Text='<%#Eval("Brand")+ " " + Eval("TyreModel")%>'></asp:Label>
<br />
<asp:Label ID="Label1" runat="server" Text="£" Height="16px" Width="4px" Font-Bold="True"></asp:Label>
<asp:Label ID="lblCurrency" runat="server" Font-Bold="True" Text='<%#Eval("ProductUnitSalePrice")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<%-- 4--%>
<asp:BoundField DataField="TyreType" HeaderText="Tyre Type" />
<%-- 5 --%>
<asp:TemplateField HeaderText="Noise Level">
<ItemTemplate>
<asp:Label ID="lblNoiseEmission" runat="server" Text='<%#Eval("NoiseEmission")+ "dB"%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="FuelEfficiencyCategory" HeaderText="Fuel Efficiency" />
<%-- 6 --%>
<asp:BoundField DataField="WetGrip" HeaderText="Wet Grip" />
<%-- 7 --%>
<asp:TemplateField HeaderText="Select Quantity">
<ItemTemplate>
<asp:DropDownList ID="txtQuantity" runat="server" OnSelectedIndexChanged="txtQuantity_SelectedIndexChanged"
AutoPostBack="true" Width="55px" Height="32px" DataFormatString="{0:£ 0.0}" ForeColor="Black">
<asp:ListItem Text="0" Value=" " />
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="Errorlabel" runat="server" Text=""></asp:Label><p></p>
<asp:Label ID="LabelTotalPoundSign" runat="server" Font-Bold="true" Text="Total £" Height="16px" Width="4px"></asp:Label>
<asp:Label ID="lblTotal" runat="server" Font-Bold="true" Text="0.00" Width="30px"></asp:Label>
<asp:LinkButton runat="server" OnClick="btnOrder_Click" CommandName="Select" class="btn btn-custom btn-sm" Style="color: white">Order »</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>

Pure CSS popup WITHOUT Javascript on DropDownList Change

I have users whose group policies block Javascript; so any use of that is out of the question.
I have found a page that performs the function that I need:
Pure CSS Popup Box
However, the popup is triggered after an anchor is clicked.
My issue issue is that I want the popup to trigger on the event change in an asp:DropDownList. My intent is that if an item is not listed in the DDL, then the user will be able to select the first item "Not Listed". After this selection I need to have the popup open with elements that will allow them to add the items to the database which populates the DDL.
I have attempted to use the following in the DDL OnSelectedIndexChanged event:
Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri.ToString() + "#popup1");
This idea has failed. I believe it is because I have it inside an Update Panel. The setup is as follows:
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<!-- Main Wrapper -->
<div class="wrapper wrapper-style2">
<div class="container">
<!-- breadcrumbs -->
<br />
<div class="row 200%">
<div class="12u">
<!-- Content -->
<div id="maincontent" runat="server">
<asp:UpdatePanel ID="upInputarea" runat="server" UpdateMode="Conditional" AssociatedUpdatePanelID="updateProgress">
<ContentTemplate>
<%-- Equipment Data --%>
<section class="box post">
<h3 class="bold">Equipment Data</h3>
<asp:UpdatePanel ID="upEquipmentData" runat="server" UpdateMode="Conditional" AssociatedUpdatePanelID="updateProgress">
<ContentTemplate>
<div id="EquipmentDataDiv2" runat="server" style="float: left; border-left: 2px solid rgba(144, 144, 144, 0.25); margin-right: auto; margin-left: auto;">
<asp:Panel ID="Pnl1" runat="server" CssClass="inputSet2">
<span>Model:</span>
<asp:DropDownList ID="ddlEquipmentDataModel" runat="server" AppendDataBoundItems="true" AutoPostBack="false" CssClass="round-corners " DataSourceID="SqlModel" DataTextField="Model" DataValueField="ID" />
</asp:Panel>
<asp:Panel ID="Pnl2" runat="server" CssClass="inputSet2">
<span>Item:</span>
<asp:DropDownList ID="ddlEquipmentDataItem" runat="server" AppendDataBoundItems="true" AutoPostBack="true" CssClass="round-corners width1" DataSourceID="SqlItem" DataTextField="Component" DataValueField="ID" OnSelectedIndexChanged="ddl_SelectedIndexChanged" />
</asp:Panel>
<asp:Panel ID="Pnl5" runat="server" CssClass="inputSet2">
<span>S/N:</span>
<asp:TextBox ID="txtEquipmentDataSN" runat="server" CssClass="round-corners " />
</asp:Panel>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</section>
<%-- Submit Button --%>
<section class="box post">
<div class="inputSet">
<asp:UpdatePanel ID="upSubmit" runat="server" UpdateMode="Conditional" AssociatedUpdatePanelID="updateProgress">
<ContentTemplate>
<asp:LinkButton ID="lbSubmit" runat="server" class="button icon fa-info-sign" Style="cursor: pointer;" OnClick="btn_Click" Text="Submit" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</section>
<div id="popup1" runat="server" class="overlay">
<div class="css_popup">
<h2>Add Component to Database</h2>
<a class="close" href="#">×</a>
<div class="content">
<asp:Panel ID="Panel13" runat="server" CssClass="inputSet2">
<span>Item:</span>
<asp:TextBox ID="txtNewItem" runat="server" CssClass="round-corners " />
</asp:Panel>
<asp:Panel ID="Panel14" runat="server" CssClass="inputSet2">
<span>NSN:</span>
<asp:TextBox ID="txtNewNSN" runat="server" CssClass="round-corners " />
</asp:Panel>
<asp:Panel ID="Panel15" runat="server" CssClass="inputSet2">
<asp:LinkButton ID="lbAddItem" runat="server" class="button icon fa-info-sign" Style="cursor: pointer;" OnClick="btn_Click" Text="Add Item" />
</asp:Panel>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
</div>
</div>
<asp:UpdateProgress ID="updateProgress" runat="server">
<ProgressTemplate>
<div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0; right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity: 0.7;">
<div class="fancybox-loading">
<asp:Image ID="imgUpdateProgress" runat="server" ImageUrl="~/fancybox/fancybox_loading.gif" AlternateText="Loading ..." ToolTip="Loading ..." Style="margin-top: -22px; margin-left: -22px; position: fixed; top: 51%; left: 51%; background: url('/fancybox/fancybox_sprite2.png'); background-position: 2 -2px;" />
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
The CSS for these elements mirror that of the link provided above.

The RadListView control does not have an item placeholder specified

the code :
<telerik:RadListView ID="RadListView1" Width="100%" AllowPaging="True" runat="server"
Skin="Metro" allowsorting="true" ItemPlaceholderID="ProductsHolder" DataKeyNames="Product_ID" GroupPlaceholderID="CategoryHolder"
GroupItemCount="4" >
<GroupTemplate>
<fieldset style="float: left; width: 330px; margin-right: 15px;">
<legend><%#Eval("CATEGORY_NAME") %></legend>
<table>
<tr>
<td>
<asp:Panel ID="CategoryHolder" runat="server"></asp:Panel>
</td>
</tr>
</table>
</fieldset>
</GroupTemplate>
<LayoutTemplate>
<fieldset style="width: 100%; margin: 0 auto; border: none;" id="FieldSet1">
<telerik:RadDataPager ID="RadDataPager2" runat="server" PagedControlID="RadListView1"
Visible='<%# Container.PageCount != 1%>' Skin="Metro" PageSize="52">
<Fields>
<telerik:RadDataPagerButtonField FieldType="FirstPrev" FirstButtonText="First" PrevButtonText="Prev"
HorizontalPosition="LeftFloat" />
<telerik:RadDataPagerButtonField FieldType="Numeric" />
<telerik:RadDataPagerButtonField FieldType="NextLast" NextButtonText="Next" LastButtonText="Last"
HorizontalPosition="RightFloat" />
</Fields>
</telerik:RadDataPager>
<br />
<asp:Panel ID="ProductsHolder" runat="server">
</asp:Panel>
<table cellpadding="0" cellspacing="4" width="100%;" style="clear: both;">
<tr>
<td>
<telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="RadListView1"
Visible='<%# Container.PageCount != 1%>' Skin="Metro" PageSize="52">
<Fields>
<telerik:RadDataPagerButtonField FieldType="FirstPrev" FirstButtonText="First" PrevButtonText="Prev"
HorizontalPosition="LeftFloat" />
<telerik:RadDataPagerButtonField FieldType="Numeric" HorizontalPosition="NoFloat" />
<telerik:RadDataPagerButtonField FieldType="NextLast" NextButtonText="Next" LastButtonText="Last"
HorizontalPosition="RightFloat" />
</Fields>
</telerik:RadDataPager>
</td>
</tr>
</table>
</fieldset>
</LayoutTemplate>
<EmptyDataTemplate>
<div style="width: 100%; text-align: center;">
<b>No Results Found</b></div>
</EmptyDataTemplate>
<ItemTemplate>
<div style="float: left; padding-bottom: 20px; padding-left: 10px; padding-right: 10px;">
<div class="CardItem" style="margin: auto !important;">
<div class="cardDisplay">
<img src="../App_Themes/VivaTheme/images/loading_big.gif" alt="" onerror="javascript:this.onerror = null;this.src='../images/Orders/VivaNotAvailable.jpg';"
onload="RetrievePicture(this,'<%# Eval("PRODUCT_ID")%>');" class="lof-image"
width="180" height="117" style="margin-bottom: 5px;" />
</div>
<div class="points">
<%# DataBinder.Eval(Container.DataItem, "SALES_PRICE", "{0:###,###,###,##0.00}") + " " + Eval("CURRENCY_ABREVIATION")%>
</div>
<hr class="fleft" style="border: 1px solid #D9E1E3; width: 195px;" />
<div class="CardItemDesc">
<table width="100%" style="display: inline-block;">
<tr>
<td>
<%# Eval("PRODUCT_NAME")%>
</td>
</tr>
<tr>
<td>
<telerik:RadRating ID="RadRating1" Skin="Metro" runat="server" Enabled="false" Value='<%# Double.Parse(Eval("SALES_PRICE").ToString()) % 3 +2 %>'>
</telerik:RadRating>
</td>
</tr>
<tr>
<td>
<img src="../images/Orders/AddToCart.png" alt="Add to Cart" height="23" onclick="AddToCart(this, '<%# Eval("PRODUCT_NAME")%>', '<%# Eval("SALES_PRICE") %>', '<%# Eval("CURRENCY_ABREVIATION") %>', '<%# (Eval("UNIT_SYMBOL").ToString()=="K" ? "Kg" : (Eval("UNIT_SYMBOL").ToString() == "U" ? "Pc" : Eval("UNIT_SYMBOL"))) %>', '<%# Eval("PRODUCT_ID") %>', '<%# Telepaty.SecurityHelper.StringEncryptorDecryptor.Instance.EncryptString(Eval("PRODUCT_ID").ToString()) %>');return false;"
class="Clickable fleft" />
<% if (LoggedClient.Current != null)
{ %>
<img src="../images/Orders/BuyNow.png" alt="Buy Now" style="padding-left: 30px;"
height="23" onclick="javascript:window.location='Checkout.aspx?pID=<%# Telepaty.SecurityHelper.StringEncryptorDecryptor.Instance.EncryptString(Eval("PRODUCT_ID").ToString()) %>';return false;"
class="Clickable fright" />
<% }
else
{ %>
<img src="../images/Orders/BuyNow.png" alt="Buy Now" style="padding-left: 30px;"
height="23" onclick="javascript:window.location='/Login.aspx?ref=anonym&pID=<%# Telepaty.SecurityHelper.StringEncryptorDecryptor.Instance.EncryptString(Eval("PRODUCT_ID").ToString()) %>';return false;"
class="Clickable fright" />
<% }; %>
</td>
</tr>
</table>
</div>
</div>
</div>
</ItemTemplate>
</telerik:RadListView>
server side :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RadListView1.DataSource = OrderDataHelper.GetProductByCategoryforGrouping();
RadListView1.DataBind();
}
}
The RadListView control does not have an item placeholder specified
anyone know why this problem occured ?
You set ItemPlaceholderID="ProductsHolder" in your ListView but there is no PlaceHolder with given ID in your LayoutTemplate .
Just add this code to your LayoutTemplate
<LayoutTemplate>
<asp:PlaceHolder ID="ProductsHolder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
The error you are getting does means that you should declare a control in your LayoutTemplate which to determine where the items (ItemTemplate, EditItemTemplate etc.) should be instantiated.
Please refer to this live demo for a sample of how to construct RadListView programmatically.

RadListView automatically sorting on ID column

I am using the Telerik radlistview o display some results, i perform some grouping in my query and return a sorted and ordered resultset and set it to the datasource. For some reason (which i have been battling with all morning) the ListView re-orders the results by the ID column.
<telerik:RadListView runat="server" ID="rlThumbnailView" OnNeedDataSource="rlThumbnailView_NeedDataSource"
AllowPaging="true" PageSize="8" OnDataBound="rlThumbnailView_DataBound" OnItemDataBound="rlThumbnailView_ItemDataBound">
<LayoutTemplate>
<span style="vertical-align: top; position: relative; top: 4px">Displaying page
<%#Container.CurrentPageIndex + 1 %>
of
<%#Container.PageCount %></span> </span>
<br />
<div id="list">
<asp:Panel runat="server" ID="Panel1" Style="float: left; margin-left: 160px" Visible="<%#Container.PageCount > 1 %>">
<asp:Button runat="server" ID="PrevButton" CommandName="Page" CommandArgument="Prev"
Text="Prev Page" Enabled="<%#Container.CurrentPageIndex > 0 %>" />
<asp:Button runat="server" ID="NextButton" CommandName="Page" CommandArgument="Next"
Text="Next Page" Enabled="<%#Container.CurrentPageIndex < Container.PageCount - 1 %>" />
</asp:Panel>
<div>
<telerik:RadSlider runat="server" ID="RadSlider1" MaximumValue="3" MinimumValue="1"
Value="2" LiveDrag="false" SmallChange="1" AutoPostBack="true" OnValueChanged="RadSlider1_ValueChanged"
Width="150px" CausesValidation="false" />
</div>
<div style="clear: both;">
</div>
<asp:Panel ID="itemPlaceholder" runat="server">
</asp:Panel>
<div style="clear: both;">
</div>
</div>
</LayoutTemplate>
<ItemTemplate>
<div id="wrapper" runat="server" style="float: left; margin-top: 2px; margin-bottom: 2px;">
<telerik:RadBinaryImage ID="ThumnailImage1" runat="server" />
UPC:
<asp:Label ID="lblUPC" runat="server"></asp:Label><br />
Description:
<asp:Label ID="lblDescription" runat="server"></asp:Label>
<br />
<div id="dvCountries" runat="server">
Languages:</div>
Changes:<asp:Label ID="lblChanges" runat="server"></asp:Label>
<br />
Pack Format:<asp:Label ID="lblPackType" runat="server"></asp:Label>
<br />
Date Completed:<asp:Label ID="lblDateCompleted" runat="server"></asp:Label>
<br />
</div>
</div>
</ItemTemplate>
</telerik:RadListView>
I beleive this is based on the standard microsoft listview,
For anybody who faces the same issue, the answer appears here:
http://www.telerik.com/community/forums/aspnet-ajax/listview/listview-paging-and-sortorder.aspx
seems to be a bug with Telerik

Categories