ajax with datalist giving error - c#

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>

Related

Is it possible to refresh the whole page using an updateprogress?

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>

c# asp net updatepanel cause page refresh

I have a simple gridview with image button to update value of one of gridview column, by problem is whenever I click the image button it refresh the wholw page and I want the gridview only to be refreshed with updated value, I tried using UpdatePanel but it also refresh the whole page,
any help will be apprechiated.
aspx code:
<form id="form1" runat="server" >
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" CssClass="datatable" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" PageSize="5">
<Columns >
<asp:BoundField DataField="req_id" HeaderText="request ID" SortExpression="req_id" />
<asp:BoundField DataField="req subject" HeaderText="request subject" SortExpression="req_subject" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="Button_update" runat="server" CommandArgument='<%# Bind("req_id") %>' CssClass="yourCssClassIsNeedIt" ImageUrl="Images/under.png" OnClick="btn_under" UseSubmitBehavior="false" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</form>
aspx.cs code:
protected void Button_update(object sender, ImageClickEventArgs e)
{
using (SqlConnection sqlCon = new SqlConnection(#"Data Source= DESKTOP-U9437PU; initial Catalog = Mydb; Integrated Security =True;"))
{
sqlCon.Open();
string sql = "update requests_table set stat_id = '2' where req_id ='" 5 "'";
SqlCommand cmd1 = new SqlCommand(sql, sqlCon);
cmd1.ExecuteNonQuery();
cmd1.Dispose();
sqlCon.Close();
}
GridView1.DataBind();
}
You need to set UpdateMode Conditional:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button_update" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="GridView1" CssClass="datatable" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" PageSize="5">
<Columns >
<asp:BoundField DataField="req_id" HeaderText="request ID" SortExpression="req_id" />
<asp:BoundField DataField="req subject" HeaderText="request subject" SortExpression="req_subject" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="Button_update" runat="server" CommandArgument='<%# Bind("req_id") %>' CssClass="yourCssClassIsNeedIt" ImageUrl="Images/under.png" OnClick="btn_under" UseSubmitBehavior="false" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Then you should work call UpdatePanel1.Update(); as following:
protected void Button_update(object sender, ImageClickEventArgs e)
{
using (SqlConnection sqlCon = new SqlConnection(#"Data Source= DESKTOP-U9437PU; initial Catalog = Mydb; Integrated Security =True;"))
{
sqlCon.Open();
string sql = "update requests_table set stat_id = '2' where req_id ='" 5 "'";
SqlCommand cmd1 = new SqlCommand(sql, sqlCon);
cmd1.ExecuteNonQuery();
cmd1.Dispose();
sqlCon.Close();
}
GridView1.DataBind();
UpdatePanel1.Update();
}
Try this:
<asp:ImageButton ID="Button_update" runat="server" CommandArgument='<%# Bind("req_id") %>' CssClass="yourCssClassIsNeedIt" ImageUrl="Images/under.png" OnClick="btn_under" UseSubmitBehavior="false" OnClientClick="javascript:void(0);" />
And this
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">

some dynamic dropdownlists don't update -- autopostback = true

I have a web page that has developed an issue with only some of the dropdownlists. As indicated autopostback = true and yes I'm accounting for the !postback.
Line of Business, Director and Agent all post back without issue but the Senior Manager and Manager postback with the first value on the list regardless of selection.
here is the asp
<asp:TableRow>
<asp:TableCell CssClass="tc1" Width="17%">
<asp:Label ID="lblLob" runat="server">Line Of Business: </asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="tc1">
<asp:DropDownList ID="cmbLoB" runat="server" AutoPostBack="true" OnSelectedIndexChanged="reSelect"></asp:DropDownList>
<asp:RequiredFieldValidator ID="rfvLoB" runat="server" ControlToValidate="cmbLoB" InitialValue="0" ErrorMessage="Please select a Line of Business"></asp:RequiredFieldValidator>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ID="tcRange" CssClass="tc1" runat="server" Width="15%">
<asp:Label ID="lblDateRange" runat="server">Report Range: </asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="tc1">
<asp:DropDownList ID="cmbDateRange" runat="server" AutoPostBack="true" OnSelectedIndexChanged="reSelect"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell CssClass="tc1"><asp:Label ID="lblStartDate" runat="server" Text="Start Date: "></asp:Label></asp:TableCell>
<asp:TableCell CssClass="tc2"><asp:TextBox ID="txtStartDate" runat="server" AutoPostBack="true"></asp:TextBox><asp:CalendarExtender
ID="calStartDate" runat="server" TargetControlID="txtStartDate" Format="yyyy-MM-dd">
</asp:CalendarExtender>
</asp:TableCell>
<asp:TableCell CssClass="tc1"><asp:Label ID="lblEndDate" runat="server" Text="End Date: "></asp:Label></asp:TableCell>
<asp:TableCell CssClass="tc2"><asp:TextBox ID="txtEndDate" runat="server" AutoPostBack="true"></asp:TextBox><asp:CalendarExtender
ID="calEndDate" runat="server" TargetControlID="txtEndDate" Format="yyyy-MM-dd"></asp:CalendarExtender>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell CssClass="tc1" Width="17%">
<asp:Label ID="lblDirector" runat="server">Senior Leader: </asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="tc1">
<asp:DropDownList ID="cmbDirector" runat="server" AutoPostBack="true" OnSelectedIndexChanged="reSelect"></asp:DropDownList>
</asp:TableCell>
<asp:TableCell CssClass="tc1" Width="17%" ID="tdlblAggregate" runat="server" Visible="false">
<asp:Label ID="lblAggregate" runat="server">Aggregation Level: </asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="tc1" ID="tdcmbAggregate" runat="server" Visible="false">
<asp:DropDownList ID="cmbAggregate" runat="server" AutoPostBack="true" OnSelectedIndexChanged="reSelect">
<asp:ListItem Value="LoB" Text="Segment"></asp:ListItem>
<asp:ListItem Value="SM" Text="Senior Manager"></asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell CssClass="tc1">
<asp:Label ID="lblSManager" Visible="true" runat="server">Senior Manager: </asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="tc1">
<asp:DropDownList ID="cmbSManager" runat="server" AutoPostBack="true" OnSelectedIndexChanged="reSelect"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell CssClass="tc1">
<asp:Label ID="lblManager" Visible="true" runat="server">Manager: </asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="tc1">
<asp:DropDownList ID="cmbManager" runat="server" AutoPostBack="true" OnSelectedIndexChanged="reSelect"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell CssClass="tc1">
<asp:Label ID="lblAgent" Visible="true" runat="server">Associate/Specialist: </asp:Label>
</asp:TableCell>
<asp:TableCell CssClass="tc1">
<asp:DropDownList ID="cmbAgent" runat="server" AutoPostBack="true" Visible="true" OnSelectedIndexChanged="reSelect"></asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
And the code behind:
DataTable SLTSelectDistinct = SLTSelect.DefaultView.ToTable(true, "sltID", "sltName");
DataView sltSelect = new DataView(SLTSelectDistinct);
DataRow sltRow = SLTSelectDistinct.NewRow();
sltRow[0] = "0";
sltRow[1] = "-- Please Select --";
SLTSelectDistinct.Rows.Add(sltRow);
sltSelect.Sort = "sltName";
cmbDirector.DataValueField = "sltID";
cmbDirector.DataTextField = "sltName";
cmbDirector.DataSource = sltSelect;
cmbDirector.DataBind();
DataTable SMSelectDistinct = SMSelect.DefaultView.ToTable(true, "smID", "smName");
DataView smSelect = new DataView(SMSelectDistinct);
DataRow smRow = SMSelectDistinct.NewRow();
smRow[0] = "0";
smRow[1] = "-- Please Select --";
SMSelectDistinct.Rows.Add(smRow);
smSelect.Sort = "smName";
cmbSManager.DataValueField = "smID";
cmbSManager.DataTextField = "smName";
cmbSManager.DataSource = smSelect;
cmbSManager.DataBind();
DataTable MSelectDistinct = MSelect.DefaultView.ToTable(true, "mID", "mName");
DataView mSelect = new DataView(MSelectDistinct);
DataRow mRow = MSelectDistinct.NewRow();
mRow[0] = "0";
mRow[1] = "-- Please Select --";
MSelectDistinct.Rows.Add(mRow);
mSelect.Sort = "mName";
cmbManager.DataValueField = "mID";
cmbManager.DataTextField = "mName";
cmbManager.DataSource = mSelect;
cmbManager.DataBind();
DataTable ASelectDistinct = LoBSelect.DefaultView.ToTable(true, "C_AGT", "aName");
DataView aSelect = new DataView(ASelectDistinct);
DataRow aRow = ASelectDistinct.NewRow();
aRow[0] = "0";
aRow[1] = "-- Please Select --";
ASelectDistinct.Rows.Add(aRow);
aSelect.Sort = "aName";
cmbAgent.DataValueField = "C_AGT";
cmbAgent.DataTextField = "aName";
cmbAgent.DataSource = aSelect;
cmbAgent.DataBind();
It is probably that you have 0 as the value of one of your actual options as well so when the page refreshes the selected value of the dropdown is 0 which also happens to be the value of the default "Select One" option.

ASP.NET manually update updatepanel to show feedback in long function

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!]

Add rows of textboxes with a click of a button

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

Categories

Resources