Load Drop Down List using Javascript


Tags: Loading dropdownlist, Loading dropdownlist using javascript

About LINQ TO SQL


LINQ TO SQL

Linq-To-SQL is the lightweight, straightforward, MS-SQL Server only technology

Advantages: 
  •  Reduction in work, Faster development               
  •  Strongly typed code (Type Safety).
  • A common syntax for all data.
  • Compile check when database changes
  • Auto-generated domain objects that are usable small projects
  • Lazy loading feature can speed up performance & at least simplify the code a lot.
  • Debugging support 
Disadvantages: 
  • Support for SQL Server only
  • No direct execution against database
  •  Not suitable for handling large amount of data, like filling dataset.

Performance
: 

Tags: Advantages of linq to sql, limitations linq to sql, linq to sql performance, about linq to sql


Exception Handling in Global.asax, Application_Error

Some of the Limitations of Exception Handling in Global.asax (Application_Error)

  • An error handler that is defined in the Global.asax file will only catch errors that occur during processing of requests by the ASP.NET runtime. For example, it will catch the error if a user requests an .aspx file that does not occur in your application. However, it does not catch the error if a user requests a nonexistent .htm file. For non-ASP.NET errors, you can create a custom handler in Internet Information Services (IIS). The custom handler will also not be called for server-level errors. 
  • You cannot directly output error information for requests from the Global.asax file; you must transfer control to another page, typically a Web Forms page. When transferring control to another page, use Transfer method. This preserves the current context so that you can get error information from the GetLastError method.
  •  Application_Error never fires for a web service.
  • Application_Error will catch parser, compilation, and run-time errors within pages. It will not catch configuration issues, nor will it catch errors that occur within inetinfo while aspnet_isapi processes the request.

One of the biggest advantages of Exception Handling in Global.asax (Application_Error)
  •     Good in Performance

How to convert image into byte 64 and byte 64 into image ?

protected void Page_Load(object sender, EventArgs e)
{
string get64 = ImageToBase64(Image.FromFile("C:\\bold.gif"), System.Drawing.Imaging.ImageFormat.Gif) ;

Base64ToImage(get64);

}


public string ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format)
{
using (MemoryStream ms = new MemoryStream())
{
// Convert Image to byte[]

image.Save(ms, format);
byte[] imageBytes = ms.ToArray();

// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
}


public Image Base64ToImage(string base64String)
{
// Convert Base64 String to byte[]
byte[] imageBytes = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(imageBytes, 0,
imageBytes.Length);

// Convert byte[] to Image
ms.Write(imageBytes, 0, imageBytes.Length);
Image image = Image.FromStream(ms, true);
image.Save("C:\\Test\\Bold1.png");
return image;
}

How to Encrypt Connection string in web.config asp.net ??

The most sensitive information stored in web.config file can be the connection string. You do not want to disclose the information related to your database to all the users where the application is deployed. Every time it is not possible to have a private machine for your sites, you may need to deploy the site in shared host environment. To encrypt the connection string in above situation is advisable.

ASP.NET 2.0 provides in built functionality to encrypt few sections of web.config file. The task can be completed using Aspnet_regiis.exe. Below is the web.config file and section.
   1: 
   2:   "cn1" 
   3:           connectionString="Server=DB SERVER;
   4:                             database=TestDatabase;
   5:                             uid=UID;
   6:                             pwd=PWD;" />
   7:  
Fig – (1) Connection string section of web.config file
To encrypt the connection string section follow the steps,
1. Go to Start -> Programm Files -> Microsoft Visual Studio 2005 -> Visual Tools

-> Microsoft Visual Studio 2005 Command Prompt
2. Type following command,
aspnet_regiis.exe -pef “connectionStrings” C:\Projects\DemoApplication
-pef indicates that the application is built as File System website. The second argument is the name of configuration section needs to be encrypted. Third argument is the physical path where the web.config file is located.
If you are using IIS base web site the command will be,
aspnet_regiis.exe -pe “connectionStrings” -app “/DemoApplication”
-pe indicates that the application is built as IIS based site. The second argument is the name of configuration section needs to be encrypted. Third argument “-app” indicates virtual directory and last argument is the name of virtual directory where application is deployed.
If everything goes well you will receive a message “Encrypting configuration section…Succeeded!”
Open your web.config file and you can see that connection string is encrypted,
   1: "RsaProtectedConfigurationProvider">
   2:   "http://www.w3.org/2001/04/xmlenc#Element"
   3:    xmlns="http://www.w3.org/2001/04/xmlenc#">
   4:    "http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
   5:    "http://www.w3.org/2000/09/xmldsig#">
   6:     "http://www.w3.org/2001/04/xmlenc#">
   7:      "http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
   8:      "http://www.w3.org/2000/09/xmldsig#">
   9:       Rsa Key
  10:      
  11:      
  12:       Ik+l105qm6WIIQgS9LsnF8RRxQtj2ChEwq7DbHapb440GynFEoGF6Y3EM3Iw/lyDV8+P8bIsketi5Ofy9gpZlCBir7n315Q6RPbdclUo79o/LKadhX4jHFpnSIQNIF/LhwjwkLFC0=
  13:      
  14:     
  15:    
  16:    
  17:     JsLrQ5S8Pq3U72nQzmSl/XlLX72GM0O3EbPLaHRNvjTDgG9seDflGMjTfO10M1s7/mPh//3MhA7pr0dNHUJ143Svhu5YXODRC6z9CkR0uyE4H7uDvTKJ8eR3m9APhXoo1sT1K3tCLHD6a2BM+gqSk9d8PzCfbM8Gmzmpjz1ElIaxu62b4cg9SNxp8o86O9N3fBl2mq
  18:    
  19:   
  20:  
Fig – (2) Encrypted connection string section
You do not have to write any code to decrypt this connection string in your application, dotnet automatically decrypts it. So if you write following code you can see plaintext connection string.
   1: Response.Write(ConfigurationManager.ConnectionStrings["cn1"].ConnectionString);
Now to decrypt the configuration section in web.config file use following command,
For File System Application,
aspnet_regiis.exe -pdf “connectionStrings” C:\Projects\DemoApplication
For IIS based Application
aspnet_regiis.exe -pd “connectionStrings” -app “/DemoApplication”
If you want to encrypt any nested section in web.config file like element within you need to write full section name as shown below,
aspnet_regiis.exe -pef “system.web/Pages” C:\Projects\DemoApplication
You can encrypt all the sections of web.config file except following using the method I displayed in this article,


















To encrypt these section you needed to use Aspnet_setreg.exe tool. For more detail about Aspnet_setreg.exe tool search Microsoft Knowledge Base article 329290, How to use the ASP.NET utility to encrypt credentials and session state connection strings.
Happy Programming !!!


- Thanks to chiragrdarji.wordpress

Call web method using jquery asp.net

Call web method using jquery asp.net ajax:

function SearchInterventionQuestions() {
$("#divSearchInterventionQuestions").html('');
//debugger;
//var welcomePageURL = document.getElementById("hdnCreateSurveyQuestionsURL");
var createInterventionQuestionsURL = "../Modules/WebForms/InterventionExercise/CreateHappinessExercise.aspx";
var searchText = $("#txtSearchInterventionQuestion")[0].value;
$.ajax({
type: "POST",
url: createInterventionQuestionsURL + "/SearchInterventionQuestion",
data: '{question: "' + searchText + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSearchInterventionQuestionsSuccess,
failure: function (response) {
alert(response);
}
});
return false;
}

function OnSearchInterventionQuestionsSuccess(response) {
$("#divSearchInterventionQuestions").html(response.d);
return false;
}

Removing Shared Folders - IT Security Guidelines - IT Security - Trinity College Dublin

Remove Shared Folders

Perform the following steps to remove shared folders which you no longer use.

Windows 2000/XP :

  1. Right click My Computer -> Select 'Manage'.

  2. Choose 'Shared Folders'.

  3. On the list expand shared folders and select the 'Shares' folder.

  4. To disable any share you are not using right click on the shared folder and choose 'Stop Sharing' as in the image below.

stop file sharing

Remember - Ignore the shares with '$' after them these are default administration shares and are required.


Thanks to tcd.ie

Merge GridView Cells Or Columns in Row ASP.NET C#

Merge GridView Cells Or Columns in Row ASP.NET C#

In most of the cases specially for reporting purpose we need to merge GridView cells or columns for client preferred output. In this example i will show you how one can merge GridView cells or columns in asp.net C#. My special focus is on to merge cells when both contains same or equal data. So that the GridView looks like a traditional report.

///////////////////////////////////////////////////////

using System;
using System.Web.UI.WebControls;

public class clsUIUtility
{
public clsUIUtility()
{
}

public static void GridView_Row_Merger(GridView gridView)
{
for (int rowIndex = gridView.Rows.Count - 2; rowIndex >= 0; rowIndex--)
{
GridViewRow currentRow = gridView.Rows[rowIndex];
GridViewRow previousRow = gridView.Rows[rowIndex + 1];

for (int i = 0; i < currentRow.Cells.Count; i++)
{
if (currentRow.Cells[i].Text == previousRow.Cells[i].Text)
{
if (previousRow.Cells[i].RowSpan < 2)
currentRow.Cells[i].RowSpan = 2;
else
currentRow.Cells[i].RowSpan = previousRow.Cells[i].RowSpan + 1;
previousRow.Cells[i].Visible = false;
}
}
}
}
}

////////////////////////////////////////////

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





How to merge GridView cell or Column









       
       
       
       
           
           
           
       

       
   





///////////////////////////////////////////

< Hope now you can merge all of your GridView Cells Or Columns in Row using ASP.NET C# within your project by writing a single line. Just call the clsUIUtility.GridView_Row_Merger method and send the GridView that you want to merge for all applicable Gridviews in your project.

There is a lot of scope to modify the generic method if GridView rows contain controls like DropDwonList, CheckBoxList, RadioButtonList etc. in a template column.

How to display loading GIF Image In JQuery AJAX in ASP.NET

Introduction

Today’s JQuery is most powerful library for web development GUI customization. Hence I would write another great article about how to display the wait or loading GIF using JQuery with when you are call AJAX Load method. Let’s say you have to load list of state based on your selected country. In this scenario, we can use the AJAX Load with div element.

Now, let say we have to show the loading gif one we are select the country, then AJAX load has request to get the states content from the database. Here is followings steps will be happen internally

1. Something triggers AJAX request (select a country).
2. We put the loading image that asks for user patience to the place where we would later insert the loaded list of state list in the html element (div).
3. After remote content is fully loaded, the content will replace earlier div html by this new content.

Note: before start the demonstration, you have to download JQuery library from jquery.com or you can point the Google JQuery API URL as well.


Now, design the page for load state list, when we select a country.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CountryDemo.aspx.cs" Inherits="WebApplication1.CountryDemo" %>


Note:I have used JQuery library from Google API.

What are the advantages of use Google JQuery URL ?

Here whole details for this question.

Now let’s write JavaScript code with JQuery library to load state once we select the a country









Through the above code ,when we are select a country, then change event will raise and send country ID to server page1.aspx.Within the page1.aspx, will compose the state list as html format, finally will write as response to client. But here now you can’t see any loading or wait GIF image when you are select a country from country dropdown list.


Let’s see, how to implement that, just an additional line we have to add within above script.


In above code, i have added only this line to load GIF.

$('#mainContent').empty().html('');
Once change event raised, GIF loading image wild add into div inner content, Once content from loaded from the server page, then .load() function would replace our loading image indicator with the loaded content.The $('#mainContent').empty() will clear inner html of the div,and then when we are call $('#mainContent').empty().html() method will add new element inside the div.

Conclusion

here I have not give the sample project with article. because I have given core part of the implementation with this article. So I hope you able to catch and enjoy.

Play the Anna Game... Support LokPal

Steve Jobs resigns as Apple CEO

Tim Cook Named CEO and Jobs Elected Chairman of the Board






Apple’s Board of Directors today announced that Steve Jobs has resigned as Chief Executive Officer, and the Board has named Tim Cook, previously Apple’s Chief Operating Officer, as the company’s new CEO. Jobs has been elected Chairman of the Board and Cook will join the Board, effective immediately.
“Steve’s extraordinary vision and leadership saved Apple and guided it to its position as the world’s most innovative and valuable technology company,” said Art Levinson, Chairman of Genentech, on behalf of Apple's Board. “Steve has made countless contributions to Apple’s success, and he has attracted and inspired Apple’s immensely creative employees and world class executive team. In his new role as Chairman of the Board, Steve will continue to serve Apple with his unique insights, creativity and inspiration.”
“The Board has complete confidence that Tim is the right person to be our next CEO,” added Levinson. “Tim’s 13 years of service to Apple have been marked by outstanding performance, and he has demonstrated remarkable talent and sound judgment in everything he does.”
Jobs submitted his resignation to the Board today and strongly recommended that the Board implement its succession plan and name Tim Cook as CEO.
As COO, Cook was previously responsible for all of the company’s worldwide sales and operations, including end-to-end management of Apple’s supply chain, sales activities, and service and support in all markets and countries. He also headed Apple’s Macintosh division and played a key role in the continued development of strategic reseller and supplier relationships, ensuring flexibility in response to an increasingly demanding marketplace.


Apple designs Macs, the best personal computers in the world, along with OS X, iLife, iWork and professional software. Apple leads the digital music revolution with its iPods and iTunes online store. Apple has reinvented the mobile phone with its revolutionary iPhone and App Store, and has recently introduced iPad 2 which is defining the future of mobile media and computing devices.
 
 
-- From Apple

Calculate age using MySQL


Calculate age using MySQL

SELECT DATE_FORMAT(FROM_DAYS(DATEDIFF(NOW(),”1978-03-28″)), ‘%Y’)+0 AS age

1:- DATEDIFF(NOW(),”1978-03-28″)
This function DATEDIFF() returns difference of two dates in days, e.g. DATEDIFF(“1978-04-28″, “1978-03-28″) will return 31 days. So by using NOW() i.e. current date, in the above query, we get, say, 10744 days.

2:- FROM_DAYS(10744)
retuns the date starting from 0000-00-00 i.e. since year 0… so this function outputs “0029-06-01″, i.e. the difference between two dates “1978-03-28″ & “2008-08-27″ is precisely 29 years, 6 months & 1 day. We need just years, so we use

3:- DATE_FORMAT(“0029-06-01″, %Y) +0
and it returns us 29 as an integer value.


SELECT DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(“1978-03-28″)), ‘%Y’)+0 AS age

1:- TO_DAYS(“1978-03-28″)
The only new function in this query is TO_DAYS(date), which converts our date to number of days starting from year 0 i.e. the opposite of function FROM_DAYS(days). So this gives us 722536 days. The other function TO_DAYS(NOW()) returns us 733280 days (for 2007-08-27). Subtracting the two, we get 733280 – 722536 = 10744 days. From here on, we move on to step 2 in the above scenario.


SELECT EXTRACT(YEAR FROM (FROM_DAYS(DATEDIFF(NOW(),”1978-03-28″))))+0 AS age

1:- EXTRACT(YEAR FROM “0029-06-01″) +0
Taking the queue from step 2 in the first scenario, FROM_DAYS(10744) we apply another function. EXTRACT(date) which extracts a part from the given date as per the format, here YEAR, and it returns us 29 as an integer value.

This last query using EXTRACT() method is a bit slower than the one using DATE_FORMAT() – (.0001 sec). All these queries return the age in y

MySQL Select NULL

MySQL Select NULL


How to select rows from MySQL table where certain field is empty is a problem i stuggled against for a while like … 10 minutes or so, while solution is quite simple. Remember that it will work with MySQL this solution was not tested with other databases and as far as i am concerned it does not work with Sybase.


SELECT * FROM `table` WHERE `field1` IS NULL
There is also variations for this:


SELECT * FROM `table` WHERE ISNULL(`field1`)
While browsing MySQL documentation i found one more interesting function IFNULL(expr1, expr2). What it basically do is: if expr1 is NULL then it returns expr2 else it returns expr1. Here is a sample usage:


mysql> SELECT IFNULL(1,0);
-> 1
mysql> SELECT IFNULL(NULL,10);
-> 10
mysql> SELECT IFNULL(1/0,10);
-> 10
mysql> SELECT IFNULL(1/0,'yes');
-> 'yes'
That’s it for now, i hope you will find it helpful.

Text Area (or) TextBox Maxlength doest not work when TextMode is set to Multiline


TextArea TextBox Maxlength doest not work when TextMode is set to Multiline

Hi,
This is known issue in ASP.NET Standard Text box control when set its TextMode="MultiLine" the MaxLength property does not work.
There is a workaround to accomplish this using RegularExpressionValidator. Following is the markup that will restrict the text box to maximum of 500 characters.

<asp:TextBox ID="txtComments" runat="server" TextMode="MultiLine" Height="100px"
Width="320px" MaxLength="10">asp:TextBox> <asp:RegularExpressionValidator
ID="regComments" runat="server" ControlToValidate="txtComments"
ValidationExpression="^[\s\S]{0,500}$" ErrorMessage="Maximum 500 characters are allowed in comments box." Text="Maximum 500 characters are allowed in comments
box." > asp:RegularExpressionValidator

MySQL: Solution for ERROR 1442 (HY000): Can’t update table ‘t1′ in stored function/trigger because it is already used by statement which invoked this stored function/trigger.


MySQL: Solution for ERROR 1442 (HY000): Can’t update table ‘t1′ in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
Posted in CentOS, Enterprise level solutions, Linux Apache MySQL PHP, MySQL, MySQL Triggers on

Here is a sample table you can create to test following problem/solution on:

CREATE TABLE `t1` (
`a` char(1) default NULL,
`b` smallint(6) default NULL
);
insert into t1 values ('y','1');

I have a table t1 which has column a and b, I want column a to be updated to ‘n’ when column b = 0. Here is the first version I created:

DELIMITER |
CREATE TRIGGER trigger1 AFTER UPDATE ON t1
FOR EACH ROW UPDATE t1 SET a= 'n' WHERE b=0;
|
DELIMITER ;

The trigger created successfully but I got this error when I tried to do an update on column b on table t1:
mysql> update t1 set b=0;
ERROR 1442 (HY000): Can't update table 't1' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.

After searching online for a while and trying different solutions, I finally found a way to update the table which has trigger on it:

drop trigger trigger1;
DELIMITER |
CREATE TRIGGER trigger1 BEFORE UPDATE ON t1
FOR EACH ROW
BEGIN
IF NEW.b=0 THEN
SET NEW.a = 'n';
END IF;
END
|
DELIMITER ;

After the new trigger is in, I issued the same update query and “ERROR 1442 (HY000): Can’t update table ‘t1′ in stored function/trigger because it is already used by statement which invoked this stored function/trigger.” didn’t show up and it updated the col a value to “n” as it suppose to.

mysql> update t1 set b=0;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from t1\G
*************************** 1. row ***************************
a: n
b: 0

Therefore, if you want to create a trigger on the table which will update itself, make sure you use the NEW.column_name to refer to the row after it’s updated and don’t do the full update statement!

However, if you are updating some other table, then you can use the regular update statement:

DELIMITER |
CREATE TRIGGER trigger1 AFTER UPDATE ON t1
FOR EACH ROW UPDATE t2 SET a= 'n' WHERE b=0;
|
DELIMITER ;

————————————-
DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. Use at your own risk.

Shared in googledotnet by Manivannan N

How to get a resource file value dynamically ?

How to get a resource file value dynamically ?

lblResult.Text = GetGlobalResourceObject("Message","rfvEmailId").ToString();

In Message.resx, in App_GlobalResource

there will be a input

Name: rfvEmailId &
Value: Please enter the Email Id


Import an Excel, CSV, txt file into MySQL

Import an Excel, CSV, TXT file into MySQL


LOAD DATA LOCAL INFILE 'C:\\temp\\ListOfCountries.csv'
INTO TABLE [Table Name]
FIELDS TERMINATED BY ''
LINES TERMINATED BY '\r\n'
([Field1],[Field2]);

Stop Sharing a Folder or Drive

Stop Sharing a Folder or Drive
Applies To: Windows 7, Windows Server 2008 R2
You can stop sharing a folder or drive by using the Shared Folders Microsoft Management Console (MMC) snap-in or by using a command prompt.
Description: ImportantImportant
Users connected to a shared folder are disconnected when you stop sharing it. Users may lose data if you stop sharing a folder containing an open shared file without warning. When possible, notify users before you stop sharing a folder.
Stop sharing a folder or drive
To stop sharing a folder by using the Windows interface
1.     Open Computer Management. To do so, click Start, then right-click Computer, and then click Manage.
2.     If the User Account Control dialog box appears, confirm that the action it displays is what you want, and then click Yes.
3.     In the console tree, click System Tools, then click Shared Folders, and then click Shares.
4.     In the details pane, right-click a shared folder, and then click Stop Sharing (this item only appears if you launched Computer Management using an account that is a member of the local Administrators group).
To stop sharing multiple files, press the CTRL key while clicking the file names, right-click any one of the selected files, and then click Stop Sharing. This removes shared network access to the selected files.
To stop sharing a folder by using a command line
1.     To open an elevated Command Prompt window, click Start, point to All Programs, click Accessories, right-click Command Prompt, and then click Run as administrator.
2.     If the User Account Control dialog box appears, confirm that the action it displays is what you want, and then click Yes.
3.     Type:
net share  /delete.
For example, to stop sharing a folder called myshare, type:
net share myshare /delete
Value
Description
Net share
Creates, deletes, or displays shared folders.
The network name of the shared folder.
/delete
Stops sharing the folder.

Description: noteNote
To view the complete syntax for this command, at the command prompt, type: net help share

Keep ur coding aside.. Relax for some time..