Advertisement

ASP.NET Interview Questions and Answers

ASP.NET > ASP.NET
Advertisements
Posted by Admin | Posted on Mon, 10 Oct 2016
ASP.NET is a webapplication development framework designed/developed by Microsoft, to help developers to build dynamic websites, webservices, modules. ASP.NET web application mostly written using C# or VB programming language, these languages are server side scripting language and execution will be done from ASP.NET Server. ASP.NET compiles the asp.net pages and provides better performance than classic ASP. There are several options available in ASP.NET like page output cache, fragment cache, etc., to make the pages load more faster.

Posted by Admin | Posted on Tue, 25 Oct 2016
protected void BindGridView()
{
    DataSet dts = new DataSet();
    using(SqlConnection conn = new SqlConnection("Data Source=DBServerName;Integrated Security=true;Initial Catalog=DBName"))
    {
      conn.Open();
        SqlCommand cmd = new SqlCommand("select * from table1", conn);
      SqlDataAdapter adap = new SqlDataAdapter(cmd);
      adap.Fill(dts);
      conn.Close();
      GridView1.DataSource = dts;
      GridView1.DataBind();
    }
}

Posted by Admin | Posted on Wed, 26 Oct 2016
protected void BindDropDownList()
{
    DataSet dts = new DataSet();
    using(SqlConnection conn = new SqlConnection("Data Source=DBServerName;Integrated Security=true;Initial Catalog=DBName"))
    {
      conn.Open();
        SqlCommand cmd = new SqlCommand("select * from table1", conn);
      SqlDataAdapter adap = new SqlDataAdapter(cmd);
      adap.Fill(dts);
      conn.Close();
      DropDownList1.DataSource = dts;
      DropDownList1.DataTextField = "Column1"; //column1 shows list of options
      DropDownList1.DataValueField = "ColumnIDfield";  //for internal reference
      DropDownList1.DataBind();
    }
}

Posted by Admin | Posted on Wed, 26 Oct 2016
Here it is:
Datatable1.Columns.Add("NewColName", typeof(string), "Column1+'-'+ Column2");

Posted by Admin | Posted on Thu, 27 Oct 2016
Example 1)   String.Format("This is my {0} book.", "Physics");
Example 2)   String.Format("These are my {0} {1} books.", "Physics","Chemistry");

Output :
1) This is my Physics book.
2) These are my Physics Chemistry books

Posted by Admin | Posted on Thu, 27 Oct 2016
Example:
int a = 575;

string x = a.ToString()
or
string x = Convert.ToString(a);


Posted by Admin | Posted on Thu, 27 Oct 2016
>>  .ToString() will to convert to string and incase of null gives error.
>>  Convert.ToString() will convert to string and incase of null value it return null.

Posted by Admin | Posted on Tue, 01 Nov 2016
SmtpClient objEmail = new SmtpClient("mailserver.domainname.com", 27);

objEmail.Credentials = new System.Net.NetworkCredential("mailid@domainname.com", "passwrd");
//or
//pass default credential
objEmail.UseDefaultCredentials = true;

//based on need
objEmail.EnableSsl = true;

//delivery method
objEmail.DeliveryMethod = SmtpDeliveryMethod.Network;

MailMessage mail = new MailMessage();
mail.From = new MailAddress("admin@domainname.com", "Subject title");
mail.To.Add(new MailAddress("testuser@anotherdomain.com"));

objEmail.Send(mail);


Recent Updates

  • PowerShell script to set list threshold value at Web Application level
    Here is the script snippet on using Powershell how to update listview threshold value at web application level

    Step1: Open SharePoint powershell management window as administrator

    Step2: Type the below script one by one or execute as PS1 file.

    $wa = Get-SPWebApplication "http://servername:portno/"
    $wa.MaxItemsPerThrottledOperation = 10000
    $wa.MaxItemsPerThrottledOperationOverride = $true
    $wa.HttpThrottleSettings.Update()
    $wa.Update()

    Thats it..!!
  • How to show a element or control using CSS ?
    HTML Code
    <div id="divContainer" class="clsContainer">lorum epsum lorum epsum lorum epsum lorum epsum lorum epsum lorum epsum lorum epsum lorum epsum lorum epsum lorum epsum lorum epsum </div>

    CSS
    css to hide the div element using ID is like below

    <style>
    #divContainer
    {
       display: block;
    }
    </style>

    css to hide the div element using class name is like below

    <style>
    .clsContainer
    {
       display: block;
    }
    </style>
  • How to hide a element or control using CSS ?
    HTML Code
    <div id="divContainer" class="clsContainer">lorum epsum lorum epsum lorum epsum lorum epsum lorum epsum lorum epsum lorum epsum lorum epsum lorum epsum lorum epsum lorum epsum </div>

    CSS
    css to hide the div element using ID is like below

    <style>
    #divContainer
    {
       display: none;
    }
    </style>

    css to hide the div element using class name is like below

    <style>
    .clsContainer
    {
       display: none;
    }
    </style>
  • How to read SharePoint 2013 List Items using REST API and javascript ajax method?
    Here it is:

    //Main method to consume REST API
    function GetListDataUsingRESTapi() {

        var strListName = 'ListName';
        var listUrl = url + "/_api/lists/getbytitle('" + strListName + "')/Items?$top=10000";
        $.ajax({
            url: listUrl,
            method: "GET",
            headers: {
                "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose"
            },
            success: retrieveSuccess,
            error: retrieveError
        });
    }

    //Success method to iterate retrieved items
    function retrieveSuccess(data) {
        var results = JSON.stringify(data.d.results);
        results = JSON.parse(results);
        if (results.length > 0) {
            for (var i = 0; i < results.length; i++) {
                var resultTitle = results[i].Title;
                var anotherCol1 = results[i].Colname1;
            }
        }
    }

    //failure method to get error message returned from REST API
    function retrieveError(request, status, error)
    {
        console.log(error);
    }
  • How to send Email in ASP.NET ?
    SmtpClient objEmail = new SmtpClient("mailserver.domainname.com", 27);

    objEmail.Credentials = new System.Net.NetworkCredential("mailid@domainname.com", "passwrd");
    //or
    //pass default credential
    objEmail.UseDefaultCredentials = true;

    //based on need
    objEmail.EnableSsl = true;

    //delivery method
    objEmail.DeliveryMethod = SmtpDeliveryMethod.Network;

    MailMessage mail = new MailMessage();
    mail.From = new MailAddress("admin@domainname.com", "Subject title");
    mail.To.Add(new MailAddress("testuser@anotherdomain.com"));

    objEmail.Send(mail);
 

Happy Reading.. Happy Programming :)