Search This Blog

Thursday, April 25, 2013

How can use Replace function in c#


 txtques.Text = dr[0].ToString().Replace("'","'").Trim();
 txtans1.Text = dr[1].ToString().Replace("'","'").Trim();
 txtans2.Text = dr[2].ToString().Replace("'","'").Trim();
 txtans3.Text = dr[3].ToString().Replace("'","'").Trim();
 txtans4.Text = dr[4].ToString().Replace("'","'").Trim();
             
cant show like this can't

insert case
string txt_book1 = txt_book.Text.ToString().Replace("'", "'").Trim();

update case
string txt_book1 = txt_book.Text.ToString().Replace("'", "'").Trim();

MAC Error in asp.net "Validation of viewstate MAC failed"


Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

Source Error:

try to add this string in <system.web> section of your web.config file :

<pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode ="Never" />
for fix "Validation of viewstate MAC failed" error.

Wednesday, April 24, 2013

How can HTML Character Encoding in C#


<%@ Page Language="C#" MasterPageFile="~/Admin_1/MasterPage.master" AutoEventWireup="true"
    CodeFile="Destination_Month.aspx.cs" Inherits="Admin_1_d_Month"
    Title="Untitled Page" ValidateRequest="false" %>

String displayed correctly in the browser and not interpreted by the browser as HTML. For example, if a text string contains a less than sign (<) or greater than sign (>), the browser would interpret these characters as the opening or closing bracket of an HTML tag. We can manage by HttpUtility.HtmlEncode(TextBox6.Text) any HTML string in c#.


cmd.Parameters.Add("@e6", SqlDbType.VarChar, 0).Value = HttpUtility.HtmlEncode(TextBox6.Text);
cmd.Parameters.Add("@e7", SqlDbType.VarChar, 0).Value = HttpUtility.HtmlEncode(TextBox7.Text);
cmd.Parameters.Add("@e8", SqlDbType.VarChar, 0).Value = HttpUtility.HtmlEncode(TextBox8.Text);
cmd.Parameters.Add("@e9", SqlDbType.VarChar, 0).Value = HttpUtility.HtmlEncode(TextBox9.Text);

Create crystal report in asp.net step by step process......

Step1: 1st create one application and add web Form as aspx page.



Step2: Add crystal reportviewer on aspx page.




Step3: Add xsd file in application.





Step4:Add new element  on xsd file.















Step5: code on cs page....


Step6: Final crystal report....



How can create crystal report for any reporting data


Step1: 1st create one application and add web Form as aspx page.


Step2: Add crystal reportviewer on aspx page.


Step3: Add xsd file in application.


Step4:Add new element  on xsd file.















Friday, April 5, 2013

How can develop a C# .NET application to support multiple languages?



I have start work on one asp.net (in 2008) application client wants multiple languages in application. Client wants application run in Hindi, English, Japanese, and Urdu language on same page for all content. In this application all page content convert in different languages on one click on selected language.

ASP.NET provides App_GlobalResources for resources file, always used resource files for multi-language applications.

Step for creating new application in multiple languages:

Step1.
Create new web application name language as per below screen in asp.net 2008.

 
 Step2.
After that add resource file in application, when add Resource file ENUS.en.resx  ASP.NET framework Ask for folder where save .resx file click on YES then auto create App_GlobalResources  folder in application as per below screen.





Step3.
Like above process also add many resource file for different languages. As per screen I am using 5 language in this application. So add 5 Resource file for 5 different languages.
ENUS.en.resx for ENGLISH
ENUS.es.resx for SPANISH
ENUS.hi.resx for HINDI
ENUS.ja.resx for JAPANESE
ENUS.ur.resx for URDU



Step4.
After this step we have create our application page Defualt.aspx in this page I have define all fields in label. As per below screen. I want change all label in different language on click given buttons.Also remember on aspx page UICulture=”auto”
<%@ Page Language="C#" AutoEventWireup="true" UICulture="auto" Culture="auto"  CodeFile="Default.aspx.cs" Inherits="_Default" %>



Step5.
Open resx file and you can see 3 fields Name , Value and comment. As per below screen you can define Name and value in different languages.



Name :: Default_lbl_department   name format not fix ,its depend on you in my name Default is page name and lbl_depatment is label name  which are define on my default page .

Value :: Value is different language text, its define in value field. Like I have one field Department:: विभाग. I have put in Hindi in this way you can define all fields in Value field as per below screen.


Step6.
We can define namespace in default.cs file, that provided by asp.net.
using System.Threading;
using System.Globalization;
using System.Resources;
using Resources;

Step7.
Write cs page code:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using System.Resources;
using Resources;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
   
    protected void But_spanish_Click(object sender, EventArgs e)
    {
        string lng = "es";
        LangChange(lng);
    }
    protected void But_japanese_Click(object sender, EventArgs e)
    {
        string lng = "ja";
        LangChange(lng);
    }

    protected void But_urdu_Click(object sender, EventArgs e)
    {
        string lng = "ur";
        LangChange(lng);

    }
    protected void But_hindi_Click(object sender, EventArgs e)
    {
        string lng = "hi";
        LangChange(lng);
    }
    protected void But_eng_Click(object sender, EventArgs e)
    {
        string lng = "en";
        LangChange(lng);
    }

    public void LangChange(string strLanguage)
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(strLanguage);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(strLanguage);
        lbl_department.Text = ENUS.Default_lbl_department;
        lbl_designation.Text = ENUS.Default_lbl_designation;
        lbl_email.Text = ENUS.Default_lbl_email;
        lbl_emp.Text = ENUS.Default_lbl_emp;
        lbl_password.Text = ENUS.Default_lbl_password;
        lbl_phone.Text = ENUS.Default_lbl_phone;
        lbl_userid.Text = ENUS.Default_lbl_userid;
    }
}

Step8.
After that we can run application and find page on browser as per below screen.On click button change reflect on web page as per languages.

Important Notes : If you find below error when build the application.

Error    1          The namespace 'Resources' already contains a definition for 'ENUS'            c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\language\630c8d9e\42ad8c5b\App_GlobalResources.__9l9ovu.1.cs     12 
      
In this case open given path and delete all Resources file and again build your application.
I hope this step useful for your application. If any query or feedback then put your valuable comments on this topic.