Monday, July 19, 2010

ISTANBUL-TURKEY

ISTANBUL-TURKEY




Bosphorus Bridge


Galata Bridge


Blue Mosque


Blue Mosque-inner


Hagia Sophia


Hagia Sophia


Hagia Sophia


Cistern (Yerebatan Palace)


Pillar base in Cistern - Yerebatan Palace


Topkapi Palace


Topkapi Palace


Topkapi Palace


Obelisk of Theodosius in Hippodrome


Maiden Tower-Topkapi Palace at the back.


View of the Bosphorus from Topkapi Palace.

How to make only one radio button selectable in Datalist?

Radio Button Control in ASP.net Datalist/Repeater


How to   make only one radio button selectable in Datalist?





In   your ASPX or ASCX add the following piece of Javascript:

<script language="javascript" type="text/javascript">

function SetUniqueRadioButton(nameregex, current)

{

re = new RegExp(nameregex);

for(i = 0; i < document.forms[0].elements.length; i++)

{

elm = document.forms[0].elements[i]

if (elm.type == 'radio')

{

if (re.test(elm.name))

{

elm.checked = false;

}

}

}

current.checked = true;

}

</script>

Now, in your code behind, and in the ItemDataBound event of your Repeater/Datalist find the Radio Button   control and add an OnClick attribute to call   the Javascript function you just added to your page:

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)

{

if(e.Item.ItemType==ListItemType.AlternatingItem  || e.Item.ItemType==ListItemType.Item)

{

RadioButton rb=(RadioButton)e.Item.FindControl("rb_plan");

String strFunction = "SetUniqueRadioButton('DataList1.*Package',this)";

rb.Attributes.Add("onclick", strFunction);

}

}

Like :- if your datlist id is "Datalist1" and radibutton groupname id "Package" than the above function would be like -

SetUniqueRadioButton('Datalist1.*Package',this)

Saturday, July 17, 2010

Sys.WebForms.PageRequestManagerTimeoutException: The server request timed out

The server request timed out


"Sys.WebForms.PageRequestManagerTimeoutException: The server request timed out"


Getting  "Sys.WebForms.PageRequestManagerTimeoutException: The server request timed out"

,when using a updatepanel. Why is that?


<add verb="GET" path="ScriptResource.axd" type="Microsoft.Web.Handlers.ScriptResourceHandler" validate="false"/>

 Possible Causes to this error are-

  • The export operation was relatively long (something like 2 minutes)
  • Ajax Extension Callback framework had a timeout.
  • Do you have a particularly long running process on the server? Sounds like the PageRequestManager was waiting for a response and it didn't come back
  • Probably you are running a server-side C# code and a client-side-script by a control like a Button all together.
  • Or maybe you have written a client-side-script for a control which is placed in an updatePanel.

Possible Solutions to this error are-

  • Try this in ur webconfig file.

                   <httpRuntime maxRequestLength="1024000" executionTimeout="999999"/>

  • Try to solved it using three line of code in asp.net

                    1) <asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout ="360000"></asp:ScriptManager>       


                    2)<httpRuntime executionTimeout="360000"/>

  • If you are running a server-side C# code and a client-side-script by a control like a Button all together.Or maybe you have written a client-side-script for a control which is placed in an updatePanel.

                 So Avoid them;

  • Maximize the timeout to 10 hours

                  <asp:ScriptManager ID="ScriptManager1" AsyncPostBackTimeOut="36000" runat="server" />

 

SanDisk's SD card can store data for 100 years

PERIPHERALS

SanDisk's SD card can store data for 100 years

Jun 23, 2010 11:15 am | IDG News Service

The cards can be written on only once
by Agam Shah

SanDisk on Wednesday announced a Secure Digital card that can store data for 100 years, but can be written on only once.

The WORM (write once, read many) card is "tamper proof" and data cannot be altered or deleted, SanDisk said in a statement. The card is designed for long-time preservation of crucial data like legal documents, medical files and forensic evidence, SanDisk said.

The media comes with capacity of only 1GB. SanDisk determined the media's 100-year data-retention lifespan based on internal tests conducted at normal room temperatures.

To draw comparisons, the card is like DVD-write only media, but much smaller and with a much longer life span. SD cards typically slot into portable devices like digital cameras and mobile phones to store or move images, video or other data. The WORM works like conventional SD media, but only with compatible devices, SanDisk said.

The company said it is shipping the media in volume to the Japanese police force to archive images as an alternative to film, SanDisk said. The company is working with a number of consumer electronics companies including camera vendors to support the media.

The media is available worldwide through resellers. SanDisk did not comment on pricing.

Cyber attacks: India is the most 'peaceful' nation

Cyber attacks: India is the most 'peaceful' nation

According to a SecureWorks study, the United States is responsible for the largest number of attempted cyber attacks in the last six months

Thursday, July 08, 2010

BANGALORE, INDIA: SecureWorks announced the findings of a research study that analyzed where the greatest number of attempted cyber attacks were launching from across the globe at its 2,800 clients.

India won the study by having the lowest number of attempted cyber attacks originating from computers within its borders with only 52 attacks per thousand PCs.

The Netherlands ended in second place with 57 attacks per thousand PCs, narrowly beating Germany and Brazil who came in third and fourth place respectively, said the study. France came fifth 106 attacks, while the UK came sixth with 107 attacks per 1000 PCs, more than double the level of 52 attacks per 1000 PCs in India.

Also read: Hacking:India needs to step up cyber offensive

Jon Ramsey, SecureWorks' chief technology officer, said that the statistics show that a substantial number of vulnerable computers in countries worldwide have been compromised and are being used as bots to launch cyber attacks.

“Overall, the study shows that not only are organizations and individuals putting themselves at risk by not securing them, but they are actually providing cyber criminals with a platform to compromise other computers,” he said.

“The reasons for the difference in number of attempted attacks per country could comprise many things - this ranges from the overall Internet speeds in a country and how proactive the ISPs are in protecting their clients to general user education on security. The ratio of Windows, Mac and Linux users in a country will also make a big difference,” he added.

According to the study, the United States is responsible for the largest number of attempted cyber attacks in the last six months, with a total of 1,660 attempted attacks per thousand computers.

According to SecureWorks, there are a variety of techniques that can be introduced to help secure systems and prevent attacks. A multi-layered solution provides compensating controls that can help reduce data loss.

Traditional methods such as firewalls and anti-virus software should be combined with intrusion prevention services, access control, data encryption, tokenization, vulnerability scans, network segmentation and log monitoring to perform a rich analysis of networks and effectively protect systems, it said.

©CIOL Bureau

Autogenerate Code Using T4 in VS 2010

Autogenerate Code Using T4 in VS 2010

The Text Template Transformation Toolkit, or T4 is a solution that reduces the repetitive work of a developer by creating a template that auto-generates code from a set of rules, other code, or data input

Friday, July 16, 2010

BANGALORE, INDIA: If you look at the work that a normal developer does most of the time, it's a fairly repetitive job wherein he writes code for doing a particular module which is similar to everything else that is done with small differences being say, the fields that need to be displayed/updated to a different table in a different database. There are many other things that are similar as well.

However, there is a way to not just automate this work so that the developer has to only fill in the requirements and the code gets generated, but also ensure that the code is up to standards as defined by policy. This can make the architect's and project manager's, not to mention the developer's life also much better. There is a technology in the .NET world that allows you to do this called T4.

T4 is an abbreviation for Text Template Transformation Toolkit. This is way of writing a 'template' that can generate code from a set of rules, other code, or data input. You can write a template that can be used multiple times with a slight change in input which will output code for different scenarios. Fairly complex scenarios are possible by using this. Let's start with some simple examples and then move on to some more complex ones to see how they work.

First of all, fire up Visual Studio 2010 (or Visual Studio 2008 with the free T4 Toolbox  installed). Note that in VS2008, you will not see an item type in the new item list and will need to create a text file yourself. In VS2010, simply create an 'Empty Project' and then add a new item of type 'Text Template'. This will create a new file with the extension of '.TT'. When the file opens in VS, you will see the following lines:

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension=".txt" #>

There are a couple of things to note here. The language attribute in the first line specifies that language that is going to be used for creating the template ? not the language that is the output. The extension attribute in the second line specifies the type of file that is going to be generated. Expand the .TT file you created in Solution Explorer and you'll see a .TXT file with the same name. Now change the value in the extension to say '.cs' and it will change the file as well. Change the .TT file to the following:

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension=".cs" #>
using System;
namespace Hello
{
class Program
{
public void Main()
{ Console.WriteLine("Hello World"); }}}

As soon as you save the file, open up the associated .CS file. You should see the entire code (other than the T4 directives at the top) generated for you. Congrats, you've just auto-generated your first piece of code.

Text Template item type in VS 2010


 

However, this is not really impressive right now. You've actually written more than what the code actually is. But think of a case where you might need to write this exact same code out, but just change the message that is shown. For this, you now need to start writing T4 code itself to allow the template to accept parameters and use them in the code generation.

Modify the code above by changing the Writeline line and adding the following:

{ Console.WriteLine("<#= this.Message #>");}}}
<#+
string Message = "Hi There";
#>

When you save this file and open the .CS one, you will see that the message has indeed changed. The '<#=' and the '<#+' signs are some T4 directives to tell the T4 compiler what needs to be done. Now by simply changing the value in the Message variable, you can output different code files each time.


An autogenerated ASP.NET WebForm using a T4 template

You can also include other code files to your own. For instance, you might want to generate this file after some other processing. So create a new .TT file, say MyTest1.tt and have the following within it:

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension=".cs" #>
<#
this.Message = "Hallo Welt!";
#>
<#@ include file="HelloWorld.tt" #>

Open the MyTest1.cs file, and you'll find a German version of the 'Hello World' message. You can of course go ahead and generate a bunch of code more complex than this of course. As an example, let's take a look at some templates that automatically generate ASP.NET files - both ASPX and ASPX.CS  - for working with a database table. For code generation, the developer simply needs to change an XML file that defines the table and the fields.

A number of T4 template files are needed in this case:

1.WebFormFields.tt: Generates the frontend ASPX and HTML code

2.CodeBehindFields.tt: Generates backend database connectivity code (for this article only displays field name)

3.SaveOutput.tt: Saves the ASPX and ASPX.cs file in the current directory

4.BuildPagesFromXML.tt: Reads the XML file for fields and then uses the other T4 files to generate

The code in each (abbreviated) looks like this:

WebFormFields.tt

<#+ void GenerateASPXField(string FName, string Type, string Choices) { #>
:
<#+ switch (Type) {
case "Text": #>
<#+ break; case "List": #>
<#+ string[] items = Choices.Split(';'); for (int i = 0; i < items.Length; i++) { #>
<#= items[i] #>
<#+ } #>
<#+ break; default: break; }} #>

This code defines a T4 function that simply outputs a textbox and a dropdownlist for fields defined as such in an XML file.

CodeBehindFields.tt
<#+ void GenerateCBFieldSave(string FName, string Type, string Choices) {
switch (Type) {
case "Text": #>
Response.Write("Field <#= FName #>; Value= " + txt<#= FName #>.Text);
<#+ break; case "List": #>
Response.Write("Field <#= FName #>; Value= " + ddl<#= FName #>.SelectedValue);
<#+ break; default: break; } } #>


Another autogenerated Webform using the same T4 template

This defines a T4 function that simply outputs the fieldname and associated value.

SaveOutput.tt
<#@ template language="C#" hostspecific="true" #>
<#@ import namespace="System.IO" #>
<#+
void SaveOutput(string outputFileName)
{
string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);

string outputFilePath = Path.Combine(templateDirectory, outputFileName);
File.WriteAllText(outputFilePath, this.GenerationEnvironment.ToString());

this.GenerationEnvironment.Remove(0, this.GenerationEnvironment.Length);
}
#>

This defines a function that saves both the ASPX and ASPX.cs files when called.

BuildPagesFromXML.tt

This code will need to generate the standard ASP.NET header and footer for both files and also the generated code by including the files above. The main code for generating the fields looks like this:

foreach (XmlNode node in doc.SelectNodes("/Fields/Field"))
{
FieldName = node.Attributes["Name"].InnerText;
Type = node.Attributes["Type"].InnerText;
switch (Type)
{
case "Text":
GenerateASPXField(FieldName, Type, "");
break;
case "List":
GenerateASPXField(FieldName, Type, node.Attributes["Choices"].InnerText);
break;
}
}
SaveOutput(WebFormName + ".aspx");
foreach (XmlNode node in doc.SelectNodes("/Fields/Field"))
{
FieldName = node.Attributes["Name"].InnerText;
Type = node.Attributes["Type"].InnerText;
switch (Type)
{
case "Text":
GenerateCBFieldSave(FieldName, Type, "");
break;
case "List":
GenerateCBFieldSave(FieldName, Type, node.Attributes["Choices"].InnerText);
break;
}
}
SaveOutput(WebFormName + ".aspx.cs");

The input XML file looks like this:

As you change the form name and the fields, a new Name.aspx and Name.aspx.cs files with the correct front and backend code will be generated in the directory. As the entire set of templates was too large for this article, I'll be uploading the solution to the PCQ Forums where you can pick it up.

T4 templates are powerful ways of automating and standardizing code generated in your company's projects. You can use this to enhance productivity as well as let developers work on better value additions to the project that doing the same repetitive job everyday.

©PCQuest

Popular Posts