Archive for the ‘ASP.NET C#’ Category

How to sort item using sortedlist

How to sort item using sortedlist

Imports System
Imports System.Collections
Imports System.Collections.Specialized

Public Class MainClass

Shared Sub Main(ByVal args As String())

Dim sorted_list As SortedList

sorted_list = New SortedList
sorted_list.Add(“A”, “A”)
sorted_list.Add(“a”, “B”)

For Each objItem As Object In sorted_list
Console.WriteLine(objItem)
Next obj

End Sub
End Class

Advertisements

namespace javascriptserializer could not be found

JavaScriptSerializer is situated in System.Web.Extensions Assembly. You should add it to your project references using add reference option.

Make JSON data using JavaScriptSerializer in asp.net

using System.Net;
using System.Text;
using System.IO;
using System.Data;
using System.Web.Script.Serialization;

string json = new JavaScriptSerializer().Serialize(new
{
empid = eid,
empname = ename,
empsalary = salary
});

Send Json Data to Webservice and get response from Webservice

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Text;
using System.IO;
using System.Data;
using System.Web.Script.Serialization;

 

string url =”http://abc.com”;

var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = “application/json”;
httpWebRequest.Method = “POST”;

using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = new JavaScriptSerializer().Serialize(new
{
empid = “1001”,
empname = “test name”,
empsalary= “10000”
});

streamWriter.Write(json);
}

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}

Print Html page using javascript in asp.net

function printpage() {
//Get the print button and put it into a variable
var printButton = document.getElementById(“printbtn”);
//Set the print button visibility to ‘hidden’
printButton.style.visibility = ‘hidden’;
//Print the page content
window.print()
//Set the print button to ‘visible’ again
//[Delete this line if you want it to stay hidden after printing]
printButton.style.visibility = ‘visible’;
}

 

<input id=”printbtn” type=”button” value=”Print page” onclick=”printpage()”/>

 

Read Resulting HTML Page code in asp.net

Add below mention assembly in your project.

using System.Net;
using System.Text;

try

{

WebClient myClient = new WebClient();

string myPageHTML = null;

byte[] requestHTML;

string currentPageUrl = “https://abcd1212.com/webpage.aspx&#8221;;

UTF8Encoding utf8 = new UTF8Encoding();

requestHTML = myClient.DownloadData(currentPageUrl);

myPageHTML = utf8.GetString(requestHTML);

Response.Write(myPageHTML);

}

catch (Exception ex)

{

}

If you like this post, request you to put your comment.

 

Call Button server event on enter key pressed in password textbox

<html>
<head>
http://../JQuery/jquery-1.7.2.js

$(document).ready(function () {
$(‘#txtPassword’).keypress(function(e)
{
var key = e.which;
if(key == 13)
{
//$(‘#btnSubmit’).click();
$(“#btnSubmit”)[0].click();
//alert(‘hi1’);
//return false;
}
});

});

</head>
<body>
<form id=”form1″ runat=”server”>
<fieldset>

 <asp:TextBox ID=”txtUser” runat=”server” class=”form-control” placeholder=”UserID”
MaxLength=”8″></asp:TextBox>
<asp:TextBox ID=”txtPassword” runat=”server” class=”form-control” placeholder=”Password”
TextMode=”Password”></asp:TextBox>
<asp:LinkButton ID=”btnSubmit” runat=”server” class=”btn btn-bricky pull-right”>Login <i class=”fa fa-arrow-circle-right”></i> </asp:LinkButton>

</fieldset>
</form>
</body>

</html>