Click here to Skip to main content
15,914,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display a label after checking condition .I have given the code after adding in c# but label is not showing

What I have tried:

My aspx page




<label for="txtName">
DishType</label>
<asp:DropDownList ID="ddddishtype" runat="server" Width="200" CssClass="form-control"
DataTextField="prodReg_Name" AppendDataBoundItems="true" onchange='BindTwoRptrs()'
DataValueField="prodReg_Id" DataSourceID="sqlds_dddregion">
<asp:ListItem Value="">Select Location

<asp:Label ID="lbalert" ForeColor="Red" Text= "You have already added this product" Visible="false" runat="server">
<asp:SqlDataSource ID="sqlds_dddregion" runat="server" ConnectionString="<%$ConnectionStrings:DatabaseConnection %>"
SelectCommand="SP_ProductRegion" SelectCommandType="StoredProcedure">







<asp:Repeater ID="rptrTable1" runat="server" >
<HeaderTemplate>

</HeaderTemplate>
<itemtemplate>

<footertemplate>
Select
Title
Qty
Add
<input type="checkbox" class="clsChk" id="test" />
<%#Eval("prod_title")%>
<input type="text" class="clsQty" id="txtQty" width="30" />
<input type="hidden" value="<%#Eval("prod_id")%>" id="hdnprodid" />

Add Products





<asp:SqlDataSource ID="sqldsTable1" runat="server" ConnectionString="<%$ConnectionStrings:DatabaseConnection %>"
SelectCommand="SP_DailyProductsSelByRegionDateToAdd" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="RegId" Name="prodReg_Id" Type="Int32" />
<asp:QueryStringParameter QueryStringField="date" Name="date" Type="String" />
</SelectParameters>







<asp:Repeater ID="Repeater1" runat="server" >
<HeaderTemplate>


</HeaderTemplate>
<itemtemplate>


<footertemplate>
Dish Name
Qty
Amount
<%#Eval("prod_title")%>( <%#Eval("prod_rate")%>)
<%#Eval("Qty")%>
<%-- <%#Eval("prod_rate")%> * <%#Eval("Qty")%> --%>
<%# String.Format("{0}", Convert.ToDecimal(Eval("prod_rate")) * Convert.ToInt32(Eval("Qty")))%>




<asp:SqlDataSource ID="sqldsDailyProducts" runat="server" ConnectionString="<%$ConnectionStrings:DatabaseConnection %>"
SelectCommand="SP_CartProductsSelByRegionDate" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter QueryStringField="RegId" Name="prodReg_Id" Type="Int32" />
<asp:QueryStringParameter QueryStringField="date" Name="date" Type="String" />
</SelectParameters>





<script src="../Admin/js/plugins/nestable/jquery.nestable_links.js" type="text/javascript"></script>
<script src="../Admin/js/plugins/nestable/ui-nestable.js" type="text/javascript"></script>
<script type="text/javascript">



function BindTwoRptrs() {
BindProductsToAdd();
BindProducts();

}


function BindProductsToAdd() {
var regId = $("#ddddishtype").val();
var dt = '<%=Request.QueryString["date"] %>';

$.ajax({
type: 'GET',
url: 'TestAddProducts.aspx?callback=GETPRODUCTSADD®Id=' + regId + '&date=' + dt + '&r=' + Math.random(),
dataType: "html",
success: function (data) {
$("#divProd").html(data);
}
});
}

function BindProducts() {
var regId = $("#ddddishtype").val();
var dt = '<%=Request.QueryString["date"] %>';

$.ajax({
type: 'GET',
url: 'TestAddProducts.aspx?callback=GETPRODUCTS®Id=' + regId + '&date=' + dt + '&r=' + Math.random(),
dataType: "html",
success: function (data) {
$("#mainOL").html(data);
}
});

}



function deleteProd(id) {
$.ajax({
type: 'GET',
url: 'TestAddProducts.aspx?callback=DELETE&id=' + id + '&r=' + Math.random(),
dataType: "html",
success: function (data) {
BindTwoRptrs();
}
});
}

function addProducts() {
// var prodId = $("#hdnprodid").val();
// var qty = $("#txtQty").val();

var result = [];
var i = 0;
var dt = '<%=Request.QueryString["date"] %>';
$(".clsQty").each(function () {

var qty = $(this).val();
var prodId = $(this).next().val();

if ($(this).parent().prev().prev().find(".clsChk").is(':checked')) {
result[i] = {
qty: qty,
prodId: prodId

};
i = i + 1;
}

});
if (result != null) {
var jsonData = JSON.stringify(result);
$.ajax({
type: 'POST',
url: 'TestAddProducts.aspx?callback=ADDPROD&date=' +dt +'&r=' +Math.random(),
data: {
postData: jsonData,
dt: '<%=Request.QueryString["date"] %>'

},

dataType: "html",
success: function (data) {
BindTwoRptrs();
}
});
}
else {
alert('Select products');

}
}
</script>

My cs-- after adding--

if (callback == "ADDPROD")
{

if (Session["Tempcartid"] == null)
{
for (int i = 0; i < 2; i++)
{
Session["Tempcartid"] = random.Next(10, 200);

}

tempcartid = Session["Tempcartid"].ToString();

}
else
{
tempcartid = Session["Tempcartid"].ToString();

}

List<productlist.dailyprod> m = JsonConvert.DeserializeObject<list><productlist.dailyprod>>(Request.Form["postData"]);
string retval = "0";
foreach (var item in m)
{
int qty = int.Parse(item.qty);
int prodId = int.Parse(item.prodId);
string datetime=Request.QueryString["date"];
dt = add.CheckProductInsert(tempcartid, prodId, datetime);
if (dt.Rows.Count != 0)
{

lbalert.Visible = true;

}
else
{

BO.ADDTOCART objAC = new BO.ADDTOCART()
{
TempCart_ID = int.Parse(tempcartid),
prod_id = prodId,
Qty = qty,
BookingDate = Request.QueryString["date"]
};

retval = add.CartInsNew(objAC);
Response.Write(retval);
Response.End();
Response.Flush();
}

}
}
Posted
Updated 29-Aug-16 0:12am

1 solution

You are using html label and not asp.net Label
So you need to give id.
To access in code behind you need to add run-at attribute.

Sample:

aspx code

ASP.NET
<label for="txtName" id="Label1" runat="server">DishType</label>



C# code
C#
if (<condition>)
{
       Label1.Visible = true
}
else
       Label1.Visible = false;
 
Share this answer
 
v2
Comments
Member 12708384 29-Aug-16 7:35am    
no iam using label lbalert which has runat server
charmyvora 30-Aug-16 2:06am    
Then it seems something wrong. Just paste your label code of aspx page and code behind

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900