Tuesday, December 16, 2008

Asp.net Ajax Panel Performance

Hello friends,

let start with some perfomance improvement tips which i used and it improved performance too.

but before starting it be sure that u have restored Vs2008 sp1.

It will give many new functionality.

today's tips is Load Script befor Ui property in scriptManager tag of ajax.

when you use the LoadScriptsBeforeUI="false" then Script is load first then javascript dowloaded on client site due to which performance at user end is improved.

Secondly if you require partial page rendering that use it EnablePartialRendering="true"

just because of it your performance will improved.

you can use both the otption as shown below.




Thanks

Rajat

Silverlight Page Navigation

Dear all,

When you are new guy in silverlight then you will find the problem how to navigate in silverlight page.

even i am also get stucked in that for this reason i am writing this post to help people like me.

As you see the initial this how the default page set or load in silverlight application then you will answer in App.xaml file and you will find below code.

Private Sub Application_Startup(ByVal o As Object, ByVal e As StartupEventArgs) Handles Me.Startup
Me.RootVisual = new Page()
End Sub

It means that when ever application start it shows page.xaml because you have assign RootVisual Page class object.

now what if you want to navigate from a button click to other page like rajat.xaml.

for this you have to right some simple code. like below

first in App.xaml Start up event

Private Sub Application_Startup(ByVal o As Object, ByVal e As StartupEventArgs) Handles Me.Startup
Dim tGrid As New Grid()
tGrid.Children.Add(New Page())
Me.RootVisual = tGrid
End Sub

Then On the button click event of Page.xaml you have to write below code

Private Sub btnNavigate_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim tmp = CType(Application.Current.RootVisual, Grid)
tmp.Children.Insert(0, New Rajat()) 'Assign Rajat.xaml page class object to grid child
tmp.Children.RemoveAt(1) ' Remove old page which is page.xaml
Application.Current.RootVisual = tmp 'Assign Root visual again the page which we need to show

End Sub

I hope it will be useful .

Thanks

Rajat

Monday, November 24, 2008

Latest Version 2010

Dear All,

Its long time for me for blog posting just because my health was not so good from last few weeks.

here i am with news that micrsoft come with latest version 2010

below is link for it so lets try it and enjoy.

https://connect.microsoft.com/VisualStudio/content/content.aspx?ContentID=9790

Thanks.

Tuesday, October 14, 2008

Security information popup

Dear all,

Today i stucked in a new problem. i got security information “This Page Contains both secure and nonsecure items, Do you want to display nonsecure items popup?”

after a lot of research i got the solution.

1. If you are using image from SSL site which is not your at your domain like if you use https://google.com/image.jpg like this then

explicitly use https or use url =’//google.com/image.jpg’

2. if you are using same domain so just use url =’image.jpg’

it will solve the purpose.

thanks

i hope it will help some one..:)

Monday, September 22, 2008

Date formating is easy when you know it

Dear all,

Today i have task to do some date formating in DataGrid. So i think its easy but you don’t belive that its easy only when you remember the formating character.

Which i don’t really remember always and it is true. so for this purpose i am putting some format string here so at least i will get benifit in future.

Before starting i want to say if you are using type dataset for binding the grid please check your date column’s data type by mistake i did it string so be remember it should be date. here firstly we talk about time so here i goes.

h :- Displays the hour like (1,2,…12) remember limit & its mainly use with AM/PM format

hh :-Displays the hour like (01,02,…12) remember limit & its mainly use with AM/PM format

H :- It also display hours but diffrence is limit goes up to 23 like (1,2,3,….23) & not used with AM/PM format

HH :- It is same as H but diffrence is it start with 0 if number is less than double digit.

m :-Display the minutes.

mm :- it always show minutes in two digits.

s:- show seconds

ss:- Show seconds in always 2 digit like 00,01,02,…59

t :- it display first character of AM/PM

tt:- it Display either AM or PM

M:- it denotes month start from 0 - 12.

MM :- it also shows month but in double digit 01,…12

MMM :- shows month in 3 character like JAN, FEB

MMMM (+): Shows month with full name.

yy:- it show year last two digit

yyyy:- its show year like 1998, or we can say in 4 digit.

d :- Shows current day of the month.

dd:-It shows day in 2 digit always like 01,

ddd:- Show’s 3 character of the day like MON , TUE

dddd(+):- show full day character

exmaple x.ToString(”0:MM/dd/yy hh:mm:sstt)

Thanks …

Friday, September 19, 2008

Some Acronyms

Dear all,
Here is some useful acronyms
CCW COM Callable Wrapper
CLI Common Language Infrastructure. This is a subset of the CLR and base class libraries that Microsoft has submitted to ECMA so that a third-party vendor can build a .NET runtime on another platform.

CLR Common Language Runtime
CLS Common Language Specification
COFF Common Object File Format
COM Component Object Model
CTS Common Type System
DISCO Discovery of Web Services. A Web Service has one or more. DISCO files that contain information on how to access its WSDL.
DNA Distributed interNet Applications Architecture.
DOM Document Object Model
GDI Graphical Device Interface
GAC Global Assembly Cache
GUID Globally Unique Identifier
HTTP Hyper Text Transfer Protocol
IDL Interface Definition Language
IL Intermediate Language
MSIL Microsoft Intermediate Language
MS-DTC Microsoft Distributed Transaction Coordinator
N-Tier Multi-Tier
OLTP Online Transaction Processing
OLAP Online Analytical Processing
PE Portable Executable
RAD Rapid Application Development
RCW Runtime Callable Wrapper
SMTP Simple Mail Transfer Protocol
SOAP Simple Object Access Protocol
TCP Transport Control Protocol
TLB Type Library
UDF Uniform Data Format
UI User Interface
URL Uniform Resource Locator
UDDI Universal Description, Discovery and Integration
WAP Wireless Access Protocol
WSDL Web Services Definition Language
WML Wireless Markup Language
XML Extensible Markup Language

Tuesday, June 03, 2008

How to use iFrames in Asp.net??

1. place your iframe tag where your want in body tag for ex
< iframe id="frame1" style="HEIGHT: 150px" border="0" name="frame1" align="middle" frameborder="no" width="100%" scrolling="no" runat="server">
2. Now, declare one Htmlgeneric control like thisprotected System.Web.UI.HtmlControls.HtmlGenericControl frame1;
3. At last ....HtmlControl
frame1 = (HtmlControl)this.FindControl("frame1");
frame1.Attributes["src"] ="target.aspx".ToString ();
write this in your application page load function.........

Monday, May 26, 2008

Crystal Report Programming

Hi friends ,

Here Some work with crystal report programming


· To total a report field with a formula field

EvaluateAfter ({@DrOpBalance});
{@DrOpBalance} + Sum ({Debit});

Where @DrOpBalance is a formula field and Debit is a report field.

· Conditional statement

1)

EvaluateAfter ({@CrSideTotal});
If {@DrSideTotal} >= {@CrSideTotal} Then
{@DrSideTotal} - {@CrSideTotal}
Else
0.00;

2)

WhilePrintingRecords;
NumberVar DrTotal;

If {XMLRBSheet.AMOUNT} > 0 Then
DrTotal := DrTotal + {XMLRBSheet.AMOUNT};

If {XMLRBSheet.AMOUNT} > 0 Then
{XMLRBSheet.AMOUNT}
Else
0.00;

· Declaring variables

NumberVar DrTotal;

· Variable assignment

Dabit := 1000

· Accessing final/latest value of a variable

EvaluateAfter ({@ClStock});
NumberVar CrTotal;
NumberVar CurrentRecord;

CurrentRecord := RecordNumber();
CrTotal := CrTotal + {@ClStock};

Practical Approach

Visual Basic Dot Net – Practical Approach


· To start a application in a new thread

System.Windows.Forms.Application.Run(New FrmMainMDI)

· Database Handling

1) Opening a new connection

Try
Dim CnString As String
Dim ActiveDBConnection = New SqlClient.SqlConnection

CnString = “Put your connection string here”

ActiveDBConnection.ConnectionString = CnString
ActiveDBConnection.Open()

Catch e As SqlClient.SqlException

ActiveDBConnection = Nothing

End Try

2) Executing a non select query

Dim RowAffected As Integer
Dim TSQLString As String
Dim DBCommand As SqlClient.SqlCommand

DBCommand = New SqlClient.SqlCommand(TSQLString, _
ActiveDBConnection)

RowAffected = DBCommand.ExecuteNonQuery()

If RowAffected = 0 Then
Return False
End If

3) Executing a select query for DataSet

Dim DBCommand As SqlClient.SqlCommand = New _
SqlClient.SqlCommand(TSQLString)

Dim DBDataAd As SqlClient.SqlDataAdapter = New _
SqlClient.SqlDataAdapter
Dim TempDS As New DataSet

DBCommand.Connection = ActiveDBConnection
DBDataAd.SelectCommand = DBCommand
DBDataAd.Fill(TempDS)
Return TempDS

· Getting value of a particular field in a DataSet

DataSet.Tables(0).Rows(“Row Index”)(“Column Name/Index”)

· Getting value of a particular field in a DataRow

DataRow.Item(“Column Name/Index”)

· Function to check whether a MDI Child is active or not

Private Function CheckActiveMDIChild(ByVal MDIChildName As
String) As Boolean
Dim X As Short
X = 0
Do While X <= Me.MdiChildren.Length - 1
If Me.MdiChildren(X).Name = MDIChildName Then
Return True
Exit Do
End If
X = X + 1
Loop
Return False
End Function

· Creating a new form object and assigning it to MDI form

Dim TempFrmProduct As New FrmProduct
TempFrmProduct.MdiParent = Me
TempFrmProduct.Show()
‘ Or to show form as dialog (Does not work in case
of a MDI child)

TempFrmProduct.ShowDialog()

· Checking data type of a column in a DataSet

If DataSet.Tables(0).Columns("Name/Index").DataType.FullName =
_ "System.Decimal"
End If

· Reading a text file

Dim ConnectionStringText As String
Dim FS As New System.IO.FileStream(FileName, _
IO.FileMode.Open, IO.FileAccess.Read)

Dim R As New System.IO.StreamReader(FS)

ConnectionStringText = R.ReadLine
R.Close()

· Handling Crystal Reports

First add the crystal report (.rpt) file to project. Visual Basic automatically creates the .VB file for that particular report. This file is basically contains the class for the report added. We can use this class to call the particular report (By making a object of the class).

For example you have a report named “RBalanceSheet”. Now do the following to call the report through code.

Dim TReportDocument As New RBalanceSheet

‘ Passing values to formula fields defined in the
‘ report

TReportDocument.DataDefinition.FormulaFields.Item("OpeningText").Text = "’To Opening Balance’


‘ Setting DataSet (Data source) for the report
TReportDocument.Database.Tables.Item("XMLRBalanceSheet").SetDataSource(ReportDS.Tables(0))

‘ Calling the report through Crystal Report Viewer

CrystalReportViewer1.ReportSource = TReportDocument

· Handling DataGrid KeyPress and mouse click events

Add following event handler on form load event:

AddHandler ProductColumnStyle.TextBox.KeyPress, AddressOf
ProductColumn_KeyPress

AddHandler ProductColumnStyle.TextBox.DoubleClick, AddressOf ProductColumn_DoubleClick

Now add following event procedure:

Private Sub ProductColumn_KeyPress(ByVal sender As Object,
ByVal e As System.Windows.Forms.KeyPressEventArgs)

If Asc(e.KeyChar) = Keys.Space Then

‘ Write code here

End If
End Sub

Private Sub ProductColumn_DoubleClick(ByVal sender As
Object, ByVal e As System.EventArgs)

‘ Write code here

End Sub

· Handling Stored Procedures

1) Filling dataset using stored procedure:

Dim TempDS = New DataSet

MyDbCommand = New SqlCommand("sp_Select", MyConnection)
MyDbCommand.CommandType = CommandType.StoredProcedure

MyParamTempID = New SqlParameter("@TempID", “1”)
MyDbCommand.Parameters.Add(MyParamTempID)

MyDbAdapter.SelectCommand = MyDbCommand
MyDbAdapter.Fill(TempDS)

2) Using output parameter of the stored procedure:

Dim MyDbAdpater As New SqlDataAdapter
Dim MyDbCommand As New SqlCommand("sp_OutputValue", MyConnection)

MyDbCommand.CommandType = CommandType.StoredProcedure
Dim TempDs = New DataSet

Dim MyParamTempID1 As New SqlParameter("@TempID1", “1”) Dim MyParamTempID2 As New SqlParameter("@TempID2", “2”) Dim MyParamNameAdd As New SqlParameter("@NameAdd", SqlDbType.VarChar, 50)
MyParamNameAdd.Direction = ParameterDirection.Output

MyDbCommand.Parameters.Add(MyParamTempID1)
MyDbCommand.Parameters.Add(MyParamTempID2)
MyDbCommand.Parameters.Add(MyParamNameAdd)

MyDbCommand.ExecuteScalar()

MsgBox(MyParamNameAdd.Value)

3) Inserting values through stored procedure:

Dim MyDbCommand As New SqlCommand("sp_Insert", MyConnection)
Dim MyParamName As New SqlParameter("@Name", “John”)

MyDbCommand.CommandType = CommandType.StoredProcedure

MyDbCommand.Parameters.Add(MyParamName)
MyDbCommand.ExecuteNonQuery()

4) Using Parameterized query:

Dim TempDOB As Date
TempDOB = "01/05/1980"
Dim MyDBCommand As New SqlCommand("Insert InTo Personal (Name, Age, DOB) Values (@Name, @Age, @DOB)", MyConnection)

Dim MyParamName As New SqlParameter("@Name", “John”)
Dim MyParamAge As New SqlParameter("@Age", 25)
Dim MyParamDOB As New SqlParameter("@DOB", TempDOB)

MyDBCommand.Parameters.Add(MyParamName)
MyDBCommand.Parameters.Add(MyParamAge)
MyDBCommand.Parameters.Add(MyParamDOB)

MyDBCommand.ExecuteNonQuery()

· Binding DataGrid To Dataset

MyDBAdapter.Fill(MyTempDS, "MyTable")

DataGrid1.DataSource = MyTempDS.Tables(“MyTable”)
DataGrid1.DataBindings()

· Binding Combo Box To Dataset

MyDBAdapter.Fill(MyTempDS, "MyTable")
ComboBox1.DataSource = MyTempDS
ComboBox1.DisplayMember = "MyTable.Name"

Monday, May 05, 2008

Some Interview Stuff

· Windows DNA was a programming model or blueprint that companies could use when designing n-tier distributed component-based application for the windows platform.

· Shadow Copy

This is a feature of CLR. When you update a component of ASP .Net and overwrite the old version of the component by the new one into the bin directory or in GAC, ASP .Net detected the changes and automatically loads the new component and use them to process all new web requests not currently executing, while as the same time keeping the older versions of the components loaded until previously active requests are completed.

· The .Net code you write today will also work under 64-bit versions of windows without change.

· The CLR is a runtime for all .Net languages. It is responsible for executing and managing all code written in any language.

· Code Verification is a process that ensures all code is safe to run prior to execution.

· The code produced for an application designed to run under the CLR is called managed code -self-describing code that makes use of and requires the CLR to be present. For managed code, the CLR will: always locate the metadata associated with a method at any point in time, walk the stack, handle exceptions, store and retrieve security information, manages memory and garbage collects.

· Namespaces have two key functions:

1) They logically group related types.
2) They make name collision less likely.

· We can use/declare any native CLR data types in any language, Even though that language does not support that type (does not have a mapping name for the type).

Value types in the CLR are defined as types that derive from System.ValueType. Value types are not instantiated using New (unless you have a parameterized constructor), and go out of scope when the function they are defined within returns.

· In case of boxing/un-boxing the value contained in the type and the created reference types are not associated in any way. If you change the original value type, the reference type is not affected. Boxing (Object = Value Type) occurs implicitly by the compiler/CLR, but you have to un-box (Value Type = Object) explicitly. In .Net structures are always value types.

· MSCoreLib.Dll is the mail CLR system assembly, which contains the core classes for the built-in CLR types, etc.

· Attributes are a feature of CLR compilers that enables you to annotate types with additional metadata. The CLR or other tools can than use this metadata for different purpose, such as containing documentation, information about COM+ service configuration, and so on.

· All windows applications run inside a process. Processes own many resources and threads execute code loaded into a process. If one application runs in its own process and we have multiple applications of same type (i.e. large number of web sites running on IIS) running in their own processes, they consume lots of resources. If we have multiple application are running on same process, although we can save much resources, but when an application crashes it can destroy entire process and all other applications. Application Domains in .Net have same benefits as a process, but multiple application domains can run within the same process. Application domains can be implemented safely within the same process, because the code verification feature of the CLR ensures that the code is safe to run. All the code execution in the application domain is managed by CLR, so the crashing of an application is not typically possible, and when it happens it does not affect the other applications running on other application domains.

· The concept of locating and consuming programmatic functions over the Internet is called web services. Web services are based on an application of XML called SOAP. SOAP defines a standardized format for enveloping the XML payloads exchanged between two entities over standard protocols such as HTTP. The consumers of a web service are completely shielded from any implementation details about the platform exposing the web service - they simply send and receive XML over HTTP. This means that any web service on a windows platform can be consumed by any other platform, such as UNIX.

· You can find information about any name-space, class, interface or any other type in .Net using a utility called WinCV (Windows Class Viewer).

· ASP .Net Page Compilation

Request For A Page >> Parsing Of The Page Into A DLL By Page Compiler >> DLL With Compiled Class Places Into A Temporary Directory >> Render The Page Using The Compiled Class.

The process of compilation of the page occurs only once for a .Aspx page. Every time a request is occurs for the same page, that request is satisfied by instantiating the class generated.

· ASP .Net is implemented as an HTTP handler. Different ASP .Net services (not web services) like state management, security and others, all handles by various HTTP handler/modules. Each HTTP handler is responsible for serving a specific task. To implement your own HTTP runtime handler, you can create a class that supports the HTTP runtime interface, add your extension and class to the web.config file and hence write your own web technologies. When your HTTP runtime handler is hosted in IIS, you must add your extension to the IIS configuration map.

ASP .Net uses the compilers section of the machine.config file to define the mapping of a page’s extension and available languages that can be used in ASP .Net.

· ASP .Net enables you to build the following types of server controls:

1) Custom server control: You can write the server controls in a compiled form, where you develop a class that inherits from one of the ASP .Net server controls classes.
2) User controls: You can declare other ASP .Net pages as controls, and then use those pages to build up other pages.

· Overloads keyword with methods is not required when overloading methods in the same class, but if it is used, it must be used on all overloaded methods.

· Shadows means that the method in the parent class is not available, and allows creation of methods with the different signature than that of the parent. It effectively re-declares the type.

· An interface is the description of the methods and properties a class will expose – it’s an immutable contract with the outside world.

· .Net’s CTS also responsible for cross-language functionality.

· Page Events: Page_Init >> Page_Load >> Control_Event >>
Page_Unload

· The difference between Page_Init and Page_Load is that the controls are only guaranteed to be fully loaded in the Page_Load. The controls are accessible in the Page_Init event, but the ViewState is not loaded, so controls will have their default values, rather than any values set during the postback.

· Sample ASP .Net page format:

<%@ Import Namespace=”System.Data” %>








runat=”server”/>





· Page’s IsPostBack property would be false when the page is loaded first time, and it will be true on subsequent request.

· When a client makes a request to the server for a page, the compilation process creates a class derived from System.Web.UI.Page, and includes all the components (.aspx file being requested, code file for the page, any user control used by the page). This dynamically created page class can than be instantiated to render the requested page. This compilation process is occurs only first time when any user requests the page. On any subsequent requests this compiled class can be used to render the same page again and again.

· Page class has a unique step, known as rendering step, when HTML is actually generated for the output to the client.

· When your code behind contains a class named MyClass then the .aspx page linked with the code behind file like:

<%@ PAGE Inherits=”MyClass” Code=”MyPage.Vb %”>

· To merge a HTML file with the currently rendering page HTML use following WriteFile method of the response object into Page_Load event: Response.WriteFile(“C:\Temp\Content.html”)

· The ViewState contains the state of all user controls on the page. This information is stored as name-value pairs using the Sytem.Web.UI.StateBag object. The ViewState is stored as a string variable that is passed back to the client in the page. String representing ViewState values is stored as a hidden form field. We can enable or disable the ViewState by using EnableViewState property at page or control level.

· Client makes requests to server (round-trips) through an HTTP POST.

· In processing of control events, those events are process first that being happened at client but did not cause a post-back. After that the event that caused a post-back is processed.

· Any in-line script code is run at rendering stage.
· When you have an event of a control that can be handled on either the client or the server, then the server handling of that event will take precedence. For example if a button control have both server (OnServerClick) and client (OnClick) event handler than client side event handler will be ignored.

· ViewState property is a collection of the state that is maintained by the page. This option is available through a state bag object. We can use ViewState property like:

ViewState(“MyName”) = “John” ‘ Adding value

Integer Name As String
Name = ViewState(“MyName”) ‘ Retrieving value