Tuesday, April 20, 2010

How to Edit Detailsview in asp.net aplplication

Using template Field you can edit datalist


Check the refrence link

System.Web.HttpException: Request timed out

Summery

executionTimeout
parameter- indicates the maximum number of seconds that a request is allowed to execute before being automatically shut down by ASP.NET.

By default, the value of the executionTimeout attribute is set to 90 seconds in theMachine.config file. “Request timed out” error occurs when the processing time of request exceeds 90 seconds. In most cases an error occurs when you are uploading large files.

Solution

To work around this problem, increase the time-out value of request execution.

You can do that by following two ways:

Method 1:
EAUpload component provides a replacement of executionTimeout attribute of httpRuntime config section. If ExecutionTimeout parameter of EAUpload environment is defined then request have time-out that is specified by this parameter and"executionTimeout" parameter of httpRuntime configuration section is ignored. The specified value will take effect only for requests which are processed by EAUpload component. The value that is specified in executionTimeout attribute will be actually for other requests.

Set the ExecutionTimeout parameter value in the EAUpload configuration

  • Open the Web.config file in Notepad.
  • Increase the value of the ExecutionTimeout attribute to avoid time-out errors.
    "1.0" encoding="utf-8" ?>  ...            "3600"                     ...        />              ...       
  • Save the Web.config file.

Method 2:
The executionTimeout attribute exists under httpRequest in the Machine.config file. You can change these settings either in the Web.Config file or in the Machine.config file. The default value for the time-out is 90 seconds. The executionTimeout attribute indicates the maximum number of seconds a request is permitted to run before being shut down by the ASP.NET Web application.

Figure A: Set the executionTimeout attribute value in the Web.config File

  • Open the Web.config file in Notepad.
  • Add the httpRuntime element in the system.web section as follows:
    "1.0" encoding="utf-8" ?>  ...      "90" maxRequestLength="4096" 	useFullyQualifiedRedirectUrl="false" 	minFreeThreads="8" 	minLocalRequestFreeThreads="4" 	appRequestQueueLimit="100" />   ...   
  • Increase the value of the executionTimeout attribute to avoid time-out errors.
  • Save the Web.config file.


Figure B: the executionTimeout attribute value in the Machine.config File
  • Open the Machine.config file in Notepad. The Machine.config file is located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ directory.
  • In the Machine.config file, locate the httpRuntime element.
    "90" maxRequestLength="4096" 	useFullyQualifiedRedirectUrl="false" 	minFreeThreads="8" 	minLocalRequestFreeThreads="4" 	appRequestQueueLimit="100" /> 
  • Increase the value of the executionTimeout attribute to avoid time-out errors.
  • Save the Web.config file.

References:

AjaxToolkit: AutoCompleteExtender

<%@ Register Assembly="AjaxControlToolkit"Namespace="AjaxControlToolkit" tagprefix="ajaxToolkit"%>

Which says that the reference assembly "AjaxControlToolkit.dll" should be registered on the page by using above method. We should also have tagprefix="ajaxToolkit" which is similar to .

In this article I have very simple database table called as "Tbl_Countries" with fields as:

CountryId int primary key,
CountryName varchar(50)

I am using a web service called as "AutoComplete.asmx" whose code behind gets automatically added to the "App_Code" folder.

Note: Very important part is you need to give a reference of "AjaxControlToolkit.dll".

Here is complete code for "AutoComplete.asms.cs".

using System;

using System.Web;

using System.Collections;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Data;

using System.Data.SqlClient;

using System.Configuration;

///

/// Summary description for AutoComplete

///

[WebService(Namespace = "http://tempuri.org/")]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService]

public class AutoComplete : System.Web.Services.WebService

{

[WebMethod]

public string[] GetCountriesList(string prefixText)

{

DataSet dtst = new DataSet();

SqlConnection sqlCon = newSqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);

string strSql = "SELECT CountryName FROM Tbl_Countries WHERE CountryName LIKE '" + prefixText + "%' ";

SqlCommand sqlComd = new SqlCommand(strSql, sqlCon);

sqlCon.Open();

SqlDataAdapter sqlAdpt = new SqlDataAdapter();

sqlAdpt.SelectCommand = sqlComd;

sqlAdpt.Fill(dtst);

string[] cntName = new string[dtst.Tables[0].Rows.Count];

int i = 0;

try

{

foreach (DataRow rdr in dtst.Tables[0].Rows)

{

cntName.SetValue(rdr["CountryName"].ToString(), i);

i++;

}

}

catch { }

finally

{

sqlCon.Close();

}

return cntName;

}

}

Let us take another page called as "default.aspx" in which I am having a tag and in which a tag in which you can specify path of webservices. You have already registered Assembly="AjaxControlToolkit" on this page so you can use that.


So my entire code will look something like this

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" tagprefix="ajaxToolkit"%>

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 id="Head1" runat="server">

<title>Untitled Pagetitle>

head>

<body>

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server">

<Services>

<asp:ServiceReference Path="AutoComplete.asmx" />

Services>

asp:ScriptManager>

<div>

<asp:TextBox ID="txtCountry" runat="server">asp:TextBox>

<ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="txtCountry"ServicePath="AutoComplete.asmx" ServiceMethod="GetCountriesList" MinimumPrefixLength="1" EnableCaching="true" />

div>

form>

body>

html>

Following snapshot gives you clear idea as how the AutoCompleteExtender works.

Monday, April 12, 2010

http to https redirect in asp.net

write code on page load event

if(!Request.IsSecureConnection)

{

string redirectUrl = Request.Url.ToString().Replace("http:", "https:");
Response.Redirect(redirectUrl);

}