I am using this
private RepoMember repoMember = new RepoMember();
public List<Member> mem { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
mem = repoMember.GetAll().ToList();
}
}
RepoMember is the generic repository and GetAll() works as the name getAll to get all the members.
I am using this in aspx file
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<% foreach (Member m in mem)
{ %>
<div class="abc">
<div class="pqr">
<asp:Label Text="<%=m.Id%>" runat="server" ID="lblEmpName"></asp:Label>
</div>
</div>
<% } %>
</div>
</form>
But it shows <%=m.Id%> in the webpage.
I want to show the list of Ids on the webpage.
I am new to asp.net.
Please help.
I am using Entity Framework with MySql Database.
Edit:
Got that I can not use asp label for that but below is working
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<% foreach (Member m in mem)
{ %>
<div class="abc">
<div class="pqr">
<div><%=m.Id%></div>
</div>
</div>
<% } %>
</div>
</form>
I do not understand why...
Related
I am trying to change the css style of the repeater to a different color on different status. The expected output is to print 6 different statuses like: In progress, complete, withdrawn so on.. Currently it has a single color, so it shows one color only. the challenging part here is to change the color dynamically based on the status. how do I achieve this? Currently it pulls the style based on "status noAction text-center" class below. Should I make any changes in the code behind or is it just a front end css change. Can someone provide me an example please.
.aspx code:
<div class="row">
<asp:Repeater ID="rptStatuses" runat="server">
<ItemTemplate>
<div class="col-md-4 col-sm-4">
<div class="status noAction text-center">
<div class="banner">
<asp:Label runat="server"> <%# Eval("ID") %></asp:Label>
</div>
<div class="label"><%# Eval("Name") %></div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
.cs code relevant part
private void GB()
{
var surveyId = 55;
var stateLabels = _manageDatasets.GetStateLabels(surveyId);
List<Status> statusesList = new List<Status>();
foreach (var sl in stateLabels)
{
if (sl.Key != -1)
statusesList.Add(new Status { ID = sl.Key.ToString(), Name = sl.Value }
);
}
this.rptStatuses.DataSource = statusesList;
this.rptStatuses.DataBind();
}
I think what you want to do is change the class in the your html and just use the embedded code to be able to dynamically change the banner color, etc. based on the status. The embedded code that you want would look something like this -
<div class="col-md-4 col-sm-4">
<% if(status == "noAction") { %>
<div class="status noAction text-center">
<div class="banner">
<asp:Label runat="server"> <%# Eval("ID") %></asp:Label>
</div>
<div class="label"><%# Eval("Name") %></div>
</div>
<% } %>
If you have any column in you table from where repeater is getting datasource then that would be pretty easy to do
something like that
<asp:Repeater ID="rptStatuses" runat="server">
<ItemTemplate>
<div class="col-md-4 col-sm-4">
<div class='<%# Convert.toInt32(eval("ActionColumnName"))==1 ? "status In progress text-center" : Convert.toInt32(eval("ActionColumnName"))==2 ? "status complete text-center" : Convert.toInt32(eval("ActionColumnName"))==3 ? "status withdrawn text-center" : "status noAction text-center" '>
<div class="banner">
<asp:Label runat="server"> <%# Eval("ID") %></asp:Label>
</div>
<div class="label"><%# Eval("Name") %></div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
How can I build a reference between a button event on a .aspx site and a function class .cs?
This is the .aspx page:
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent1" Runat="Server">
<form id="form1" runat="server">
<div class="contentText">
<div class="row">
<label for="name">Name:</label>
<input type="text" id="name" name=""><br><br>
</div>
<div class="row">
<label for="address">Address:</label>
<input type="text" id="address" name=""><br><br>
</div>
<div class="row">
<label for="phone">Phone:</label>
<input type="tel" id="phone" name=""><br><br>
</div>
<div class="row">
<label for="email">Email:</label>
<input type="email" id="email" name="">
</div>
</div>
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:GridView ID="GridView1" runat="server" >
</asp:GridView>
</div>
</form>
</asp:Content>
And here you can see my class .cs.
public class Login
{
protected void Button1Click(object sender, EventArgs e)
{
makedatatable();
}
private void makedatatable()
{
DataTable dt = new DataTable("MyTable");
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.Decimal");
column.AllowDBNull = false;
column.Caption = "Price";
column.ColumnName = "Prices";
dt.Columns.Add(column);
DataRow row;
for(int i = 0; i < 10; i++)
{
row = dt.NewRow();
row["Prices"] = i + 1;
dt.Rows.Add(row);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
The OnClick="Button1_Click" attribute in your markup tells the system which method in the server side code to execute when the form is posted back due to the click of that button. You can either rename your Button1Click to Button1_Click or add a nandler that calls Button1Click.
If it is ASP.Net Website, you are missing autowireup and codefile attributes in your .aspx page
<%# Page Language="C#" AutoEventWireup="true" CodeFile="class.cs" %>
If it is ASP.NET web application, You would have a designer.cs file auto generated for you. Then in the aspx file you can Inherit the class name
<%# Page Language="C#" AutoEventWireup="true" Inherits="MyNamespace.Login" %>
I am trying to set the visibility of a "ul" element in c# code behind but getting a null exception
Function behind Page (Master page in this instance)
protected void profileDropDown(Object sender, ImageClickEventArgs e)
{
HtmlGenericControl dropDownList = (HtmlGenericControl)Master.FindControl("profileList");
if (dropDownOpen == false)
{
dropDownList.Visible = true;
}
else
{
dropDownList.Visible = false;
}
}
Html behind Page (Master page in this instance)
<body>
<form id="form" runat="server">
<div runat="server" id="navBarContainer">
<img runat="server" id="imgLogo" src="Images/logo_netflix.png"/>
<ul id="navBarLeft">
<li id="liLobbies" class="navItem">Lobbies</li>
</ul>
<ul id="navBarRight">
<li id="liProfile" class="navItem">
<div id="profileHeader">
<img id="imgProfilePic" src="Images/img_user.png"/>
<span><asp:Label Text="Profile" runat="server" CssClass="lblProfile"></asp:Label></span>
<asp:ImageButton runat="server" id="imgDropDown" src="Images/icon_down_arrow.png" OnClick="profileDropDown"/>
</div>
<ul id="profileList">
<li id="liAccount" class="navItemProfile"><a class="navItemProfile" href="/Account/Login.aspx">Account</a></li>
<li id="liMessages" class="navItemProfile"><a class="navItemProfile" href="/Account/Login.aspx">Messages</a></li>
</ul>
</li>
<li id="liLogin" class="navItem">Login</li>
<li id="liRegister" class="navItem">Register</li>
</ul>
</div>
<asp:ContentPlaceHolder id="body" runat="server">
</asp:ContentPlaceHolder>
</form>
You must make the ul runat=server
<ul id="profileList" runat="server">
<li id="liAccount" class="navItemProfile"><a class="navItemProfile" href="/Account/Login.aspx">Account</a></li>
<li id="liMessages" class="navItemProfile"><a class="navItemProfile" href="/Account/Login.aspx">Messages</a></li>
</ul>
And the you change you method, accessing the element directly
protected void profileDropDown(Object sender, ImageClickEventArgs e)
{
profileList.Visible = !dropDownOpen;
}
I try to firean submit via an asp button. I got the error that there is no definition vor SubmitBtn_Click in 'ASP.default_aspx.
BootstrapASP.Master:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="BootstrapASP.master.cs" Inherits="Shift.BootstrapASP" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html" charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Shift</title>
<link type="text/css" rel="stylesheet" href="css/bootstrap.css" />
<link type="text/css" rel="stylesheet" href="css/main.css" />
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<asp:ContentPlaceHolder ID="head" runat="server"></asp:ContentPlaceHolder>
</head>
<body>
<div>
<asp:ContentPlaceHolder ID="ContentMain" runat="server"></asp:ContentPlaceHolder>
</div>
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/interactive.js"></script>
</body>
</html>
Default.aspx:
<%# Page Title="Shift" Language="C#" MasterPageFile="~/BootstrapASP.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Shift.WebForm1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentMain" runat="server">
<div class="container content-wrapper">
<form role="form" runat="server">
<div class="row">
<div class="col-md-4 col-md-offset-7">
<asp:LinkButton ID="SubmitBtn" runat="server" OnClick="SubmitBtn_Click" CssClass="btn btn-danger btn-lg pull-right">
<span class="glyphicon glyphicon-import"></span> Senden
</asp:LinkButton>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-1">
<h1>Set Down</h1>
<hr />
<div id="down-form-holder">
<div class="form-group">
<label for="old-pc-ci">Computer CI*</label>
<input type="text" class="form-control" name="old-pc-ci" id="old-pc-ci" />
</div>
<div class="form-group">
<label for="old-mon-ci">Monitor CI*</label>
<input type="text" class="form-control" name="old-mon-ci[]" id="old-mon-ci" />
</div>
</div>
<button type="button" id="old-add-monitor" class="btn btn-default btn-sm pull-right">
<span class="glyphicon glyphicon-plus"></span> Monitor
</button>
</div>
</div>
</form>
</div>
</asp:Content>
In the Default.aspx.cs I created an eventhandler for the "SubmitBtn_Click"
Default.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Shift
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
void SubmitBtn_Click(Object sender, EventArgs e)
{
}
}
}
Methods in C# are private by default, so your click handler is not visible from the markup. Common practice is to make them protected:
protected void SubmitBtn_Click(Object sender, EventArgs e)
Your event needs to be protected, the way you have it is defaulting to private:
protected void SubmitBtn_Click(Object sender, EventArgs e)
{
}
protected void SubmitBtn_Click(object sender, EventArgs e)
{
}
<asp:LinkButton ID="SubmitBtn" runat="server" OnClick="SubmitBtn_Click" CssClass="btn
btn-danger btn-lg pull-right">
<span class="glyphicon glyphicon-import"></span> Senden</asp:LinkButton>
I have two DropDownList with update panel when i select value from first dropdownlist then in second dropdownlist display data related first. But there is problem at run time it can't display dropdownlist and continuously refresh this page.
So please help to solve this problem.
Here is my code ASPX PAGE
<%# Page Language="C#" AutoEventWireup="true" CodeFile="AddRoomPrice.aspx.cs" Inherits="AddRoomPrice" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Presha Admin</title>
<style type="text/css">
#import url("css/style.css");
#import url('css/style_text.css');
#import url('css/form-buttons.css');
#import url('css/link-buttons.css');
#import url('css/menu.css');
#import url('css/statics.css');
#import url('css/messages.css');
#import url('css/table-sorter.css');
#import url('css/tabs.css');
#import url('css/forms.css');
#import url('css/datepicker.css');
#import url('css/jquery.fancybox-1.3.4.css');
#import url('css/accordions.css');
#import url('css/jquery.treeview.css');
#import url('css/wysiwyg.css');
#import url('css/wysiwyg.modal.css');
#import url('css/wysiwyg-editor.css');
</style>
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<link rel="shortcut icon" href="gfx/Favicon.png">
<link rel="stylesheet" type="text/css" href="css/component.css" />
<script type="text/javascript" src="js/modernizr.custom.js"></script>
<!--[if lte IE 8]>
<script type="text/javascript" src="js/excanvas.min.js"></script>
<![endif]-->
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div class="container">
<div class="logo-labels">
<img id="logo" runat="server" src="~/gfx/logo.png" height="50" />
<ul>
<li><asp:Label ID="lblAdmin" runat="server" Text="Wel come "></asp:Label></li>
<li class="logout"><asp:LinkButton ID="lnkLogout" runat="server" onclick="lnkLogout_Click"><span>Logout</span></asp:LinkButton></li>
</ul>
</div>
<div class="menu-search">
<ul>
<li>Home</li>
<li>Hotel
<ul>
<li>Hotel List</li>
<li>Add Hotel</li>
</ul>
</li>
<li>Hotel Album
<ul>
<li>Album List</li>
<li>Add Album</li>
</ul>
</li>
<li>Hotel Facility
<ul>
<li>Facility List</li>
<li>Add Facility</li>
</ul>
</li>
<li>Category
<ul>
<li>Category List</li>
<li>Add Category</li>
</ul>
</li>
<li class="current">Room Price
<ul>
<li>Price List</li>
<li>Add Price</li>
</ul>
</li>
<li>New Facility</li>
<li>Admin
<ul>
<li>Admin List</li>
<li>Add Admin</li>
</ul>
</li>
<li>Inquiry</li>
<li>Map</li>
</ul>
</div>
<div class="breadcrumbs">
<ul>
<li class="home"></li>
<li class="break">ยป</li>
<li>Add Room Price</li>
</ul>
</div>
<div class="section">
<div class="box">
<div class="title">
<h2>Add/Edit Room Category</h2>
</div>
<div class="content forms">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="line padding-left50">
<label>Hotel</label>
<asp:DropDownList ID="ddlHotel" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlHotel_SelectedIndexChanged">
</asp:DropDownList>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlHotel" EventName="selectedindexchanged" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<div class="line padding-left50">
<label>Room Category</label>
<asp:DropDownList ID="ddlCategory" runat="server">
</asp:DropDownList>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlHotel" EventName="selectedindexchanged" />
</Triggers>
</asp:UpdatePanel>
<div class="line padding-left50">
<label>Single Price</label>
<asp:TextBox ID="txtSingle" runat="server" class="medium"></asp:TextBox>
</div>
<div class="line padding-left50">
<label>Double Price</label>
<asp:TextBox ID="txtDouble" runat="server" class="medium"></asp:TextBox>
</div>
<div class="line padding-left50">
<label>Extra Bed Price</label>
<asp:TextBox ID="txtExtraBed" runat="server" class="medium"></asp:TextBox>
</div>
<div class="line padding-left50">
<label>Meal Plan</label>
<asp:TextBox ID="txtMealPlan" runat="server" class="medium"></asp:TextBox>
</div>
<div class="line padding-left50">
<label>Extra Meal Price</label>
<asp:TextBox ID="txtExtraMeal" runat="server" class="medium"></asp:TextBox>
</div>
<div class="line button" style="padding-left:325px">
<asp:Button ID="btnSubmit" runat="server" Text="Sumbit" CssClass="btn btn-2 btn-2d" onclick="btnSubmit_Click"></asp:Button>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="js/superfish.js"></script>
<script type="text/javascript" src="js/supersubs.js"></script>
<script type="text/javascript" src="js/hoverIntent.js"></script>
<script type="text/javascript" src="js/jquery.flot.js"></script>
<script type="text/javascript" src="js/jquery.graphtable-0.2.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/customInput.jquery.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.pager.js"></script>
<script type="text/javascript" src="js/jquery.sparkbox-select.js"></script>
<script type="text/javascript" src="js/jquery.fancybox-1.3.4.js"></script>
<script type="text/javascript" src="js/jquery.filestyle.mini.js"></script>
<script type="text/javascript" src="js/date.js"></script>
<script type="text/javascript" src="js/jquery.datepicker.js"></script>
<script type="text/javascript" src="js/jquery.treeview.js"></script>
<script type="text/javascript" src="js/jquery.tipsy.js"></script>
<script type="text/javascript" src="js/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="js/plugins/wysiwyg.rmFormat.js"></script>
<script type="text/javascript" src="js/controls/wysiwyg.image.js"></script>
<script type="text/javascript" src="js/controls/wysiwyg.link.js"></script>
<script type="text/javascript" src="js/controls/wysiwyg.table.js"></script>
<script type="text/javascript" src="js/inline.js"></script>
</form>
</body>
</html>
and here is CS code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
public partial class AddRoomPrice : System.Web.UI.Page
{
clsbll bll = new clsbll();
protected void Page_Load(object sender, EventArgs e)
{
if (Session["admin"] != null)
{
lblAdmin.Text = "Wel Come " + Session["admin"].ToString();
}
else
{
Response.Redirect("Login.aspx");
}
if (!Page.IsPostBack)
{
if (Session["hotelID"] != null)
{
ddlHotel.SelectedValue = Session["hotelID"].ToString();
}
ddlHotel.DataSource = bll.getHotel();
ddlHotel.DataTextField = "HName";
ddlHotel.DataValueField = "HotelID";
ddlHotel.DataBind();
ddlHotel.Items.Insert(0, "Select Hotel");
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
bll.insertRoomPrice(txtSingle.Text, txtDouble.Text, txtExtraBed.Text, txtMealPlan.Text, txtExtraMeal.Text, Convert.ToInt32(ddlCategory.SelectedValue), Convert.ToInt32(ddlHotel.SelectedValue));
txtSingle.Text = "";
txtDouble.Text = "";
txtExtraBed.Text = "";
txtMealPlan.Text = "";
txtExtraMeal.Text = "";
ddlCategory.SelectedIndex = 0;
ddlHotel.SelectedIndex = 0;
Session.Remove("hotelID");
//Session.Remove("hotel");
}
protected void ddlHotel_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCategory.DataSource = bll.getCategoryByID(ddlHotel.SelectedValue);
ddlCategory.DataTextField = "RCategoryNameBed";
ddlCategory.DataValueField = "RCategoryID";
ddlCategory.DataBind();
ddlCategory.Items.Insert(0, "Select Category");
}
protected void lnkLogout_Click(object sender, EventArgs e)
{
Session.Remove("admin");
Response.Redirect("Login.aspx");
}
}
So please reply as soon as possible
Thanks
It is not you calling the page load function, that is the way ASP.NET works. The page posts to itself, thus calling the page_load function, when any Server controls on the page are fired (those which as set to postback).
What you need to do is to put some checks to differentiate between an initial page load and a post back
if(!IsPostBack)
{
//Code when initial loading
}
else
{
// code when post back
}
UpdatePanel control has been designed to refresh only its content.
For filtering purpose you can choose one of these methods:
All related DropDownLists must be placed inside one UpdatePanel.
or
First UpdatePanel and its content must be nested in second UpdatePanel.(Not Recommended)
There is no need to declare AsyncPostBackTrigger in both methods.
Good luck.
Maybe following code resolve the problem:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["admin"] == null)
Response.Redirect("Login.aspx");
else
{
lblAdmin.Text = "Welcome " + Session["admin"].ToString();
ddlHotel.Items.Clear();
ddlHotel.Items.Add(new ListItem("Select Hotel", ""));
ddlHotel.AppendDataBoundItems = true;
ddlHotel.DataSource = bll.getHotel();
ddlHotel.DataTextField = "HName";
ddlHotel.DataValueField = "HotelID";
ddlHotel.DataBind();
if (Session["hotelID"] == null)
ddlHotel.SelectedIndex = 0;
else
ddlHotel.SelectedValue = Session["hotelID"].ToString();
ddlHotel_SelectedIndexChanged(null,null);
}
}
}
protected void ddlHotel_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCategory.Items.Clear();
ddlCategory.Items.Add(new ListItem("Select Category", ""));
ddlCategory.AppendDataBoundItems = true;
ddlCategory.DataSource = bll.getCategoryByID(ddlHotel.SelectedValue);
ddlCategory.DataTextField = "RCategoryNameBed";
ddlCategory.DataValueField = "RCategoryID";
ddlCategory.DataBind();
}
if not, I am so sorry, I can not help you more.