I have a website that has a code-behind file and a separate class that has a function that takes a long time to complete.
What I want is to show some information to the visitor when the function passes a string.
I use a delegate to send a string back to the code-behind like this:
public event Feedback feedbackInfo;
public EventArgs e = null;
public delegate void Feedback(String message, bool info);
So in my function I can use FeedbackInfo("message", true); which is received by the code-behind function setFeedback:
public void example() {
new Thread(delegate()
{
crypto = new EncryptNoLibraries(#"C:\Users\Robbie\TestDES\New Microsoft Visio Drawing.vsdx", #"C:\Users\Robbie\TestDES\New Microsoft Visio Drawing encrypted.vsdx");
crypto.feedbackInfo += new EncryptNoLibraries.Feedback(setFeedback);
object[] allArgs = { EncryptNoLibraries.CryptType.ENCRYPT, lstSleutels };
object args = allArgs;
crypto.DoCryptFile(args);
}).Start();
}
public void setFeedback(String message, bool info)
{
if (info)
{
if (!infoCell.Visible)
{
errorCell.Visible = false;
infoCell.Visible = true;
}
lblInfo.Text += String.Format("- {0}<br />", message);
}
else
{
if (!errorCell.Visible)
{
infoCell.Visible = false;
errorCell.Visible = true;
}
lblError.Text += String.Format("- {0}<br />", message);
}
}
This is my webpage:
<%# Page Title="Home" Async="true" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DESEncryptie._Default" %>
<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
<script type="text/javascript">
function updater() {
__doPostBack('updatePanel', '');
}
</script>
<section class="featured">
<div class="content-wrapper">
<hgroup class="title">
<h1>DES encryptie/decryptie</h1>
</hgroup>
<p>
Kies simpelweg uw bestand. Vervolgens kiest u uw sleutel en de methode van encryptie of decryptie. Als laatste kiest u de taal waarmee u wilt werken (bijv. Java of .NET).
</p>
</div>
</section>
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<h3>Start hier:</h3>
<asp:UpdatePanel ID="updatePanel" runat="server">
<ContentTemplate>
<asp:Table runat="server" CssClass="tableStartHier">
<asp:TableRow>
<asp:TableCell>Bestand:</asp:TableCell>
<asp:TableCell>
<asp:FileUpload ID="bestand" runat="server" on />
<i>(Probleem: bestandsnamen kunnen te lang zijn)</i>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell><asp:CheckBox ID="DES" runat="server" Checked="true" TextAlign="Left"
Text="DES" OnCheckedChanged="DES_CheckedChanged" AutoPostBack="true" /></asp:TableCell>
<asp:TableCell><asp:CheckBox ID="ThreeDES" runat="server" Checked="false" TextAlign="Left"
Text="3DES" OnCheckedChanged="ThreeDES_CheckedChanged" AutoPostBack="true" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ColumnSpan="2">Sleutel:</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="sleutelDES" runat="server" Visible="true">
<asp:TableCell ColumnSpan="2"><asp:TextBox ID="txtSleutel" runat="server" placeholder="Geef een sleutel" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="sleutelDrieDES1" runat="server" Visible="false">
<asp:TableCell ColumnSpan="2"><asp:TextBox ID="txtSleutel1" runat="server" placeholder="Geef sleutel 1" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="sleutelDrieDES2" runat="server" Visible="false">
<asp:TableCell ColumnSpan="2"><asp:TextBox ID="txtSleutel2" runat="server" placeholder="Geef sleutel 2" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="sleutelDrieDES3" runat="server" Visible="false">
<asp:TableCell ColumnSpan="2"><asp:TextBox ID="txtSleutel3" runat="server" placeholder="Geef sleutel 3" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Taal:</asp:TableCell>
<asp:TableCell>
<asp:DropDownList ID="taal" runat="server" Width="75px">
<asp:ListItem Text=".NET" Value=".NET" />
<asp:ListItem Text=".NET Libraries" Value=".NETLib" />
<asp:ListItem Text="Java Libraries" Value="Java" />
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell><asp:Button id="encrypteer" Text="Encrypteer" runat="server" OnClientClick="setInterval(updater, 2500);" OnClick="encrypteer_Click" ToolTip="Encrypteer uw bestand" /></asp:TableCell>
<asp:TableCell><asp:Button id="decrypteer" runat="server" Text="Decrypteer" OnClick="decrypteer_Click" ToolTip="Decrypteer uw bestand" /></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell runat="server" ID="spinner" Visible="false">
<asp:Image ID="imgSpinner" runat="server" ImageUrl="~/Images/spinner.gif"/>Even geduld.
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ForeColor="Blue">
<asp:TableCell ID="infoCell" runat="server" ColumnSpan="2" Visible="false">
Informatieberichten tijdens het crypteren:<br />
<asp:Label ID="lblInfo" runat="server" Text="" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ForeColor="Red">
<asp:TableCell ID="errorCell" runat="server" ColumnSpan="2" Visible="false">
Foutberichten tijdens het crypteren:<br />
<asp:Label ID="lblError" runat="server" Text="" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
You can see I use a javascript to update my panel by postback every 2.5 seconds. The problem is that when the postback is triggered, the text in the label that should be update is lost.
Here are some images to illustrate. Before is how the page looks at first render and after is what is displayed after I push the encrypt button. Not all messages are displayed even after 2.5 seconds (they even disappear!).
Before:
After:
What am I doing wrong?
I guess this was my fault, I found a solution.
I added two static string variables holding the messages so far.
private static String infoMessages = "", errorMessages = "";
public void setFeedback(String message, bool info)
{
if (info)
{
if (!infoCell.Visible)
{
errorCell.Visible = false;
infoCell.Visible = true;
}
infoMessages += String.Format("- {0}<br />", message);
lblInfo.Text += infoMessages;
}
else
{
if (!errorCell.Visible)
{
infoCell.Visible = false;
errorCell.Visible = true;
}
errorMessages += String.Format("- {0}<br />", message);
lblError.Text += errorMessages;
}
}
I don't think ASP .Net web page objects persist between posts. They are recreated and populated from your session store.
In my code, I have a background operation that is global to the app. I was able to use some static members in the class to relay progress of the background task to users.
I used the ASP timer to get the postbacks:
The Timer1_Tick method has no code in it. Just a comment stating the PageLoad did the work related to showing progress.
Your case will be a bit tougher, since you can have a background task for each browser instance.
If you use a static member dictionary, keyed by session id, the background process can update the dictionary entry and Page_Load can update the user's screen.
Then there's the problem of sessions coming and going. How do you clean up such a dictionary?
Also, remember IIS tends to shut down the whole web site process after 20 minutes of no http requests.
[And while I was typing my verbose answer, you seem to have found it yourself. Good show!]
Related
I'm trying to implement a reinitialization button in my page which is linked to an UpdatePanel (AsyncPostBackTrigger). When i click on the button, it deals with an UpdateProgress.
The problem is that, because the reinitialization button is linked with an update panel, it cannot reinitialize what is outside of the UpdatePanel.
Is there a way to do some changes to the controls outside of the UpdatePanel without adding an UpdatePanel for the whole page ? In this case, i want to reinitialize the DropDownLists, the Textbox and the Repeater contained in the UpdatePanel.
How the page is rendered
ASPX code :
<body style="padding: 50px;">
<form id="form1" runat="server">
<asp:Label runat="server" ID="test"></asp:Label>
<asp:HiddenField runat="server" ID="AllDemandsTypeHfi"></asp:HiddenField>
<asp:ScriptManager runat="server" ID="ScriptManager"></asp:ScriptManager>
<asp:Panel runat="server" CssClass="panel-page-title">Création de demande</asp:Panel>
<asp:Panel runat="server" CssClass="panel-primary">
<asp:Panel runat="server" CssClass="panel-heading">Configuration de la recherche</asp:Panel>
<asp:Panel runat="server" CssClass="panel-body">
<asp:Table runat="server">
<asp:TableRow ID="BankRow">
<asp:TableCell>
<asp:Label runat="server">Banque : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList runat="server" ID="BankDdl" AutoPostBack="true" OnSelectedIndexChanged="BankDdl_SelectedIndexChanged"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server">Famille : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList runat="server" ID="FamilyDdl" AutoPostBack="true" OnSelectedIndexChanged="FamilyDdl_SelectedIndexChanged"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server">Motif : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList runat="server" ID="MotiveDdl" AutoPostBack="true" OnSelectedIndexChanged="MotiveDdl_SelectedIndexChanged"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server">Sous-motif : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList runat="server" ID="SubmotiveDdl" AutoPostBack="true" OnSelectedIndexChanged="SubmotiveDdl_SelectedIndexChanged"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label runat="server">Mots-clés : </asp:Label>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox runat="server" ID="KeywordsTbx" data-target="#modalSuggestions" data-toggle="modal"></asp:TextBox>
<div id="keywordsTbxSuggestions"></div>
<asp:HiddenField runat="server" ID="KeywordsSearchHfi"></asp:HiddenField>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<br />
<asp:Button runat="server" ID="ResearchBtn" Text="Rechercher" OnClick="ResearchBtn_Click" />
<asp:Button runat="server" ID="ReinitializeBtn" Text="Réinitialiser" OnClick="ReinitializeBtn_Click" />
</asp:Panel>
</asp:Panel>
<br />
<asp:UpdatePanel runat="server" ID="ResultsUpnl" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel runat="server" CssClass="panel-primary">
<asp:Panel runat="server" CssClass="panel-heading">Résultat de la recherche </asp:Panel>
<asp:Panel runat="server" CssClass="panel-body">
<asp:Label runat="server" ID="ResultsLb" Text="Veuillez sélectionner les critères de recherche, puis cliquer sur Rechercher."></asp:Label>
<asp:Repeater runat="server" ID="ResultsRpt">
<HeaderTemplate>
<asp:Label runat="server" Text="<b>Type de demande</b>"></asp:Label>
<table>
</HeaderTemplate>
<ItemTemplate>
<asp:Panel runat="server">
<asp:HyperLink runat="server" NavigateUrl='<%# Eval("Link") %>' Text='<%# Eval("Title") %>' Target="_blank"></asp:HyperLink>
</asp:Panel>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Panel>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ResearchBtn" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="ReinitializeBtn" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UppDemandsResult" runat="server" DisplayAfter="0">
<ProgressTemplate>
<div style="text-align: center;">
<table style="width: 100%;">
<tr>
<td>
<Loader:LoaderComponent ID="UcLoadingProgess" runat="server" />
</td>
</tr>
</table>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</form>
</body>
Code-behind :
private void HandleReinitialization()
{
this.ResultsLb.Text = DemandCreationConstants.ResearchDefaultText;
this.familyDdlSelectedValue = string.Empty;
this.motiveDdlSelectedValue = string.Empty;
this.submotiveDdlSelectedValue = string.Empty;
this.LoadFamilies(true);
this.LoadMotives(false);
this.LoadSubmotives(false);
this.ResultsRpt.DataSource = null;
this.ResultsRpt.DataBind();
this.KeywordsSearchHfi.Value = string.Empty;
this.KeywordsTbx.Text = string.Empty;
LogServiceInstance.Debug("L'utilisateur " + UserSession.UserLogOn + " a réinitialisé la recherche.");
}
HandleReinitialization is launched by the event ReinitializeBtn_Click.
If understand you correctly, you will need to create UpdatePanel2 and add whatever controls into it, then in the button Click() method of the first UpdatePanel1 invoke the Update() method.
UpdatePanel2.Update();
Update:
Make sure you set the UpdateMode of UpdatePanel2 to "Conditional"
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
// Your controls
</ContentTemplate>
</asp:UpdatePanel>
Here is what I am trying to do
Store Reservation data
Create a time table based on a date selected
Populate time table will reservations that are for date selected. for empty slots, display a slot open.
Here is what I have tried thus far
ERD
After inserting reservation data and querying all selected data for November 11th 2017
Displaying result for date is asp.net
What I would like to do
Have the schedule time table have slots starting from 6:00am and go
to 7:00pm. Go by intervals as provided by the following image below.
Be able to add reservations to empty slots using.
Be able to view details of current slots (only player names)
I have included my current code for the aspx file and the aspx.cs file below. Any help or guidance would be greatly appreciated. Thank you for your time.
ASPX
<%# Page Language="C#" AutoEventWireup="true" CodeFile="MakeReservation.aspx.cs" Inherits="ClubBAIST.CBS.UI.MakeReservation" %>
<%--<%# Import Namespace="ClubBAIST.CBS.UI"%>--%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="lblDate" runat="server" Text="Date: "></asp:Label>
<asp:TextBox ID="tbxDate" runat="server"></asp:TextBox>
<%-- Expand/Hide Calendar --%>
<asp:Button ID="BtnCalendar" runat="server" OnClick="BtnCalendar_Click" Height="25px" Width="25px" Text="+" />
<%-- Handle customer selection via calendar control --%>
<asp:Calendar ID="calCalendar" runat="server" Visible="False" OnSelectionChanged="calCalendar_SelectionChanged" BackColor="White" BorderColor="White" BorderWidth="1px" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="190px" NextPrevFormat="FullMonth" Width="350px">
<DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" VerticalAlign="Bottom" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#333399" ForeColor="White" />
<TitleStyle BackColor="White" BorderColor="Black" BorderWidth="4px" Font-Bold="True" Font-Size="12pt" ForeColor="#333399" />
<TodayDayStyle BackColor="#CCCCCC" />
</asp:Calendar>
<%-- Drop down for days of the week --%>
<asp:Label ID="lblDayOfWeek" runat="server" Text="Day Of Week: "></asp:Label>
<asp:DropDownList ID="ddlDayOfWeek" runat="server">
<asp:ListItem Text="Sunday" Value="Sunday"></asp:ListItem>
<asp:ListItem Text="Monday" Value="Monday"></asp:ListItem>
<asp:ListItem Text="Tuesday" Value="Tuesday"></asp:ListItem>
<asp:ListItem Text="Wednesday" Value="Wednesday"></asp:ListItem>
<asp:ListItem Text="Thursday" Value="Thursday"></asp:ListItem>
<asp:ListItem Text="Friday" Value="Friday"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="GetTeeTimes" runat="server" Text="Find Tee Times" />
<br />
<asp:Table ID="TeeTimesTable" runat="server">
</asp:Table>
<asp:GridView ID="gvTeeTime" runat="server" OnSelectedIndexChanged="gvTeeTime_SelectedIndexChanged">
</asp:GridView>
<br />
<div>
<asp:Table ID="BookingTable" runat="server" Visible="false">
<asp:TableRow>
<asp:TableHeaderCell>
<h3>Book Tee Time</h3>
</asp:TableHeaderCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Date:
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="Date" TextMode="Date" runat="server"></asp:TextBox><br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Time:
</asp:TableCell>
<asp:TableCell>
Hour:
<asp:DropDownList ID="Hour" runat="server">
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
</asp:DropDownList>
Minute:<asp:DropDownList ID="Minute" runat="server">
<asp:ListItem>00</asp:ListItem>
<asp:ListItem>07</asp:ListItem>
<asp:ListItem>15</asp:ListItem>
<asp:ListItem>22</asp:ListItem>
<asp:ListItem>30</asp:ListItem>
<asp:ListItem>37</asp:ListItem>
<asp:ListItem>45</asp:ListItem>
<asp:ListItem>52</asp:ListItem>
</asp:DropDownList>
AMorPM
<asp:DropDownList ID="AMorPM" AutoPostBack="true" OnSelectedIndexChanged="AMorPM_SelectedIndexChanged" runat="server">
<asp:ListItem>AM</asp:ListItem>
<asp:ListItem>PM</asp:ListItem>
</asp:DropDownList><br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Number of Players:
</asp:TableCell>
<asp:TableCell>
<asp:RadioButtonList OnSelectedIndexChanged="NumberOfPlayers_SelectedIndexChanged" ID="NumberOfPlayers" runat="server" RepeatDirection="Horizontal" AutoPostBack="True">
<asp:ListItem Selected="True">1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
</asp:RadioButtonList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Member Type :
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList
ID="MemberTypeDDL"
runat="server">
<asp:ListItem> </asp:ListItem>
<asp:ListItem Text="Gold" Value="1"> </asp:ListItem>
<asp:ListItem Text="Silver" Value="2"> </asp:ListItem>
<asp:ListItem Text="Bronze" Value="3"> </asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
MemberNumber:
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="MemberNumber" runat="server" Enabled="True"></asp:TextBox><br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Player 1:
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="MemberName1" runat="server" Enabled="true"></asp:TextBox><br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Player 2:
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="MemberName2" runat="server" Enabled="false"></asp:TextBox><br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Player 3:
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="MemberName3" runat="server" Enabled="false"></asp:TextBox><br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Player 4:
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="MemberName4" runat="server" Enabled="false"></asp:TextBox><br />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Number Of Carts:
</asp:TableCell>
<asp:TableCell>
<asp:DropDownList
ID="NoOfCartsDDL"
runat="server">
<asp:ListItem> </asp:ListItem>
<asp:ListItem Text="None" Value="0"> </asp:ListItem>
<asp:ListItem Text="One" Value="1"> </asp:ListItem>
<asp:ListItem Text="Two" Value="2"> </asp:ListItem>
<asp:ListItem Text="Three" Value="3"> </asp:ListItem>
<asp:ListItem Text="Four" Value="4"> </asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableFooterRow>
<asp:TableCell>
<asp:Button ID="BookTeeTime" runat="server" OnClick="BookTeeTime_Click" Text="Book Tee Time" />
</asp:TableCell>
</asp:TableFooterRow>
</asp:Table>
</div>
<asp:Label ID="Message" runat="server" Text=""></asp:Label><br /><br />
</form>
</body>
</html>
ASPX.CS
using ClubBAIST.CBS.Domain;
using ClubBAIST.CBS.TechnicalServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
/// <summary>
/// Namespace for all UI for Club BAIST
/// </summary>
namespace ClubBAIST.CBS.UI
{
/// <summary>
/// Interacts with the Controller class CBS to create a reservation
/// </summary>
public partial class MakeReservation : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}//eom
/// <summary>
/// When user changes selection, whether via DDL or Calendar, update the Textbox field.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void calCalendar_SelectionChanged(object sender, EventArgs e)
{
tbxDate.Text = calCalendar.SelectedDate.ToShortDateString();
ddlDayOfWeek.Text = calCalendar.SelectedDate.DayOfWeek.ToString();
BookingTable.Visible = true;
Date.Text = calCalendar.SelectedDate.ToShortDateString();
calCalendar.Visible = false;
//ViewReservationSheet
//ClubBAISTController TeeTimeDirector = new ClubBAISTController();
TeeTimes TeeTimesManager = new TeeTimes();
DateTime ttDate = Convert.ToDateTime( tbxDate.Text);
gvTeeTime.DataSource = TeeTimesManager.GetTeeTime(ttDate);
gvTeeTime.DataBind();
//TeeTime TeeTimeManager = new TeeTime();
}//eom
/// <summary>
/// Makes the Calendar appear upon expanding
/// </summary>
protected void BtnCalendar_Click(object sender, EventArgs e)
{
calCalendar.Visible = true;
}//eom
protected void NumberOfPlayers_SelectedIndexChanged(object sender, EventArgs e)
{
if (NumberOfPlayers.SelectedIndex == 0)
{
MemberName1.Enabled = true;
MemberName2.Enabled = false;
MemberName3.Enabled = false;
MemberName4.Enabled = false;
MemberName2.Text = "";
MemberName3.Text = "";
MemberName4.Text = "";
}
else if (NumberOfPlayers.SelectedIndex == 1)
{
MemberName1.Enabled = true;
MemberName2.Enabled = true;
MemberName3.Enabled = false;
MemberName4.Enabled = false;
MemberName3.Text = "";
MemberName4.Text = "";
}
else if (NumberOfPlayers.SelectedIndex == 2)
{
MemberName1.Enabled = true;
MemberName2.Enabled = true;
MemberName3.Enabled = true;
MemberName4.Enabled = false;
MemberName4.Text = "";
}
else
{
MemberName1.Enabled = true;
MemberName2.Enabled = true;
MemberName3.Enabled = true;
MemberName4.Enabled = true;
}
}
protected void AMorPM_SelectedIndexChanged(object sender, EventArgs e)
{
Hour.Items.Clear();
if (AMorPM.SelectedIndex == 0)
{
Hour.Items.Add("6");
Hour.Items.Add("7");
Hour.Items.Add("8");
Hour.Items.Add("9");
Hour.Items.Add("10");
Hour.Items.Add("11");
}
else
{
Hour.Items.Add("12");
Hour.Items.Add("1");
Hour.Items.Add("2");
Hour.Items.Add("3");
Hour.Items.Add("4");
Hour.Items.Add("5");
Hour.Items.Add("6");
Hour.Items.Add("7");
Hour.Items.Add("8");
}
}
protected void gvTeeTime_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void BookTeeTime_Click(object sender, EventArgs e)
{
int hours = int.Parse(Hour.SelectedItem.Text);
int minutes = int.Parse(Minute.SelectedItem.Text);
if (AMorPM.SelectedItem.Text == "PM" && hours != 12)
hours += 12;
string datetime = Date.Text;
datetime += " " + hours.ToString() + ":" + minutes.ToString();
TeeTime NewTeeTime;
DateTime DateT = DateTime.Parse(datetime);
try
{
NewTeeTime = new TeeTime(DateT, DateT, Convert.ToInt32(MemberNumber.Text), MemberName1.Text, MemberName2.Text, MemberName3.Text, MemberName4.Text, Convert.ToInt32(NumberOfPlayers.SelectedValue), Convert.ToInt32(NoOfCartsDDL.SelectedValue),Convert.ToInt32(MemberTypeDDL.SelectedValue));
}
catch (Exception)
{
Message.Text = "Some of your fields are incorrect";
return;
}
ClubBAISTController RequestHandler = new ClubBAISTController();
if (RequestHandler.ReserveTeeTime(NewTeeTime))
{
Message.Text = "Reservation was successfuly made.";
//update teeTimes
TeeTimes TeeTimesManager = new TeeTimes();
DateTime ttDate = Convert.ToDateTime(tbxDate.Text);
gvTeeTime.DataSource = TeeTimesManager.GetTeeTime(ttDate);
gvTeeTime.DataBind();
}
else
{
Message.Text = "Reservation could not be made.";
}
}
}//eoc
}//eon
I have a C# repeater that is running a test list of objects and it runs the correct amount of iterations. The problem is is that the data is not visible on the web page. I have created an object but it seems like I am not accessing it correctly when it is time to bind it.
I have tested the objects and they do contain the test data.
ASPX CODE
<asp:Repeater ID="repeater" runat="server">
<ItemTemplate>
<asp:Panel ID="header" runat="server">
<asp:Panel ID="reportName" runat="server">
<p class='text-bold-xlg'>
<asp:Label ID="CampaignNameData" Text="Campaign Name" runat="server"></asp:Label></p>
<p class="text-md">
<asp:Label ID="ReportRangeLabel" Text="Report Range: " runat="server"></asp:Label>
<asp:Label ID="ReportRangeData" Text="" runat="server"></asp:Label>
</p>
</asp:Panel>
<asp:Panel ID="logo" runat="server">
<img src="images/Picture1.jpg" runat="server" enableviewstate="true" />
</asp:Panel>
</asp:Panel>
<asp:Panel ID="info" runat="server">
<asp:Panel ID="drPersonal" runat="server">
<p class='text-bold-lg'>
<asp:Label ID="DoctorNameData" Text="<%# DataBinder.Eval(Container.DataItem, "Name") %>"></asp:Label></p>
<asp:Table ID='drInfoTable' runat="server">
<asp:TableRow>
<asp:TableCell>
<p class='text-bold-md'>
<asp:Label ID="SpecialtyLabel" Text="Specialty:" runat="server"></asp:Label></p>
</asp:TableCell>
<asp:TableCell>
<p class='text-md'>
<asp:Label ID="SpecialtyData" Text="<%# DataBinder.Eval(Container.DataItem, "Specialty") %>"></asp:Label></p>
</asp:TableCell>
</asp:TableRow>
<..close table>
</itemTemplate>
</asp:Repeater>
ASPX.CS CODE
protected void Page_Load(object sender, EventArgs e)
{
List<Doctor> lstHcp = new List<Doctor>();
Doctor a = new Doctor();
a.Name = "Dr. A";
a.Decile = "10";
Doctor b = new Doctor();
b.Name = "Dr. B";
b.Decile = "5";
Doctor c = new Doctor();
c.Name = "Dr. C";
c.Decile = "7";
Doctor d = new Doctor();
d.Name = "Dr. D";
d.Decile = "2";
lstHcp.Add(a);
lstHcp.Add(b);
lstHcp.Add(c);
lstHcp.Add(d);
repeater.DataSource = lstHcp;
repeater.DataBind();
The asp:Label is missing the runat attribute.
The line should be:
<asp:Label ID="DoctorNameData" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'></asp:Label>
(notice the use of single quotes for the Text attribute. Else a The server tag is not well formed. exception will be thrown)
DataBinder.Eval(Container.DataItem, "Specialty")
change it to following:
DataBinder.Eval(Container.DataItem, "Decile")
I am badly stuck on this problem and would appreciate any kinds of helps! I have to create a page where the user can add more rows by clicking a button. For example, I have the first row with 2 text boxes (name and birth dates), second row with the "Add Row" button. When the user clicks the "Add Row" button, the first row should be cloned and repeated...but the user can't add more than 5 rows. Later all the information need to be saved in a SQL table. How this can be achieved in C#?
I am attaching my sample ASP.NET. Can any one PLEASE help me?
PS: I have already read and tried "How to: Add Rows and Cells Dynamically to a Table Web Server Control"....but that's not working for me.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Testing Adding Rows</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Table ID="Table1" runat="server" width="400" style="border:[none][0]; border-color:White; border-style:hidden">
<asp:TableRow ID="TableRow1" runat="server">
<asp:TableCell runat="server" nowrap="nowrap" Width= "70">
<asp:Label ID="nameLabel" runat="server" Text="Your Name" Font-Size="X-Small"></asp:Label>
</asp:TableCell>
<asp:TableCell runat="server" nowrap="nowrap" Width= "100">
<asp:TextBox ID="tb_name" runat="server" Font-Size="Smaller"></asp:TextBox>
<asp:RequiredFieldValidator ID="nameValidator" runat="server" ControlToValidate="tb_name" Font-Size="Smaller">*</asp:RequiredFieldValidator>
</asp:TableCell>
<asp:TableCell runat="server" nowrap="nowrap" Width= "70">
<asp:Label ID="dateLabel" runat="server" Text="Birthdate" Font-Size="Smaller" ></asp:Label>
</asp:TableCell>
<asp:TableCell runat="server" Width= "100">
<asp:TextBox ID="tb_date" runat="server" Font-Size="Smaller"></asp:TextBox>
<asp:RequiredFieldValidator ID="dateValidator" runat="server" ControlToValidate="tb_date" Font-Size="Smaller">*</asp:RequiredFieldValidator>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRow2" runat="server">
<asp:TableCell runat="server" align="left" Width= "100">
<asp:Button ID="addRow" runat="server" Height="22px" Text="Add Row"
ToolTip="Click to add another row" onclick="ButtonAddRow_Click" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRow3" runat="server">
<asp:TableCell runat="server" bordercolor="#FFFFFF"> </asp:TableCell>
<asp:TableCell runat="server" align="left" nowrap="nowrap" bordercolor="#FFFFFF">
<asp:Label ID="msg" runat="server" ForeColor="Red" Font-Size="Smaller"></asp:Label>
<asp:ValidationSummary ID="LogonValidationSummary" HeaderText="All the fields (*) are required." DisplayMode="SingleParagraph"
Font-Italic="true" ShowSummary="True" EnableClientScript="true" runat="server" Font-Size="Smaller"/>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRow4" runat="server">
<asp:TableCell ID="TableCell10" runat="server" bordercolor="#FFFFFF"> </asp:TableCell>
<asp:TableCell ID="TableCell11" runat="server" align="left" bordercolor="#FFFFFF">
<asp:Button ID="ButtonSubmit" runat="server" Height="22px" Text="Submit" Width="79px" onclick="ButtonSubmit_Click" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
</form>
</body>
</html>
This codes snippet is just a hint that you can do this way..
TableRow row = new TableRow();
for (int j = 0; j < colsCount; j++)
{
TableCell cell = new TableCell();
TextBox tb = new TextBox();
tb.ID = "TextBoxRow_" + i + "Col_" + j;
cell.Controls.Add(tb);
row.Cells.Add(cell);
}
Table1.Rows.Add(row);
I would like if you make use of GridView control and than add row runtime to gridview rather than using table. That would minize your effort also code.
here is code for you : Adding Dynamic Rows in GridView with TextBoxes
I have a data list control which is placed inside a content place holder.
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
<asp:ScriptManager ID="MainScriptManager" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DataList ID="dlProdocut" runat="server" RepeatColumns="3" EditItemIndex="-1"
RepeatDirection="Horizontal" OnItemDataBound="dlProdocut_ItemDataBound">
<ItemTemplate>
<asp:Table ID="Table1" runat="server" border="0" CellSpacing="0" CellPadding="0">
<asp:TableRow>
<asp:TableCell Height="10" HorizontalAlign="Center" VerticalAlign="Top">
</asp:TableCell>
</asp:TableRow>
<%--Image--%>
<asp:TableRow>
<asp:TableCell Height="150" Width="7" HorizontalAlign="left" VerticalAlign="top">
<asp:HyperLink ID="hyrProductImg" runat="server">
<img alt='<%# DataBinder.Eval(Container.DataItem,"Title")%>' src="../images/<%# DataBinder.Eval(Container.DataItem,"SmallImage") %>" border="0" width="226" height="166" />
</asp:HyperLink>
</asp:TableCell>
<asp:TableCell Width="5"> </asp:TableCell>
</asp:TableRow>
<%--Title--%>
<asp:TableRow>
<asp:TableCell Height="45" Width="7" CssClass="product-name" HorizontalAlign="Center"
VerticalAlign="Top">
<strong> <%# DataBinder.Eval(Container.DataItem, "Title")%></strong>
</asp:TableCell>
</asp:TableRow>
<%--ShortDescription--%>
<asp:TableRow>
<asp:TableCell Width="7" HorizontalAlign="Justify" VerticalAlign="Top" CssClass="testimonial-text">
<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ShortDescription")%>'></asp:Label>
</asp:TableCell>
</asp:TableRow>
<%--Read More--%>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Left">
<asp:HyperLink ID="lnkProductDetails" CssClass="read-more" runat="server">Read More →</asp:HyperLink>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell Height="60" HorizontalAlign="Justify" VerticalAlign="Top" CssClass="testimonial-text">
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="dlProdocut" />
<asp:AsyncPostBackTrigger ControlID="btnNext" />
</Triggers>
</asp:UpdatePanel>
<asp:Label ID="lblPage" runat="server" Text="" />
<asp:Button ID="btnPrevious" runat="server" Text="<<" />
<asp:Button ID="btnNext" runat="server" Text=">>" OnClick="btnNext_Click" />
<asp:Panel ID="BottomPager_Panel" runat="server">
</asp:Panel>
</asp:Content>
On click of next button i am doing paging on the control and navigating to the next page.
On page load i am doing this
if (!IsPostBack)
{
pageCount = 1;
PageNo = 1;
startPage = 6 * (PageNo - 1) + 1;
lastPage = startPage + 5;
bindDataList();
}
This is my code for bindDataList
public void bindDataList()
{
string source = ConfigurationManager.ConnectionStrings["Cad-B"].ToString();
SqlConnection con = new SqlConnection(source);
SqlCommand cmd = new SqlCommand("sp_GetProductPagingByMenuId", con);
//cmd.CommandType = CommandType.StoredProcedure;
//cmd.CommandText = "sp_GetProductPagingByMenuId";
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("#startPage", startPage);
cmd.Parameters.Add("#lastPage", lastPage);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
dlProdocut.DataSource = dt;
dlProdocut.DataBind();
}
On click of next button i have written the following code
protected void btnNext_Click(object sender, EventArgs e)
{
dlProdocut.DataSource = null;
dlProdocut.DataBind();
pageCount++;
PageNo = pageCount;
startPage = 6 * (PageNo - 1) + 1;
lastPage = startPage + 5;
bindDataList();
}
Problem i am facing is that it every time shows me the same content that is loaded the first time on the page. When i debug the code i can see that the data list is loaded with the new records but it is not reflected on the page i tried removing caching but it dint help. The moment i removed the next button from the trigger section it is giving me the proper record but the complete page is getting post back which i dont want. This is the removed code
<asp:AsyncPostBackTrigger ControlID="btnNext" />
Please help i am stuck with this since long. I am new to this technology. Thanks in advance.
Try :
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DatalistId$btnNext" />
</Triggers>