Friday, 28 December 2012

compare validation in gridview asp.net


I did a sample for :

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false"OnRowDataBound="GridView1_RowDataBound">
        <Columns>
          <asp:TemplateField HeaderText="Start Date">
            <ItemTemplate>
              <asp:Label runat="server" ID="Label1" Text='<%# Eval("StartDate") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
              <asp:TextBox runat="server" ID="TextBox1" Text='<%# Eval("StartDate","{0:d}")  %>'></asp:TextBox>
            </EditItemTemplate>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="End Date">
            <ItemTemplate>
              <asp:Label runat="server" ID="Label2" Text='<%# Eval("EndDate") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
              <asp:TextBox runat="server" ID="TextBox2" Text='<%# Eval("EndDate","{0:d}") %>'></asp:TextBox>
            </EditItemTemplate>
          </asp:TemplateField>
          <asp:CommandField ShowEditButton="true" />
        </Columns>
</asp:GridView>

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowState == DataControlRowState.Edit)
        {
            CompareValidator cv = new CompareValidator();
            e.Row.Cells[1].Controls.Add(cv);
            cv.ControlToValidate = "TextBox2";
            cv.Type = ValidationDataType.Date;
            cv.Operator = ValidationCompareOperator.GreaterThan;
            cv.ErrorMessage = "End date should be later than start date!";
            cv.ValueToCompare = ((TextBox)e.Row.FindControl("TextBox1")).Text;
        }
    }

You can change index or anything as your real situation.

refer from asp.net forum

Validation - CustomValidator in asp.net

If none of the other validators can help you, the CustomValidator usually can. It doesn't come with a predefined way of working; you write the code for validating your self. This is of course very powerful, since the possibilities are basically endless. A common way of using the CustomValidator is when you need to make a database lookup to see if the value is valid. Since this tutorial hasn't treated database access yet, we will do a simpler example, but hopefully you will see that you can do just about everything with the CustomValidator. The control allows you to validate both clientside and serverside, where the serverside approach is probably the most powerful. Of course, doing serverside validation requires a postback to validate, but in most cases, that's not really a problem. 

In this example, we will simply check the length of the string in the TextBox. This is a very basic and that useful example, only made to show you how you may use the CustomValidator.


Custom text:<br />
<asp:TextBox runat="server" id="txtCustom" />
<asp:CustomValidator runat="server" id="cusCustom" controltovalidate="txtCustom" onservervalidate="cusCustom_ServerValidate" errormessage="The text must be exactly 8 characters long!" />
<br /><br />


As you can see, it's pretty simple. The only unknown property is the onservervalidate event. It's used to reference a method from CodeBehind which will handle the validation. Switch to our CodeBehind file and add the following method:
protected void cusCustom_ServerValidate(object sender, ServerValidateEventArgs e)
{
    if(e.Value.Length == 8)
        e.IsValid = true;
    else
        e.IsValid = false;
}
This is very simple. The validator basically works by setting the e.IsValid boolean value to either true or false. Here we check the e.Value, which is the string of the control being validated, for it's length. If it's exactly 8 characters long, we return true, otherwise we return false. 

Although the serverside approach is probably the most powerful, you need to consider your site hosting, especially if your database receives plenty of queries. 


Properties






Example

CustomValidator
Declare two Label controls, one TextBox control, one Button control, and one CustomValidator control in an .aspx file. The user() function checks the length of the input value. If the length is <8 or >16 the text "A username must be between 8 and 16 characters!" will appear in the CustomValidator control.







Could not load file or assembly 'DotNetOpenAuth.AspNet' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Add this reference on the flow

1)DotNetOpenAuth.AspNet.dll
2)DotNetOpenAuth.Core.dll
3)DotNetOpenAuth.Core.UI.dll
4)DotNetOpenAuth.InfoCard.dll
5)DotNetOpenAuth.OAuth.Common.dll
6)DotNetOpenAuth.OAuth.Consumer.dll
7)DotNetOpenAuth.OAuth.dll
7)DotNetOpenAuth.OpenId.dll
8)DotNetOpenAuth.ServiceProvider.dll

This all reference was must be version in 4.1


and build  your applications,load this dll in Bin folder .then run

Thursday, 27 December 2012

How to Login With SQL Server Database with VB(or C#) Language

The following example demonstrates how to use a Login control to provide a user interface to log on to a Web site with sql server database. VB : Imports System.Data , Imports System.Data.SqlClient and Imports System.Web.Configuration , C# : using System.Data; , using System.Data.SqlClient; and using System.Web.Configuration;

User Name: aspxcode , Password: 2008

   1. xml file or web.config


<?xml version="1.0"?>

  <configuration>

<connectionStrings>
 <add name="ConnectionASPX" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Northwind.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

  </configuration>


2. how-to-login-with-sql-server.aspx (Design Page)
Login Coltrol ASP.NET
3. how-to-login-with-sql-server.aspx (Source Page)


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="how-to-login-with-sql-server.aspx.vb" Inherits="how_to_login_with_sql_server" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>how to login with sql server database</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
         <asp:Login ID="Login1" runat="server" BackColor="#FFFBD6" BorderColor="#FFDFAD" BorderPadding="4"
            BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em"
            ForeColor="#333333" OnAuthenticate="Login1_Authenticate" TextLayout="TextOnTop"
            Width="293px" 
               Height="172px">
            <TitleTextStyle BackColor="#990000" Font-Bold="True" Font-Size="0.9em" 
                   ForeColor="White" />
            <InstructionTextStyle Font-Italic="True" ForeColor="Black" />
            <TextBoxStyle Font-Size="0.8em" />
            <LoginButtonStyle BackColor="White" BorderColor="#CC9966" BorderStyle="Solid" BorderWidth="1px"
                Font-Names="Verdana" Font-Size="0.8em" ForeColor="#990000" />
        </asp:Login>
    
    </div>
    </form>
</body>
</html>


4. how-to-login-with-sql-server.aspx.vb (Code Behind VB Language)

Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration
Partial Class how_to_login_with_sql_server
    Inherits System.Web.UI.Page

    Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
        Dim username As String
        Dim pwd As String
        Dim pName As String

        username = Login1.UserName
        pwd = Login1.Password
        pName = ""
        Dim strConn As String
        strConn = WebConfigurationManager.ConnectionStrings("ConnectionASPX").ConnectionString

        Dim Conn As New SqlConnection(strConn)
        Conn.Open()


        Dim sqlUserName As String
        sqlUserName = "SELECT UserName,Password FROM UserName "
        sqlUserName &= " WHERE (UserName = @UserName"
        sqlUserName &= " AND Password = @Password)"

        Dim com As New SqlCommand(sqlUserName, Conn)
        com.Parameters.AddWithValue("@UserName", username)
        com.Parameters.AddWithValue("@Password", pwd)


        Dim CurrentName As String
        CurrentName = CStr(com.ExecuteScalar)

        If CurrentName <> "" Then
            Session("UserAuthentication") = username

            Response.Redirect("how-to-StartPage.aspx")
        Else
            Session("UserAuthentication") = ""
        End If

    End Sub
End Class

5. how-to-login-with-sql-server.aspx (View in Browser)
Login Coltrol ASP.NET
Login Coltrol ASP.NET

Convert to C#


refer from:http://www.aspxcode.net

The SMTP server requires a secure connection or the client was not authenticated error while sending email from asp.net

I am trying to send an email from my asp.net application, the function worked fine on my machine, but when I deployed it on the webserver, I got the error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required,

But finally i get the solution .I has shared it


The SSL should be enable on the webserver as well, here is a link to enable ssl on the IIS7

dynamic DataGrid in silverlight

Set and Get values in string resource file


Creating Resources From a Web Page

The following feature is not available with Visual Web Developer Express.

To generate a local resource file from an ASP.NET Web page

  1. Open the page for which you want to create a resource file.
  2. Switch to Design View.
  3. In the Tools menu, click Generate Local Resource.
    Visual Web Developer creates the App_LocalResources folder if it does not already exist. Visual Web Developer then creates the culturally neutral base resource file for the current page, which includes a key/name pair for each control property or page property that requires localization. Finally, Visual Web Developer adds a meta attribute to each ASP.NET Web server control to configure the control to use implicit localization. For more information about implicit and explicit localization, see ASP.NET Web Page Resources Overview and How to: Use Resources to Set Property Values in Web Server Controls.
    Note:
    {Do not attempt to embed a graphic directly in a resource file because controls will not read the resource string as a streamed image file. Resource files represent graphics by storing the URL of the graphic as a string.}
  4. If the latest resource changes are not displayed, refresh Design view by switching to Source view and then switching back to Design view.
  5. Create resource files for additional languages by following steps 6 and 7 in the preceding procedure

    Add Values  to resource file
    Open with xml(text)Edit
    then
    <data name="PasswordError" xml:space="preserve">
        <value>Password or user name is invalid</value>
      </data>

    Call Resource file value in code-behind
     Strings.PasswordError

    MVC Razor side
     @Strings.PasswordError 

How to reduce angular CLI build time

 Index: ----- I am using angular cli - 7 and I am going to tell how to reduce the build time as per my knowledge. Problem: -------- Now the ...