Archive

Posts Tagged ‘Asp.net’

Using Jquery, Json with Asp.net

Using Asp.net Ajax Update Progress

March 22, 2010 1 comment

Here in this article, we will learn how to use updateprogress control that comes asp.net ajax toolkit.

<asp:ScriptManager ID=”scriptManager” runat=”server” />

<asp:UpdatePanel ID=”UdpLogin” runat=”server”>
<ContentTemplate>

<div>

Content comes here…

</div>
</ContentTemplate>
</asp:UpdatePanel>

<asp:Panel ID=”UpdateProgress” runat=”server” CssClass=”ProgressContent” Width=”100%”
Height=”100%”>
<asp:UpdateProgress ID=”UpdateProg” runat=”server” DisplayAfter=”1″ AssociatedUpdatePanelID=”UdpLogin”>
<ProgressTemplate>
<asp:Panel ID=”UpdatePro” runat=”server” CssClass=”Trans” Width=”100%” Height=”100%”>
<table width=”100%” height=”100%”>
<tr>
<td align=”center” valign=”middle” width=”100%” height=”100%”>
<asp:Image ID=”imgProg” runat=”server” ImageUrl=”~/img/loading.gif” AlternateText=”Updating ……”
ImageAlign=”Middle” />
</td>
</tr>
</table>
</asp:Panel>
</ProgressTemplate>
</asp:UpdateProgress>
</asp:Panel>

Css Styles to include here are as follows:

/* StyleSheet for Update Progress */
.ProgressContent
{
font-family: verdana;
font-size: 11px;
color: #000000;
font-weight: normal;
text-decoration: none;
}

.Trans
{
background-color: White;
filter: alpha(opacity=70);
opacity: 0.7;
position: absolute;
left: 0px;
top: 0px;
}
.Progress
{
font-family: verdana;
font-size: x-small;
color: Green;
font-weight: bold;
text-decoration: none;
height: auto;
}

Please visit my previous article for downloading loading images:

https://pankajlalwani.wordpress.com/2009/05/30/download-ajax-loading-image/

Read/Write Section from/into Web.config in Asp.net

Many times, we need to read sections from web.config or write into web.config.

I have a requirement where i need to write an section in web.config that points to another config file.

Below is the code where “abc” is the section

Configuration objConfig = WebConfigurationManager.OpenWebConfiguration(“~”);
ConfigurationSection section = objConfig.Sections[“abc”];
string str = “abcdef”;
section.SectionInformation.SetRawXml(str);
objConfig.Save();

The above code will read “abc” section and write the content in str.

For Reading Appsettings from web.config, below is the code

Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); AppSettingsSection appSettings = (AppSettingsSection) config.GetSection(appSettings);

string[] appKeys = appSettings.Settings.AllKeys;

for (int i = 0; i < appSettings.Settings.Count; i++)

{

Response.Write(appSettings.Settings[appKeys[i]].Value);

Response.Write(“<BR>”);

}

Using Dataview RowFilter (Syntax) in Asp.net C#

February 8, 2010 1 comment

Lets say we have a datatable, we want to select rows that meet certain criteria, then we can use Dataview.Rowfilter.

For example we have a datatable having empid column, we want the row whose empid is 8.

dataView.RowFilter = "empid = 8";

Other examples are
dataView.RowFilter = "EmpName = 'Pankaj'" ;
dataView.RowFilter = "Date = #12/08/2000#" ;

Comparision
dataView.RowFilter = "Date>=" + "#" + startdate + "#" +
"And Date <=" + "#" + enddate + "#";
You can find other examples at:
http://www.csharp-examples.net/dataview-rowfilter/

Validator Enable/Disable in Asp.net using Javascript

February 3, 2010 Leave a comment

You can enable/disable validators using javascript as follows:

ValidatorEnable(document.getElementById(‘<%= rfv.ClientID %>’), false);

First argument is id of validator, second argument is to enable pass “true”, else pass “false”.

Export To Excel Inside An Update Panel in Asp.net

January 27, 2010 2 comments

When using export to excel inside update panel, it will popup an error like “pagerequestmanagerparsererrorexception” .

The actual problem is with Response.write, as it tries to update only certain part of the page asynchronously.

This can be solved in following ways:

1) Adding trigger :

<Triggers>
<asp:PostBackTrigger ControlID=”btn_ExpertToExcel” />
</Triggers>

2) Placing button outside the update panel



Refresh Content in UpdatePanel using Asp.net Ajax Timer Control

January 19, 2010 1 comment

Lets say we have a requirement where we have a label control and we have assigned date time to its text, and in every 5 seconds we want to update the time, over there we need to place the label control inside the update panel and use a timer control to update its content.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Update Panel and Timer</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:Timer runat="server" id="UpdateTimer" interval="5000"
          ontick="UpdateTimer_Tick" />
        <asp:UpdatePanel runat="server" id="TimedPanel" updatemode="Conditional">
            <Triggers>
                <asp:AsyncPostBackTrigger controlid="UpdateTimer"
                  eventname="Tick" />
            </Triggers>
            <ContentTemplate>
                <asp:Label runat="server" id="lbldatetime" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>

In the codebehind:

protected void UpdateTimer_Tick(object sender, EventArgs e)
{  
lbldatetime.Text = DateTime.Now.ToString();
}