Thursday, 14 March 2013

Calling code behind function from a html button

HTML button click call code behind in asp.net



<input type="button" id="btnuplod" runat="server" value="Upload" onclick="__doPostBack('btnSubmit','Submit');">

Code Behind
 
protected void Page_Load(object sender, EventArgs e)
{
   if (IsPostBack)
   {
      if (Convert.ToString(Request.Form["__EVENTARGUMENT"]) == "Submit")
      {
          btnuplod_Click();//submit action here
      }
   }
}

Your Function


Public void btnuplod_Click()
{
      if (FileUploadPDF.HasFile)
        {
            string fileName = Server.HtmlEncode(FileUpload1.FileName);
            string extension = System.IO.Path.GetExtension(fileName);
            if (extension == ".pdf")
            {

            }
            else
            {
                lblerror.InnerText = "Please upload PDF Files Only";
            }
        }
}
 

Thursday, 7 March 2013

Disable Browser Back Button Functionality using JavaScript in ASP.Net

Solutions 1:  
 
Suppose there are two pages Main1.aspx and Main2.aspx and Main1.aspx redirects
 to Main2.aspx

Hence to prevent user from visiting Main1.aspx using Back Button you will need
to place the above script in the head section of Main1.aspx as shown below. 

<script type = "text/javascript" >
         function preventBack() { window.history.forward(); }
         setTimeout("preventBack()", 10);
         window.onunload = function() { null };
 

    </script>


I have tested the script in the following browsers:

1.     Internet Explorer 5.55
2.     Internet Explorer 6
3.     Internet Explorer 7
4.     Mozilla Firefox 19.0
5.     Opera 9
6.     Safari 4
7.     Google Chrome

Friday, 1 March 2013

Dynamically add HTML (div / table / all HTML ) element using ASP.Net and C#

Solutions 1:  

HtmlGenericControl mydiv=new System.Web.UI.HtmlControls.HtmlGenericControl("div");
mydiv.Style.Add(HtmlTextWriterStyle.MarginLeft,"360px"); 

How do I get current index in “for each” loop

Solutions 1:  
foreach (DataRow row in dtGroups.Rows)
{
    string grpTitle = row["MainCategory"].ToString();
    int  id = dtGroups.Rows.IndexOf(row);   // (row no)
}

Wednesday, 20 February 2013

Converting .exe project (Existing Project ) to class library (DLL)

Step 1: Project + Properties
Step 2: Change Output type Windows Application to Class Library
Step 3: Build solution
Step 4: see Dll  \bin\Debug  or  \bin\Release

Monday, 18 February 2013

The OLE DB provider "Microsoft.ACE.OLEDB.12.0" has not been registered


Solutions 1:  
You need to download

"Data Connectivity Components for 2007 office system Driver".
after you download, please restart your server.







you can Click Microsoft Link.

Tuesday, 12 February 2013

How to create Setup File in C# 2008 (windows Application)

How to create Setup File in C# 2008 (windows Application)







Rich Text Format (RTF) use  All Programs   ==> Accessories ==> Wordpad

 How to run an installed file after installation?
 Step 1:
Screenshot - 3.png

Step 2: Name it Installer Class.
Screenshot - 4.png
Step 3:

 Step 4:
Rebuild your install solution.

Download  Process steps (Pdf Format  -> 21.5 MB)