Skip to main content

Posts

Showing posts with the label Asp.net programming

Asp code to call home page on logout button,reset password of user

Asp code to call home page on logout button Make script code this way Put this code in vb-script tag sub home() document.frm.submit() end sub //to call function on click event this way onclick="home()" Asp code to reset password of user If you want to reset password or change password of particular user and you can login page then you can get hint or help to set this code in your form. set con=server.CreateObject ("ADODB.CONNECTION") set rs=server.CreateObject ("ADODB.RECORDSET") con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database Path" Response.Clear () set rs = con.Execute ("select * from logtable where Username='" & Request.Form ("logid") & "' and pwd = '" & Request.Form ("oldpassword") & "'" ) if rs.RecordCount <=0 then Response.Write "invalid password" end if if Request.Form("che

Code To Fill data table in DataGrid,fill static, get DataSet combo in asp.Net

Code To Fill DataGrid using asp.net  You can try Code To Fill DataGrid using asp.net common class. After creation these methods you need to call these method to your form editors by creating class object. Fill DataGrid Private Sub fillgrid() dim dta2 as New dataTable Dim str1 As String = "select * from receipt_detail " Dim datatb As New DataTable datatb = obj.OpenDataTable(str1, "receipt_detail") dta2.DataSource = datatb dta2.DataBind() End Sub 'Other Related Function Public Function OpenCn() As Boolean Try If cn Is Nothing Then cn = New SqlConnection End If If Not (cn.State = ConnectionState.Open) Then cn.ConnectionString = constr cn.Open() End If Finally End Try Return True End Function Public Function Closecn() As Boolean Try If Not (cn Is Nothing) Then cn.Close() End If Finally cn.Dispose() End Try Return True End Function Public Function OpenDataTable(B

ASP.Net Tips-Create object for delegate ,Paste data using code,Delete lines in dataTable

namespace Akadia.BasicDelegate { // Declaration public delegate void SimpleDelegate(); class TestDelegate { public static void MyFunc() { Console.WriteLine("I was called by delegate ..."); } public static void Main() { // Instantiation SimpleDelegate simpleDelegate = new SimpleDelegate(MyFunc); // Invocation simpleDelegate(); it's the object of delegate. } } } objectname.Eventname += new objectname.delegatename(functionname()); in this we are calling events by creating an object of that particular class providing events but when we attaching delegates we are not using the object name or we cannot use object name, instead we are using class name of that particular delegate provided . Delegate is neither meant to do any action nor to persist a value. so there is no need to access the delegate by an object. And we can even declare the delegate outside of the class. There is no significant in declaring the dele

Function to check key validation using asp.net

Function to check key validation using asp. net ublic Function KeyValid(ByVal keyChar As Char, ByVal strType As KeyType) As Boolean Dim blnRetVal As Boolean Dim strNumStr As String = "0123456789" Dim strDecStr As String = "0123456789." Dim strAlpha As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" Dim strDate As String = "0123456789/" Dim strPhone As String = "0123456789-()," Dim strTime As String = "01234567890:" Dim strEqn As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789./*+-()|" Dim strAlphaNum As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" Try blnRetVal = False If Asc(keyChar) < 32 Then KeyValid = False Exit Function End If Select Case strType Case KeyType.KeyAlpha If strAlpha.IndexOf(keyChar) < 0 Then blnRetVal = Not blnRetVal Case KeyType.KeyAlphaNum If strAlphaNum.IndexOf(keyChar) &

Retrive image from database and open in new page using asp.net

Retrive image from database and open in new page using asp.net MemoryStream mstream = new MemoryStream(); SqlConnection conn = new SqlConnection("Data Source=(local)\\sqlexpress;Initial Catalog=master;Integrated Security=True"); conn.Open(); SqlCommand cmd = new SqlCommand("select Image from student1 where Id=" + TextBox1.Text, conn); byte[] image = (byte[])cmd.ExecuteScalar(); mstream.Write(image, 0, image.Length); Bitmap bitmap = new Bitmap(mstream); Response.ContentType = "image/gif"; bitmap.Save(Response.OutputStream, ImageFormat.Gif); conn.Close(); mstream.Close();

How to create sitemap runtime in asp.net

How to create sitemap runtime in asp.net // begin program abc // declare namespace using System.Xml; using System.Text; using System.Data.SqlClient; //declare class public partial class sitemap : System.Web.UI.Page { SqlConnection cn; protected void Page_Load(object sender, EventArgs e) { try { cn = new SqlConnection("Your connection string"); string mydomain = "your domain name"; string strSql = "select abc from test"; SqlDataAdapter dacontent = new SqlDataAdapter(strSql, cn); DataSet dscontent = new DataSet(); dacontent.Fill(dsd, "SiteMap"); //Now we are going to create XML file using XMLTextWriter XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8); writer.WriteStartDocument(); writer.WriteStartElement("urlset", "url"); writer.Writ

Re size image in ASP.NET while uploading an image

Re size image in ASP.NET while uploading an image public bool SaveThumbnailImage(System.Web.UI.WebControls.FileUpload fu, string FullSavePath, int HeightMax, int WidthMax) { try { if (fu.HasFile){string tmpSaveDir = pg.Server.MapPath("~/TempUploads/"); if (System.IO.Directory.Exists(tmpSaveDir) == false) { System.IO.Directory.CreateDirectory(tmpSaveDir); } string tmpSavePath = pg.Server.MapPath("~/TempUploads/" + fu.FileName); if (System.IO.File.Exists(tmpSavePath)) { try { System.IO.File.Delete(tmpSavePath); } catch { } } fu.SaveAs(tmpSavePath); System.Drawing.Image img = System.Drawing.Image.FromFile(tmpSavePath); double ratioWidth = (double)img.Width / (double)WidthMax; double ratioHeight = (double)img.Height / (double)HeightMax; double ratio = Math.Max(ratioHeight, ratioWidth); int newWidth = (int)(img.Width / ratio); int newHeight = (int)(img.Height / ratio); System.Drawing.Ima

Compiling and Delivering ASP.NET Pages stages

Compiling and Delivering ASP.NET Pages stages The process of compiling and delivering ASP.NET pages goes through the following stages: 1. IIS matches the URL in the request against a file on the physical file system (hard disk) by translating the virtual path (for example, /site/index.aspx) into a path relative to the site’s Web root (for example,d:\domains\thisSite\wwwroot\site\index.aspx). 2. Once the file is found, the file extension (.aspx) is matched against a list of known file types for either sending on to the visitor or for processing. 3. If this is first visit to the page since the file was last changed, the ASP code is compiled into an assembly using the Common Language Run time compiler, into MSIL, and then into machine-specific binary code for execution. 4. The binary code is a .NET class .dll and is stored in a temporary location. 5. Next time the page is requested the server will check to see if the code has changed. If the code is the same, then the compilat

ASP.NET validation controls

ASP.NET validation controls RequiredFieldValidator CompareValidator RangeValidator RegularExpressionValidator CustomValidator E.g. <asp:TextBoxid=“pwd” runat=“server”/><asp:RequiredFieldValidatorControlToValidate=“pwd”ErrorMessage=“Password required.”EnableClientScript=“true”id=“pwdRequired”runat=“server”/>

Encrypt Decrypt password using asp dot net

using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Security.Cryptography; namespace xyz { class abc { public static string Encrypt(string plainText, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize) { // Convert strings into byte arrays. // Let us assume that strings only contain ASCII codes. // If strings include Unicode characters, use Unicode, UTF7, or UTF8 // encoding. byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector); byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue); // Convert our plaintext into a byte array. // Let us assume that plaintext contains UTF8-encoded characters. byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText); // First, we must create a password, from which the key will be derived. // This password will be generated from the specified passphrase and

compare To Current Time in asp.net

compare To Current Time in asp.net public static bool compareToCurrentTime(string time) { time = convert12To24(time); int hr = DateTime.Now.Hour; int min = DateTime.Now.Minute; string current = ((hr < 10) ? "0" : "") + hr + ":" + ((min < 10) ? "0" : "") + min; if (time.CompareTo(current) >= 0) { return true; } else return false; }

convert time 24 To 12 in asp.net

 If you want to convert time  24 format  To 12  am pm form in asp.net then you can try following method. You can write this method in common class in asp.net program then you can call this function by passing time variable in function parameter. public static string convert24To12(string time) { if (time.IndexOf(":") == -1) return time; string appendstring = "AM"; string strHr = time.Substring(0, time.IndexOf(":")); string strMin = time.Substring(time.IndexOf(":") + 1); int intHr = Convert.ToInt16(strHr); if (intHr > 12) { appendstring = "PM"; intHr -= 12; } if (intHr == 12) { appendstring = "PM"; } else if (intHr == 0) { intHr = 0; } return ((intHr < 10) ? "0" : "") + intHr + ":" + strMin + "

Show parent child node value at runtime and populate treeview in asp.net

Show parent child node value at runtime and populate treeview in asp.net. This program is use to populate treeview at runtime using asp.net. you can try this code. Imports System.Data Imports System.Configuration Imports System.Web Imports System.Web.Security Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.WebControls.WebParts Imports System.Web.UI.HtmlControls Imports System.Data.SqlClient Imports System.Web.UI.WebControls.TreeNode Partial Class Bibliography Inherits System.Web.UI.Page Dim clscmn1 As New clsCommon Dim cn As New clsConnection Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then PopulateRootLevel() Else Exit Sub End If End Sub Private Sub PopulateRootLevel() Dim dt1 As New DataTable() Dim objCommand As New SqlCommand("select PRODUCT_CATEGORY_CD,PRODUCT_CATEGORY,(select count(*) FROM PRODUCT_CATEGORY

Add items to menu at runtime,display message,Web service to search item in textbox etc in asp.net

Add items to menu at runtime using asp.net Dim str, str1 As String str = "select distinct PRODUCT_CATEGORY,PARENT_CATEGORY_CD,PRODUCT_CATEGORY_CD from PRODUCT_CATEGORY where PARENT_CATEGORY_CD is NULL" Dim adp As New SqlDataAdapter(str, cn.openDb()) adp.Fill(ds) cn.closeDb() If (ds.Tables(0).Rows.Count > 0) Then For Each dr In ds.Tables(0).Rows Dim mu As MenuItem = New MenuItem mu.Text = dr("PRODUCT_CATEGORY").ToString mu.Value = dr("PRODUCT_CATEGORY_CD").ToString BrowsebyCategory.Items.Add(mu) Next End If This code is to Add items to menu at runtime using asp.net code you can use code to backend side Simple Display message using asp.net Simple Display message using asp.net. Just use following code. Dim myStringVariable As String = String.Empty myStringVariable = "Message" ClientScript.RegisterStartupScript(Me.[GetType](), "myalert", "alert('" & myStringVariab

How to fill grid in asp.net through code in function of class

How to fill grid in asp.net through code in function of class Public Function FillGrid() As DataTable Dim cmd As SqlCommand cmd = New SqlCommand("SP_SELECT_COLUMNNAMES", objCn.openDb()) cmd.CommandType = CommandType.StoredProcedure Dim dt As New DataTable("Dt") Dim da As New SqlDataAdapter(cmd) Try cmd.Parameters.Add(New SqlParameter("@COLUMNNAME", SqlDbType.VarChar, 1000, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, _ColumnName)) cmd.Parameters.Add(New SqlParameter("@TABLE", SqlDbType.Char, 300, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, _Table)) cmd.Parameters.Add(New SqlParameter("@CRITERIA", SqlDbType.Char, 2000, ParameterDirection.Input, True, 0, 0, "", DataRowVersion.Proposed, _Criteria)) 'Execute Query da.Fill(dt) 'da.Fill(dt) Dim Inti As Integer 'For Inti = 0 To dt.Columns.Count - 1 ' '

How to get financial year using asp.net code in class

How to get financial year using asp.net code in class Public Function GetFinYear(ByVal Dt1 As String) As String Dim mm, yy As String Dim int_mm, int_yy As Integer Dim dt As String dt = Dt1 ''.ToString("dd/MM/yyyy") Dim frm_dt, to_dt, fin_yr As String mm = dt.Substring(3, 2) yy = dt.Substring(6, 4) int_mm = CType(mm, Integer) int_yy = CType(yy, Integer) If int_mm <= 3 Then to_dt = "31/03/" & yy int_yy = int_yy - 1 frm_dt = "01/04/" & int_yy.ToString() Else frm_dt = "01/04/" & yy int_yy = int_yy + 1 to_dt = "31/03/" & int_yy.ToString() End If fin_yr = frm_dt.Substring(8, 2) + to_dt.Substring(8, 2) Return fin_yr End Function

function to Get scalar value and Get value of table using query using asp.net code

function to Get scalar value using asp.net code Public Function getSclarValue(ByVal Qry As String) As String Dim cmdDatabase As New SqlCommand Try cmdDatabase = New SqlCommand(Qry, objCn.openDb()) Return cmdDatabase.ExecuteScalar() Catch ex As Exception MsgBox(ex.Message) Return Nothing Finally objCn.closeDb() End Try End Function Function to Get value of table using query in asp.net Public Function GetTable(ByVal str As String) As DataTable Try Dim dt As New DataTable Dim cmd As New SqlCommand(str, objCn.openDb()) Dim adp As New SqlDataAdapter(cmd) adp.Fill(dt) Return dt Catch ex As Exception MsgBox("Error" + ex.Message) Return Nothing Finally objCn.closeDb() End Try End Function