ASP.NET

Q1.Difference between GET & POST Method?

Ans.
GET:
1) Data is appended to the URL(QueryString)
2) Data is not secret.(Can be seen by anyone)
3) It is a single call system
4) Maximum data that can be sent is 256.
5) Data transmission is faster
6) This is the default method for many browsers
7)Get requests can be cached
POST:
1) Data is not appended to the URL but sent as part of Http Body.
2) Data is Secret
3) It is a two call system.
4) There is no Limit on the amount of data.That is characters any amount of data can be sent.
5) Data transmission is comparatively slow.
6) No default and should be Explicitly specified.
7)Post requests are never cached.


What are page directives?

The first line of an ASP.NET page is the page directive; you will find it on all ASP.NET pages. These directives are instructions for the page. It begins with the @Page directive and continues with the various attributes available to this directive.
It's unreasonable to expect a candidate to know all of these attributes, but a few popular ones include the following.
·         AutoEventWireup: Indicates whether page events are autowired.
·         CodeBehind: The name of the compiled class associated with the page.
·         Debug: Indicates whether the page is compiled in debug mode (includes debug symbols).
·         EnableTheming: Indicates whether themes are used on the page.
·         EnableViewState: Indicates whether view state is maintained across pages.
·         ErrorPage: Specifies a target URL to be used when unhandled exceptions occur.
·         Language: Indicates the language used when compiling inline code on the page.
·         Trace: Signals whether tracing is enabled on the page.

What is a master page?

A master page is a template for one or more Web Forms. The master page defines how the page will be laid out when presented to the user, with placeholders for content. The MasterPageFile Page Directive in a content page's header is one way to assign a master page. The content pages rely solely on content and leave layout to the master page. ASP.NET merges the content with the master page layout when the content page is requested by a user.

What is the code behind feature of ASP.NET?

The code behind feature divides ASP.NET page files into two files where one defines the user interface (.aspx), while the other contains all of the logic or code (.aspx.cs for C# and .aspx.vb for VB.NET). These two files are glued together with page directives like the following line, which ties the page to the specific code behind class.
<%@ Page language="c#" Codebehind="UICode.cs" Inherits="Library.UICode" %>

What are ASHX files?

ASP.NET Web handler files have an .ashx file extension. Web handlers work just like .aspx files except you don't have to deal with the browser interface, thus no worrying about presentation. Web handlers are generally used to generate content dynamically like returning XML or an image. Web handlers use the IHttpHandler interface with the ProcessRequest() method invoked when the handler is requested. Web handlers are simpler than pages (fewer events and wiring), so they are ideal for performance-critical applications.

How does PostBack work?

PostBack is basically the ASP.NET submitting a form to it -- it posts back to the current URL. The JavaScript __doPostBack function is placed on the page (look at the source within the browser) to facilitate. PostBack uses ViewState to remember controls and data. The IsPostBack property of the ASP.NET page allows you to determine if the loading of the page is the result of a postback event; this is done in the Page_Load event.

How can you pass values between ASP.NET pages?

There are numerous ways to accomplish this task; the option you choose depends on the environment. The oldest way to approach it is via the QueryString (i.e., passing values via URL); this is also one of the least secure ways because users can easily see the data and could possibly hack the site/page by changing parameter values. Next, you can use HTTP POST to pass values; these are available via a collection within the ASP.NET page. More specific to ASP.NET is the use of Session state, which makes information available to all pages within the ASP.NET application. Another approach is using public properties on the source page and accessing these properties on the target page. Also, you can use the PreviousPage property of the current page to access control information on the referring page. The last two require the source, and target pages are within the same ASP.NET application.

What are ASP.NET Server controls?

ASP.NET includes a number of built-in server controls that are the foundation of its Web programming model. They have various properties to control their behavior and appearance. These controls provide an event model where events are handled on the server (whereas HTML controls are handled in the client). Server controls have the ability to maintain state (via ViewState) across requests, and they can automatically detect the browser. With these controls, you will see the RunAt attribute (RunAt="Server") that signals its processing will be done on the server. A good example of these controls is the basic TextBox control (<ASP:TextBox RunAt="Server" .... >.

What is View State?

Basically, View State is how ASP.NET Web pages persists data across requests. It handles data that must be preserved between postbacks, and you can use it to store page-specific data. By default, View State is enabled on a page and its controls. This can be a problem as the amount of data and controls on a page increases resulting in more data for ASP.NET to maintain. This is accomplished via the hidden __VIEWSTATE field on a form (look at the page source in a browser), so more data in this field means a slower load time and slower overall processing, as it has to be posted to the server each time. You can limit the size of the data in View State by disabling controls that do not need to be persisted via the EnableViewState property. View State can be encrypted to address security concerns.

What is the global.asax file?

The global.asax file is an optional piece of an ASP.NET application. It is located in the root of the application directory structure. It cannot be directly loaded or requested by users. It provides a place to define application- and session-wide events. You can define your own events, but it does contain default Application events like when the application starts Application_Start and ends with Application_End. The same is true for Session events (Session_Start and Session_End).

How can you loop through all controls on an ASP.NET Web form?

You can easily traverse all controls on a form via the Web Form's Controls collection. The GetType method can be used on each control to determine its type and how to work with it. Now, it gets tricky because the form contains a tree of controls; that is, some controls are contained within others (think of a Table). You would have to recursively loop through the controls to make sure everything is processed.

What is a web.config file? Machine.config?

The web.config is the basic configuration file for ASP.NET applications. It utilizes an XML format. It is used to define application settings, connection strings, and much more. These files can appear in multiple directories, and they are applied in a top-down approach; that is, configuration files apply to their container directory as well as all directories below it, but the configuration files in lower directories can override those in parent directories. This provides a way to granularly apply settings. The machine.config file contains ASP.NET settings for all of the applications on the server -- it is at the top of the configuration file hierarchy, thus web.configs can override it.

How to check Strong Password

public static bool IsPasswordStrong(string password)
{
  // Check for strong password
  return Regex.IsMatch(password, @"^(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).*$");
}


protected void cmdSubmit_Click(object sender, EventArgs e)
{
        string strtxtNewPwd = txtNewPwd.Text;
        if (IsPasswordStrong(strtxtNewPwd) == false)
        {
            errorpanel.Style.Add(HtmlTextWriterStyle.Display, "inline");
            status.Text = "Password must be atleast 8 characters long and should be a mix of atleast One Uppercase letter, One Lowercase letter and One Numeral.";
        }
        else
        {
            // Update password
        }
}



Guidelines for creating strong password 
Be at least eight characters long. Because of the way passwords are encrypted, the most secure passwords are 8 or 14 characters long.
Contain at least one character from the following three groups:

Group  Examples 
Uppercase Letters  A,B,C... 
Lowercase Letters  a,b,c... 
Numerals  0,1,2,3,4,5,6,7,8,9 

Be significantly different from prior passwords.
Not contain your name or user name.
Not be a common word or name.
Exapmle:- Password1  => (P)Uppercase, (assword)Lowercase, (1)Numeral

Encrypt and Decrypt the Password

 private string Encryptdata(string password)
    {
        string strmsg = string.Empty;
        byte[] encode = new byte[password.Length];
        encode = Encoding.UTF8.GetBytes(password);
        strmsg = Convert.ToBase64String(encode);
        return strmsg;
    }

    private string Decryptdata(string encryptpwd)
    {
        string decryptpwd = string.Empty;
        UTF8Encoding encodepwd = new UTF8Encoding();
        Decoder Decode = encodepwd.GetDecoder();
        byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
        int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
        char[] decoded_char = new char[charCount];
        Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
        decryptpwd = new String(decoded_char);
        return decryptpwd;
    }

How to check the Length of the File in c#

txtEFileUpload.PostedFile.ContentLength <= 2048000

If Condition in Design Page

<% if(Request.QueryString["id"]==null){ %>
                         <tr class="row1">
                                            <td align="left" style="width: 125px">
                                                <strong>
                                                &nbsp;Upload File</strong></td>
                                            <td align="left" colspan="2" style="width: 672px">
                                                &nbsp;<asp:FileUpload ID="txtFileUpload" runat="server" CssClass="swifttext" />
                                                </td>
                                        </tr>
                                        <%} else{%>
                                        <tr class="row1">
                                            <td align="left" style="width: 125px">
                                                <strong>
                                                &nbsp;Upload File</strong></td>
                                            <td align="left" colspan="2" style="width: 672px">
                                                <table cellpadding="0" cellspacing="0" border="0">
                                                    <tr>
                                                        <td><asp:HyperLink ID="FileList" runat="server" Target="_blank"><img src="../../Images/menu_pdf.gif" /></asp:HyperLink>
                                                        </td>
                                                        <td>
                                                            &nbsp;<asp:HyperLink ID="RemoveImg" runat="server"><img src="../../Images/del.gif" /></asp:HyperLink>
                                                            &nbsp;<asp:FileUpload ID="txtEFileUpload" Visible="false" runat="server" CssClass="swifttext" />
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <%} %>              

Message Alert

 ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Remarks is Required Field');", true);
 Response.Write("<script LANGUAGE='JavaScript' >alert('Account Success Inserted');document.location='" + ResolveClientUrl("Account.aspx") + "';</script>");

 Note:-If your Srcript manager message not show you write (return;) after script manager

Drop down List Item Value select in Gridview from backend

<asp:DropDownList Enabled="false" ID="statusdropdown" SelectedValue='<%# Eval("status") %>' runat="server">
<asp:ListItem Value="1">Active</asp:ListItem>
<asp:ListItem Value="0">Deactive</asp:ListItem>
</asp:DropDownList>

Popup window Open

<a href="ViewHeaderAuthDetails.aspx?HEADERMASTERID_IN=<%# Eval("CLEARENCEHEADERID") %>&Status=<%# Eval("STATUS") %>"
 onclick="window.open(this.href, 'AuthorityDetails', 'resizable=no,status=no,location=no,toolbar=no,menubar=no,
fullscreen=no,scrollbars=no,dependent=no,width=500,height=200'); return false;">
<img src="../../images/icon_search1.gif" />
</a>


 ScriptManager.RegisterClientScriptBlock(Page, GetType(), "View", "javascript:window.open('ExitInterviewAnswers.aspx?id=" + Resigid + "','View','scrollbars=1,center=yes,resizable=yes,STATUS=no,Width=850px,Height=550px,top=80px,left=140px')", true);

GRAPH IN ASP.NET USING THROUGH DATATABLE


                                                   
Design Page Code:


                         <asp:Chart EnableViewState="false" ID="Chart1"  runat="server"  ImageStorageMode="UseHttpHandler" Width="560" Height="400">
                                                        <Titles>
                                                            <asp:Title ShadowColor="32, 0, 0, 0"  TextStyle="Shadow" Font="Trebuchet MS, 14.25pt, style=Bold"  ForeColor="26, 59, 105">
                                                          </asp:Title>
                                                        </Titles>
                                                        <Legends>
                                                            <asp:Legend LegendStyle="Row" IsTextAutoFit="False" DockedToChartArea="ChartArea1"
                                                                Docking="Top" IsDockedInsideChartArea="False" Name="Default" BackColor="Transparent"
                                                                Font="Trebuchet MS, 8.25pt, style=Bold" Alignment="Far">
                                                            </asp:Legend>
                                                        </Legends>
                                                        <Series>
                                                            <asp:Series ChartArea="ChartArea1" IsValueShownAsLabel="true" ChartType="Column"
                                                                LegendText="Average Score" Name="Series1" LabelForeColor="#150517" BorderColor="180, 26, 59, 105"
                                                                CustomProperties="EmptyPointValue=Zero" Color="220, 65, 140, 240" IsXValueIndexed="True"
                                                                Label="#VALY" LabelToolTip="#VALX">
                                                                <EmptyPointStyle MarkerStyle="Diamond" MarkerColor="224, 64, 10"></EmptyPointStyle>
                                                            </asp:Series>
                                                         </Series>
                                                        <ChartAreas>
                                                            <asp:ChartArea Name="ChartArea1" BorderColor="64, 64, 64, 64" BackSecondaryColor="Transparent"
                                                                BackColor="64, 165, 191, 228" ShadowColor="Transparent" BackGradientStyle="TopBottom">
                                                                <AxisY LineColor="64, 64, 64, 64">
                                                                    <LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" />
                                                                    <MajorGrid LineColor="64, 64, 64, 64" />
                                                                </AxisY>
                                                                <AxisX LineColor="64, 64, 64, 64">
                                                                    <LabelStyle Font="Trebuchet MS, 8.25pt" />
                                                                    <MajorGrid LineColor="64, 64, 64, 64" />
                                                                </AxisX>
                                                            </asp:ChartArea>
                                                        </ChartAreas>
                                                    </asp:Chart>


c# code Page:

DataTable dt = objReport.OVERALLTNGEffEvalAvgScore(TRAININGNAME, STRKI, stroperation);
            if (dt.Rows.Count > 0)
            {
                Chart1.DataSource = dt;

                string titletxt="Average score of " + dp_traininglist.SelectedItem.Text;
                Chart1.Titles.Add(new Title(titletxt, Docking.Top, new Font("Trebuchet MS", 14f, FontStyle.Bold), Color.Black));

                Chart1.Series["Series1"].XValueMember = "OPERATION";
                Chart1.Series["Series1"].YValueMembers = "AVGSCORE";
                Chart1.Series["Series1"]["PointWidth"] = "0.3";

                Chart1.DataBind();
                Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
                Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = true;
                Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;
            }

 

No comments:

Post a Comment