Skip to content

Instantly share code, notes, and snippets.

View smetronic's full-sized avatar

Alexander Sikandar smetronic

View GitHub Profile
@smetronic
smetronic / code02.cs
Created November 15, 2016 11:01
ExecuteNonQuery
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString))
{
connection.Open();
using (SqlCommand cmd = new SqlCommand(@"SELECT * FROM Table WHERE Id = @Input", connection))
{
cmd.Parameters.Add("Input", SqlDbType.Int).Value = 1;
cmd.ExecuteNonQuery();
}
@smetronic
smetronic / code03.cs
Created November 15, 2016 12:14
Calculate a MD5 hash from a string
// given, a password in a string
string password = @"1234abcd";
// byte array representation of that string
byte[] encodedPassword = new UTF8Encoding().GetBytes(password);
// need MD5 to calculate the hash
byte[] hash = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(encodedPassword);
// string representation (similar to UNIX format)
@smetronic
smetronic / code04.cs
Created November 15, 2016 12:25
Access session variables from any page
public class MySession
{
// private constructor
private MySession()
{
Property1 = "default value";
}
// Gets the current session.
public static MySession Current
@smetronic
smetronic / code05.cs
Created November 19, 2016 09:50
Calling JavaScript Function From CodeBehind
Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction","MyFunction()",true);
@smetronic
smetronic / gist:dc9fbe07bbf5331d6489b75cbd74b9e3
Created November 19, 2016 10:01
Calling JavaScript Function From CodeBehind; Register script block
ScriptManager.RegisterStartupScript(this, this.GetType(), "CallMyFunction", "MyFunction();", true);
@smetronic
smetronic / Default.aspx
Created December 3, 2016 06:21
Calling ASP.Net Page Method using jQuery AJAX
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Ajax.Default" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
</head>
<body>
@smetronic
smetronic / file.cs
Created December 3, 2016 06:46
Using ConfigurationManager
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
namespace browser
{
public partial class Default : System.Web.UI.Page
@smetronic
smetronic / code06.cs
Created December 3, 2016 07:01
Retrieving data from database using SqlDataReader
var result = "";
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString))
{
connection.Open();
using (SqlCommand cmd = new SqlCommand(@"SELECT * FROM Table WHERE Id = @Input", connection))
{
cmd.Parameters.Add("Input", SqlDbType.Int).Value = 1;
<asp:Repeater ID="categoryRP" runat="server">
<ItemTemplate>
<tr>
<td>
<asp:Label ID="Id" runat="server" Text='<%# Eval("Id") %>' />
</td>
<td>
<asp:Label ID="Name" runat="server" Text='<%# Eval("Name") %>' />
</td>
<td>
@smetronic
smetronic / CookieConsentAttribute.cs
Created October 17, 2017 16:26 — forked from Maarten88/CookieConsentAttribute.cs
ASP.NET ActionFilterAttribute to help implement european cookie-law
/*
* ASP.NET ActionFilterAttribute to help implement EU Cookie-law
* MIT Licence (c) Maarten Sikkema, Macaw Nederland BV
*/
using System;
using System.Web;
using System.Web.Mvc;
namespace Auction.Web.Utility