Monday, 7 December 2009

ASP .NET: How to get parameter in url ( by C# for .net)

if (Request.QueryString["param1"] != null) Response.Write("From Page1 param1 value=" + Request.QueryString["param1"]);

Tuesday, 1 December 2009

ASP .NET: Refresh page every x secs

Examples
Place inside <~head~> to refresh page after 5 seconds:
<~meta http-equiv="refresh" content="5" /~>
Redirect to http://example.com/ after 5 seconds:
<~meta http-equiv="refresh" content="5;url=http://example.com/" /~>
Redirect to http://example.com/ immediately:
<~meta http-equiv="refresh" content="0;url=http://example.com/" /~>

http://en.wikipedia.org/wiki/Meta_refresh

Friday, 27 November 2009

ASP .NET setting up mail server (SMTP)

If server is unsecure dont need SMTP credentials or SSL enabled.

For example if using google:
SMTP = smtp.gmail.com
credentialsUN = johnilett@gmail.com
credentialsPW = YOURPASSWORD
returnEmail = noreply@gmail.com - Dummy

using System.Net.Mail;

protected void mail(string email, string name)
{
getCredentials();
MailMessage mail = new MailMessage();

mail.To.Add(email);

mail.From = new MailAddress(credentialsUN);
mail.ReplyTo = new MailAddress(credentialsUN);

mail.Subject = "HR DW Website Password";

mail.IsBodyHtml = true;

string Body = "<~html~><~/body~>Dear " + name + "," + "<~br /~>" + "<~br /~>" + "Your password for the HR DW website is: " + "" + "<~b~>" + password + "<~/b~>";
Body += "<~br /~>" + "<~br /~>" + "Thanks," + "<~br /~>" + "HR DW Support.<~/body~><~/html~>";

mail.Body = Body;

SmtpClient smtp = new SmtpClient();

smtp.Host = credentialsSMTP;

//Dont need these 2 if unsecure SMTP
smtp.Credentials = new System.Net.NetworkCredential(credentialsUN, credentialsPW);
smtp.EnableSsl = true;

smtp.Send(mail);

}

*replace ~ with ""

asp .net: Creating NameSpace

Step 1: Creating Namespace class in App_Code (cs or vb)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace YOURNAMESPACENAME
{
///
/// Summary description for of Class
///

public class YOURCLASSNAME
{
//METHODS AND VALUES - PUBLIC
}
}

Step 2: Calls your namespace in aspx.cs class

using YOURNAMESPACENAME;

create new object in Main class for YOURCLASSNAME -
YOURCLASSNAME ClassName = new YOURCLASSNAME ();

Now call your methods and values, etc:
ClassName.MethodName()

Wednesday, 11 November 2009

ASP: gridview delete confirmation box



...


OnClientClick='return confirm("Are you sure you want to delete this entry?");'
Text="Delete" />



Tuesday, 3 November 2009

Javascript: Confirm logout and save document

function closeWindow() {
if (confirm('Are you sure you would like to logout?')) {
//document.forms['form1'].submit();
window.open('', '_self');
window.close();
};
}

Friday, 30 October 2009

SQL: Try Catch

EG1:BEGIN TRY
-- Table does not exist; object name resolution
-- error not caught.
SELECT * FROM NonexistentTable;
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_MESSAGE() AS ErrorMessage;
END CATCH



EG2:CREATE PROCEDURE usp_ExampleProc
AS
SELECT * FROM NonexistentTable;
GO

BEGIN TRY
EXECUTE usp_ExampleProc;
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber
,ERROR_MESSAGE() AS ErrorMessage;
END CATCH;