-->

Saturday, April 4, 2015

Fix Application is currently offline

Application is currently offline error occurs in the browser. Offen, when we work with the SQL-Sserver then that's types of problem occurs. When, today i  was develop a new project with the help of SQl. i face this error during demonstration. I want to say that when we retrieve data from database table through Sql DataSource control. I was run my application in browser, error becomes in the browser. Actually its not a error, you can say its a exception, which is detect by the browser. I think, this is overloading exception,  after some time buffer is full so dotnet framework create a page for this types of exception.

Exception snapshot

 

How to fix it

  1. Remove the app offline page (HTML page) from the project folder
  2. Empty your Recycle Bin

How to Hide web application code from users in ASP.NET

If we talk about web application projects then we simply says that each presentation page attach with code behind page(where you can design your business logic code). If you are a developer and you want to sell your project without code then you will hide its business logic code behind the ".DLL" (dynamic link library) file.
There are available some steps to do this task.
These are
  1. Create a web application project (file--new project--Visual C# --Web -- ASP.NET web Form application)
  2. Write project name, which you want, In this article we take "hide code" as a project name.
new web project in asp.net

3. Delete all directories from the solution explorer. Because i want to design only business logic code, after coding we will create DLL file for this. For this you should attach a class file in this project. Take a look after deleted all files from solution explorer.

deleted all files from solution explorer.

4.  Now, we learn how to attach a class file in the project. Select "add new item" from context menu by right clicking on project name.
Select "add new item"

Now, here appear a new window. In this window select code in left panel and also select class in the right panel.
 select code in left panel and also select class in the right panel.

5.  Write the business logic code for display message on the screen, so we raise a button handler code in displayResult class.
You can design your code for multiple classes through this approach we will create a business logic model. Suppose i want to create a small application for employee, in which i want to display data of employee also display employee salary. Application hold two function first for employee data and second for employee salary. Similarly through this code i want to display "Hello World!" message on the browser. Now your code look like
business logic model

In the above mentioned snap displayResult class inherits from page class, page class contains some object like response,request etc. if you want to use page objects then created class must be inherits from Page class. Also mentioned two namespace, first is System.Web.UI and other is System.Web.UI.WebControls.
6.  Build the solution by selecting "Build HideCode" from Build Tab.
Build the solution by selecting "Build HideCode"

Now your .DLL file has made in Bin folder of the project. File contains single namespace(HideCode) , class(displayResult) and single method(displayresult( )).
7. Now add new project in the solution by right clicking on solution name. Select ASP.NET Web form application project in appeared window also write name of the project, i keep presentation part as a project name. Now your solution explorer contains two project, see below
solution explorer contains two project

8.  Now add new web form in the project also change the name of it, i keep  "presentationpage.aspx" as a project name. This page is basically used for designing purpose. Through this page we can call method of other projects, but will do some changes in the page . Before doing this, first of all add above mentioned project reference in the current project. Learn how to add reference in the project.
Note : Remove all attached file from this page.
 Remove all attached file from this page

(a) Add Reference by right click on References link. select Solution from the appeared window also select .dll checkbox which is appeared in right panel of it.
select .dll checkbox which is appeared in right panel

9. Remove "CodeBehind" attribute from presentation page also add inherits attribute in the page directive. Assign namespace , which is created in earlier project  with class name. Look like
 Remove "CodeBehind" attribute

10. Add button in the page also raise onclick event on it. Call displayresult( ) method, which is created in business logic code. now your code look like
<%@ Page Language="C#" AutoEventWireup="true" Inherits="HideCode.displayResult" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="hide coding" OnClick ="displayresult" />
</div>
</form>
</body>
</html>

Now your code generate the following output

How to Hide web application code from users in ASP.NET

First code of line define the page directive. In this line,you must to add namespace with class name in inherits attribute. After that you can access methods and properties of that class. In this code i also access method of displayResult class using Button click event.

Tuesday, March 31, 2015

Can we take multiple web.config files in single asp.net application

Yes,  we can take multiple web.config files in the single asp.net application. If we have a single directory then we can add multiple config file with different name. If you want to access xml tag from config file then you can access only web.config file elements. Lets take an simple example of the file.


web.config file

<configuration>
  <appSettings>
    <add key="first" value="My first web.config file"/>   
    
  </appSettings>
</configuration>

Default.aspx file

    <asp:Label ID="Label1" runat="server" Text="<%$appSettings:first%>"></asp:Label> 

Its working fine, but when we take another config file in the application then get the error like file not found error. So, i have a solution of this problem. Follow the mentioned steps to overcome this problem:
Step-1 : Add a new directory in the solution(application)
Step-2 : Add new web.config file in the newly created directory.
Step-3 : Also add a web form in the directory.
Step-4 : Now, you can easily access web.config file which is available in the newly created directory.

Saturday, March 28, 2015

Button Enable disable when we write some text into TextBox in ASP.NET

I mean to say, we have three controls, two TextBoxes and one Button control. When we run the source code in the browser button is disabled by default. If we want to enable button at run time then we must to input some text in both TextBoxes. For this type of problem we should go for java script.


<%@ Page Language="C#" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script>
        function change(textb,buttont)
        {
            var firstt = document.getElementById('<%= TextBox1.ClientID %>');
            var secondt = document.getElementById('<%= TextBox2.ClientID %>');
            if ((textb.value.length>=1 && firstt.value.length >= 1) && (textb.value.length>=1 && secondt.value.length >= 1))

                document.getElementById(buttont).disabled = false;
            else
                document.getElementById(buttont).disabled = true;

        }



    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" onkeyup="change(this,'Button1');"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"  onkeyup="change(this,'Button1');"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" Enabled="false" />
    </div>
    </form>
</body>
</html>

Here,

  1.  onkeyup() function call when we input character into text box.
  2.  change() function have two parameter first is TextBox instance and second is button reference.
  3. Access both TextBoxes by using document.getElementById( ) method.
  4.  Now, check the length of the string which is entered in the TextBox.
  5. If, Length is greater than equal to 1 then Button is enable otherwise disable.

Monday, March 16, 2015

How to create pdf file in windows form c#

If you wan to create pdf file in windows form as well as web application , you must to add iTextSharp.dll file as a reference. In iTextSharp , we have a Document class through which we can create a new document. Also provide PdfWriter class, through which we can create a pdf file in a specified path. Now, you can use Paragraph class for creating text. Now, use this code and Generate pdf file:

Document d1 = new Document();
            PdfWriter.GetInstance(d1, new FileStream("E:/t1.pdf", FileMode.Create));
            d1.Open();
            Paragraph p1 = new Paragraph("Hello World");
            d1.Add(p1);
            d1.Close();


Video cover all such things which is i mentioned in above. Also provide the link where you can download the iTextSharp.dll file and where you will put the mentioned code in function.

Thursday, March 12, 2015

How to write something on image in windows form c#

Using Graphics class we can write something on image. Graphics class object invoke drawing objects, like String, Rectangle, oval etc. For DrawString( ) method, we need some parameter like string text, font, point where you want to display string on image. Now copy this code



            Image img = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);

            var font = new Font("TimesNewRoman", 25, FontStyle.Bold, GraphicsUnit.Pixel);

            var graphics = Graphics.FromImage(img);

            graphics.DrawString("Hello World! " , font, Brushes.Red, new Point(0, 0));

            this.pictureBox1.Image = img;

Here

  1. First to add the picture box in the form.
  2. Now, using the Bitmap class we can pick the resolution parameter of picture box then assign these parameter to Image class instance.
  3. Take Font class for making highly visualize text in the image.
  4. Use graphics class to Draw the string on the image.
  5. Before Drawing must to assign the image to the Graphics class.
The following mentioned video contain full implementation guide:



Monday, March 9, 2015

Tips for program designing in C language

Now, let us see "What are the tips to design a good program?"
Although the program design involves several stages, the following are the few important tips to design a good program:

I Tip: Make a program readable. It is a combination of the following:

  1. Careful choice of data structure or data type.
  2. Careful choice of variable names.
  3. Generous use of remarks or comments.
  4. Program indentation.
  5. General program design


II Tip: Stepwise refinement of a solution

  1. Break a problem into a sequence of relatively self-contained or independent sub-problems.
  2. Follow orderly flow of stepwise refinement.


III Tip: Avoid 'goto' statement to jump around, forward and backward, into and out of loops or blocks of statements. The blocks are also called compound statements.

  1. The programs using 'goto' are difficult to read and debug.
  2. The programs using 'goto' are called unstructured programs. Always hate such unstructured programs.


© Copyright 2013 Computer Programming | All Right Reserved