Archive for April, 2008

Cool CSS templates

Monday, 28 April, 2008 8 comments
Categories: CSS, HTML Tags: , ,

Large file uploads in ASP.NET

Monday, 28 April, 2008 4 comments

Large file uploads in ASP.NET

Uploading files via the FileUpload control gets tricky with big files. The default maximum filesize is 4MB – this is done to prevent denial of service attacks in which an attacker submitted one or more huge files which overwhelmed server resources. If a user uploads a file larger than 4MB, they’ll get an error message: “Maximum request length exceeded.”

Read more…

Categories: ASP.NET 2.0 Tags: , ,

Difference between Page.IsPostBack and Not page.IsPostBack.

Monday, 28 April, 2008 3 comments

Page.IsPostBack is for forms that are runat=”server”. It is mostly used for same page validation, same page operations, … anything really same page!

It is also used to help keep bandwidth and rendering times down.

The main reason why people use IsPostBack is to stop taping the databases everytime a request is made. If you are on your default page and just do work via that page, you can use the if Not page.ispostback then statements to populate information. When pages are posted back to the sever and then rendered back to the client, they don’t have the need to repopulate the information since it was just populated. It is all kept in the viewstate and read back without using precious resources on the server.

Read more…

Categories: ASP.NET 2.0 Tags:

[C#] Using the switch case Statement

Saturday, 26 April, 2008 1 comment

The switch statement chooses flow of control based on the evaluation of a
numeric or string comparison.The switch statement does not allow control to fall
through to the next case as in C/C++ unless the case statement is followed
immediately by another case statement. In other words, you must use a break statement
with every case statement.You can also use a goto statement, although most
programmers frown on using them. Here are two examples:

int j = 0;
int i = 1;
switch (i)
case 1:j = 7;break;
case 2:
case 3:j = 22;break;
default:j = 33; break;

string lastName = “”;
string text = “fred”;
switch ( text )
case “fred”:lastName = “Flinstone”;break;
case “barney”:lastName = “Rubble”;break;
default:lastName = “Slate”;break;

Categories: C# Tags: ,

Getting Visitor’s IP Address and Server’s IP Address

Thursday, 24 April, 2008 4 comments

Getting Visitors IP Address:

There are two ways, either by using:

The Following Line will get the IP Address of the machine instead of Proxy’s IP


Getting Server’s IP address:

string strHostName = Dns.GetHostName ();
IPHostEntry ipEntry = Dns.GetHostByName (strHostName);
IPAddress [ ] addr = ipEntry.AddressList;
for(int i=0;i< addr.Length;i++)
lblServerIP.Text=lblServerIP.Text+"The Server IP address is"+addr[i].ToString()+"\n";

Categories: ASP.NET 2.0, C# Tags: ,

Fill DropDownLists

Thursday, 24 April, 2008 Leave a comment

void FillDropDownLists()
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ASPGConnectionString"].ConnectionString);
SqlCommand commGetDept = new SqlCommand("select id, dept from s_dept where id in (select dept from s_users) order by dept", conn);
SqlDataReader res = commGetDept.ExecuteReader();
ListDepts.DataTextField = "dept";
ListDepts.DataValueField = "id";
ListDepts.DataSource = res;
ListDepts.Items.Insert(0, "Все");
catch (SqlException sqlex)
//ErrMess.Text = sqlex.Message;
if (conn.State != ConnectionState.Closed) conn.Close();

Get data from web.config

Thursday, 24 April, 2008 2 comments

Any data
<?xml version="1.0"?>
<add key="admins" value="esetov_b, lobanov_v"/>

string admins = ConfigurationManager.AppSettings["Admins"];

Connection String
<?xml version="1.0"?>
<add name="ASPGConnectionString" connectionString="Data Source=DS;Initial Catalog=basename;Persist Security Info=True;User ID=user;Password=psw"
providerName="System.Data.SqlClient" />

SqlConnection conn = new