Showing posts with label programming tips. Show all posts
Showing posts with label programming tips. Show all posts

301 redirect "/Default.aspx" to "/" Root Asp.Net


Sunday, October 30, 2011

Question : How to use global.asax and do 301 redirect "/Default.aspx" to "/" Root ?
Answer :

Add below code in global.asax, thats it.


void Application_BeginRequest(object sender, EventArgs e)
    {
        if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://induway.com"))
        {
            HttpContext.Current.Response.Status = "301 Moved Permanently";
            HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("http://induway.com/default.aspx", "http://www.induway.com"));
        }
    }



Let me know, if you have any query..


Thanks Hope this post will help you, if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Email: raj143svmit@gmail.com
Dobazaar (Dubai, UAE)
www.dobazaar.com

Alpha Numeric And Few Special Character Allowed Validation


Wednesday, August 3, 2011

Hello Friends,

jQuery provides you alphanumeric validation or only Special Character validation, below code will help you validate your textbox with alphanumeric and also allow few special character, you can see regex pattern below, you can add your special character which you want to allow..you can also see live demo by entering your text in below textbox.. 


Demo



Enter Name :


Note : Few character allowed (!,\-,.,&,*,#,@,/)




<html>
<head>
<title>jQuery test page</title>
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>

<script type="text/javascript">
function loadContent() {

            if(validate()){
            document.getElementById('error').innerHTML="Validate Success.";
            document.getElementById("error").setAttribute("style", "color:Green;"); 
            }
            else{
            document.getElementById('error').innerHTML="Not Validate, its wrong.";
            document.getElementById("error").setAttribute("style", "color:Red;"); 
            }
}

function validate()
{
    return /^([a-zA-Z 0-9]([a-zA-Z 0-9\s\[\]\!\(\)\-\.\&\*\#\@/\\(/)/)])+$)/.test(document.getElementById('txtcheck').value);
}
</script>
</head>
<body>
Enter Name : <input type="text" id="txtcheck" onblur="loadContent()" />
<span id="error"></span><br />
Note : Few character allowed (!,\-,.,&,*,#,@,/)
</body>
</html>





Thanks
Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Senior Asp.Net Developer
Email: raj143svmit@gmail.com
e-Procurement Technologies Ltd (India)
www.abcprocure.com

Solved : Cannot load the DLL xp_md5.dll


Monday, May 23, 2011

Issue : "Cannot load the DLL xp_md5.dll, or one of the DLLs it references. Reason: 126(The specified module could not be found.)."


Solution :

You are missing one dll to keep in this folder "D:\Program Files\Microsoft SQL Server\100\Tools\Binn\ "

You can download that file from here
http://download555.mediafire.com/3hw61lrj9njg/ki2omn4dzjm/xp_md5.dll.rar


Then keep this file in folder "D:\Program Files\Microsoft SQL Server\100\Tools\Binn\"

Then open your sql server and run this sql query so that you can register this dll in sql server.


xp_md5.dll

USE [master]
GO

EXEC dbo.sp_addextendedproc N'xp_md5', 'D:\Program Files\Microsoft SQL Server\100\Tools\Binn\xp_md5.dll'
 
GO


Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Senior Asp.Net Developer
Email: raj143svmit@gmail.com
e-Procurement Technologies Ltd (India)
www.abcprocure.com

Validate Datetime with current Datetime using jQuery


Thursday, January 27, 2011

Suppose you want to validate both Date i.e with time and without time with current date and time,
that is, selected data should be greater that current date.

with time
27/01/2011 13:01

without time
27/01/2011

Below is the fuction, you can make use of it and you can check that selected date and time is greater or lesser than current date and time.

This function will return true and false,

if selected date is less than current date and time, then it will return false, else it will return true.




function CompareToForToday(value,params)
            {
               if(value!='')
        {
                    var mdy = value.split('/')     //Date and month split
                    var mdyhr= mdy[2].split(' ');  //Year and time split
                   
                    
                    if(mdyhr[1] == undefined){
                        var valuedate= new Date(mdyhr[0], mdy[1]-1, mdy[0]);
                    }
            else
                    {
                        var mdyhrtime=mdyhr[1].split(':');
                        var valuedate= new Date(mdyhr[0], mdy[1]-1, mdy[0], mdyhrtime[0], mdyhrtime[1]);
                    }

                    var d = new Date();
                    if(mdyhr[1] == undefined){
                        var todaydate = new Date(d.getFullYear(), d.getMonth(), d.getDate());
                    }
                    else
                    {
                        var mdyhrtime=mdyhr[1].split(':');
                        var todaydate = new Date(d.getFullYear(), d.getMonth(), d.getDate(),d.getHours(),d.getMinutes());
                    }

                    return Date.parse(valuedate) > Date.parse(todaydate);
                }
                else
                {
                    return true;
                }
            }



Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Senior Asp.Net Developer
Email: raj143svmit@gmail.com
e-Procurement Technologies Ltd (India)
www.abcprocure.com

How to bind Datalist control from code behind ?


Wednesday, May 26, 2010

Solution :

This blog will explain you, how you can bind Datalist control from code behind.
First you need to add Datalist control in .aspx file, you can do this by draging the control form the toolbox or you can past e the below code in .aspx file.

Then you need to bind this control from the database, you can do this by assigning Datasource of control to dataset, find code for this also below.


Place below code in HTML file.

<asp:DataList ID="dlPhotos" runat="server" RepeatColumns="3" CellSpacing="0" CellPadding="5"
            RepeatDirection="Horizontal" Width="100%">
            <ItemStyle VerticalAlign="Top" />
            <ItemTemplate>
                <table cellspacing="0" cellpadding="0" width="100%" border="0" align="center">
                    <tr>
                        <td align="center" class="cellheightfifteen">
                            <a id="lnk<%#Container.DataItem("iProductImageID")%>" href="javascript:void(0)" 

onclick="removePhoto('<%=Application("SiteURL")%>ajaxopes.aspx','<%#Container.DataItem("iProductImageID")%>','<%#container.da

taitem("sImageFileName")%>')">
                                Remove Photo </a><span class="redlink" id="spn<%#Container.DataItem("iProductImageID")%>"
                                    style="display: none;"></span>
                        </td>
                    </tr>
                    <tr>
                        <td class="heightfive">
                        </td>
                    </tr>
                    <tr>
                        <td align="center">
                            <table id="tbl<%#Container.DataItem("iProductImageID")%>" 

width="<%=Application("THUMBIMAGEWIDTH") + 10%>"
                                height="<%=Application("THUMBIMAGEHEIGHT") + 10%>" border="0" cellspacing="0"
                                cellpadding="0" class="tblbox1">
                                <tr>
                                    <td align="center" id="tdImage" runat="server">
                                        <img 

src='<%=Application("SiteURL")%>Images/ThumbleImages/<%#container.dataitem("sImageFileName")%>?<%=now.tostring%>'
                                            alt='Loading...' />
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" class="cellheightfifteen">
                            <input type="radio" id="opt<%#Container.DataItem("iProductImageID")%>" name="rdPhoto"
                                onclick="setPhotoId('<%#Container.DataItem("iProductImageID")%>')" />
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:DataList>



Place below code in Code behind.

Code in VB.Net

If Not dsImage Is Nothing Then
       If dsImage.Tables(0).Rows.Count > 0 Then
          dlPhotos.DataSource = dsImage
          dlPhotos.DataBind()
       End If
End If

OR

Code in C#.Net

if ((dsImage != null)) 
{
        if (dsImage.Tables(0).Rows.Count > 0) 
    {
            dlPhotos.DataSource = dsImage;
            dlPhotos.DataBind();
        }
}


Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)
rajesh@indianic.com


Populate Datagrid control using Stored Procedure.




Please follow below steps.

Step 1: Create Stored Procedure, see below code and modify according to your need.

CREATE PROCEDURE [dbo].[GetProducts] 
   (
       @CategoryID int
   ) 
AS
SELECT ProductID, ProductName FROM Products WHERE CategoryID = @CategoryID

Step 2: Please see below code and explaination for each line.

Complete Code

SqlConnection conn = new SqlConnection("Data 
Source=localhost;Database=Northwind;Integrated Security=SSPI");
SqlCommand command = new SqlCommand("GetProducts", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@CategoryID", SqlDbType.Int).Value = 1;
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds, "Products");
dataGrid1.DataSource = ds;
dataGrid1.DataMember = "Products";


Explanation of above code line by line

Make sqlconnection using your connectionstring
SqlConnection conn = new SqlConnection("Data 
Source=localhost;Database=MyDB;Integrated Security=SSPI");

Declare sqlcommand and pass your Stored Procedure name and make connection to it.
All pass all the parameter to Stored Procudure.
SqlCommand command = new SqlCommand("GetProducts", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@CategoryID", SqlDbType.Int).Value = 1;

Declare sqldataadapter and assign command to this,
SqlDataAdapter adapter = new SqlDataAdapter(command);

Declare dataset and fill dataset using sqldataadapter and table name "Products".
DataSet ds = new DataSet();
adapter.Fill(ds, "Products");

Fill datagrid by dataset ds,
dataGrid1.DataSource = ds;
dataGrid1.DataMember = "Products";

Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)
rajesh@indianic.com




Insert Form data in database using Stored Procedure




Please follow below steps.

Step 1: Create Stored Procedure, see below code and modify according to your need.

CREATE PROCEDURE [dbo].[InsertUser] (
    @User varchar(50),
    @Pass varchar(50)
) AS
INSERT INTO Users VALUES(@Username, @Password)

Step 2: Please see below code and explaination for each line.

Complete Code

string user = ... // get username from user
string pass = ... // get password from user

SqlConnection conn = new SqlConnection("Data 
Source=localhost;Database=MyDB;Integrated Security=SSPI");
SqlCommand command = new SqlCommand("InsertUser", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@User", SqlDbType.VarChar).Value = user;
command.Parameters.Add("@Pass", SqlDbType.VarChar).Value = pass;
conn.Open();
int rows = command.ExecuteNonQuery();
conn.Close();

Explanation of above code line by line

Assign your text box value to this variables
string user = ... // get username from user
string pass = ... // get password from user

Make sqlconnection using your connectionstring
SqlConnection conn = new SqlConnection("Data 
Source=localhost;Database=MyDB;Integrated Security=SSPI");

Declare sqlcommand and pass your Stored Procedure name and make connection to it.
All pass all the parameter to Stored Procudure.
SqlCommand command = new SqlCommand("InsertUser", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@User", SqlDbType.VarChar).Value = user;
command.Parameters.Add("@Pass", SqlDbType.VarChar).Value = pass;

Open connection to database and run your store procedure, thus you can insert your form data to database succussfully.
conn.Open();
int rows = command.ExecuteNonQuery();
conn.Close();

Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)
rajesh@indianic.com



How to get @@Identity after insert operation in Access Database


Saturday, March 20, 2010

Solution :

I am going to explain this in Vb.Net.

Create one vb.net project and add one from frmAddContact.vb in your project.
and take one button and txtbox in that form.

Create Dataaccesslayer class file with name, DAL.vb

and add below code to respective files, please find the code below.


frmAddContact.vb

Dim ObjDataAccess As New DAL()
Public Class frmAddContact
Dim ObjDataAccess As New DAL()

Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click

Dim iRelationID As New Integer
iRelationID = ObjDataAccess.ExecuteNonQueryGetIdentity("INSERT INTO PAM_Relationship ( tRelationshipName,dCreatedDate,dModifiedDate) VALUES ('" & _
cmbrelationship.Text.Trim() & "',#" & _
Date.Now & "#,#" & _
Date.Now & "# )")

End Sub
End Class





DAL.vb

Imports System.Data.SqlClient
Imports System.Data
Imports System.Data.OleDb

Public Class DAL
Dim ConnStr As String = Configuration.ConfigurationSettings.AppSettings("DBConn").ToString()

Public Function ExecuteNonQueryGetIdentity(ByVal Query As String) As Integer

Dim iResult As Integer
Try
Dim Conn As New OleDb.OleDbConnection(ConnStr)
Conn.Open()
Dim cmd As New OleDb.OleDbCommand(Query, Conn)

cmd.ExecuteNonQuery()
cmd.CommandText = "Select @@Identity"
iResult = cmd.ExecuteScalar()
Conn.Close()
cmd.Dispose()
Catch ex As Exception
ex = Nothing
End Try

Return iResult
End Function

End Class


After insert operation, when you will check the value of return value of iRelationID, you will find the inserted row id.


Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)
rajesh@indianic.com


.

Failed to retrieve data for this request Error in SQL Server


Saturday, February 6, 2010

SomeTimes after formating your computer, when you install sql server 2008.

When you try to connect your database and click on database menu to see the list of database, you will find windows alert showing you this below error.




Microsoft SQL Server Management Studio

Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)

Additional information:

An exception occurred while executing a Transact-SQl statement or batch.(Microsoft.SqlServer.COnnectionInfo)

The server principal "DatabaseName" is not able to access the database "Birdiethis" under the current security context. (Microsoft SQL Server, Error:916)




Please read below to find, how to solve this problem,

There is nothing to worry about, mostly user use to uninstall sqlserver software and install it again. then also they feel same problem.

Follow this steps :

Step 1: Open your sql server 2008,connect to database.

Step 2: click on view option for the top menu panel,then click to Object Explorer Details,



Step 3: You will see a panel will open at the right hand side,

Step 4: Right click on the header part of that panel, and unselect all option, as shown in the image,



Step 5: This will solve that issue, and you can use sql server 2008 without any error.

That's it,


Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)
rajesh@indianic.com

How to stop right clicking of mouse on my web page ?


Monday, November 23, 2009

You can just put single line code in body tag, to stop copy your website content and copy your image.

Here is the code

<BODY oncontextmenu="return false">


Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)
rajesh@indianic.com

Explaination of flow of Authorize.net Payment Gateway


Wednesday, October 14, 2009

In this post, I have explained you step by step implementation of authorize.net payment gateway integration in your website and explained you what happen behind the screen in payment gateway processing.


Explanation of Step 1


Step 1: The merchant submits a credit card transaction to the Authorize.Net Payment
Gateway on behalf of a customer via secure Web site connection, retail store, MOTO
center or wireless device.


Explanation of Step 2


Step 2: Authorize.Net receives the secure transaction information and passes it via a secure connection to the Merchant Bank's Processor.


Explanation of Step 3


Step 3: The Merchant Bank's Processor submits the transaction to the Credit Card Network (a system of financial entities that communicate to manage the processing, clearing, and settlement of credit card transactions).


Explanation of Step 4


Step 4: The Credit Card Network routes the transaction to the Customer's Credit Card Issuing Bank

Explanation of Step 5

Step 5: The Customer's Credit Card Issuing Bank approves or declines the transaction based on the customer's available funds and passes the transaction results back to the Credit Card Network.


Explanation of Step 6


Step 6: The Credit Card Network relays the transaction results to the Merchant Bank's Processor.

Explanation of Step 7


Step 7: The Merchant Bank's Processor relays the transaction results to Authorize.Net.


Explanation of Step 8


Step 8: Authorize.Net stores the transaction results and sends them to the customer and/or the merchant. This step completes the authorization process – all in about three seconds or less!


Explanation of Step 9


Step 9: The Customer's Credit Card Issuing Bank sends the appropriate funds for the transaction to the Credit Card Network, which passes the funds to the Merchant's Bank. The bank then deposits the funds into the merchant's bank account. This step is known as the settlement process and typically the transaction funds are deposited into your primary bank account within two to four business days.




Hope this post has helped you,
If yes, Please put a comment below to encourage us.
Thank you

Rajesh Singh,
Indianic Infotech Ltd
rajesh@indianic.com