Skip to main content

Posts

Showing posts from February, 2014

dynamically generate table cells in asp.net in csharp (c#)

 The following code will generate table cells as needed and add it in panel for further requirement.   public void generateoption()     {         bool isImage = rblOptionsType.SelectedIndex == 1;         int rowCount = 4;         Table table = new Table();         table.ID = "tblOptionsCollection";         for (int i = 0; i < rowCount; i++)         {             TableRow row = new TableRow();             TableCell cell5 = new TableCell();             cell5.Width = 150;             cell5.ID = "cell5" + i.ToString();             cell5.Text = "      ";             row.Cells.Add(cell5);             TableCell cell1 = new TableCell();             cell1.Width = 300;             cell1.ID = "cell1" + i.ToString();             cell1.CssClass = "h_text";             cell1.Text = "Option :" + (i + 1).ToString();             row.Cells.Add(cell1);             if (!isImage)             {                 TableCell cell = new TableCell()

update progress bar for update panel in asp.net

While update panel is loading the webpage looks hanged out and inresponsive.To make it alive that page is loading while update panel trigger is fired we add update progress as follow :  <asp:UpdateProgress ID="updateProgress" runat="server" AssociatedUpdatePanelID="UpdatePanel1"         DisplayAfter="1">         <ProgressTemplate>             <div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0;                 right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity: 0.8;">                 <span style="border-width: 0px; position: fixed; padding: 50px; background-color: #FFFFFF;                     font-size: 36px; left: 40%; top: 40%; color: Black">... Please Wait !! ...</span>             </div>         </ProgressTemplate>     </asp:UpdateProgress> Done !! :)

fade out button on click using jquery

Code for fade out button on click using jquery is :  $(document).ready(function () {                             $("#<%=Button1.ClientID %>").click(function () {                                   $("#<%=Button1.ClientID %>").fadeOut("slow");                           });                    }); Done :)

show image in asp.net form from database

In order to show image from database to webform first add an image control in webpage.   <asp:Image ID="imgStudentImage" runat="server" Height="157px" Width="160px" /> Then add new webform to read image from database for example displayimage.aspx and in code behind model write the following code. public string str = //your string     public SqlConnection conn;     public SqlCommand sql = new SqlCommand();     public SqlDataReader dr;     public string strSQL;     protected void Page_Load(object sender, EventArgs e)     {         conn = new SqlConnection(str);         conn.Open();         long id = Convert.ToInt64(Request.QueryString["mId"]);         strSQL = "";         strSQL = strSQL + " SELECT snap from StudentPicture ";         strSQL = strSQL + " WHERE IsOdl='true' and (Convert(Varchar(50),AdmissionId) = '" + id + "' or (Convert(Varchar(50),RegisterationNumber)='&

Add timing constraint for asp.net form to open

Did you ever met a condition where you want that your asp.net webpage will open only from particular date and particular time to particular date and particular time.Here is the simple code. First edit web.config file to add key for starting date and ending date :   <location allowOverride="true" inheritInChildApplications="true">     <appSettings>   <add key="frmstartdate" value="02/15/2014 03:30:59 PM " />       <add key="frmenddate" value="03/30/2014 03:30:59 PM " />     </appSettings>   </location> Very Simple isn't it.Now on WebPage on which restrictions are to be applied.Code is   if ((Convert.ToDateTime(ConfigurationManager.AppSettings.Get("AdmissionFormStartDateTime")) > (System.DateTime.Now))                 || (Convert.ToDateTime(ConfigurationManager.AppSettings.Get("AdmissionFormEndDateTime")) < (System.DateTime.Now)))             { //mak

Code to avoid master Page javascript to conflict with page javascript in asp.net

What if master page javascript is colliding with current page javascript on which you are using javascript that is same as that of master page javascript.In that case you have to ignore master page javascript by just one line code to make current page javascript work.Below is the simple jquery code  <script type="text/javascript">         $.noConflict();     </script> Done !! :)

Code to print Particular div tag in asp.net

Below is the Code to print Particular div of html in any browser .From the below code you can adjust even height,width and font for that print. function printContent(id) {             var   height = '260';             var width = '675';             var   font = '12';             str = document.getElementById(id).innerHTML             newwin = window.open('', 'printwin')             newwin.document.write('<HTML>\n<HEAD>\n')             newwin.document.write('<TITLE>Print CA</TITLE>\n')             newwin.document.write('<style type="text/css">\n')             newwin.document.write('*{font-size:' + font + 'px;}\n')             newwin.document.write('html { width: ' + width + '; height: ' + height + '; }\n')             newwin.document.write('<\/style>\n')             newwin.document.write('<script>\n')           

javascript to avoid particular invalid character in textbox

Suppose we have a testbox and you dont want to allow comma in the textbox.Below is the code to do so :   function checkKey(ele, event) {             var v = ele.value.substring(0, ele.value.length);             if (event.keyCode == 188) {                 alert("Invalid Character");                 $("#<%=lccode.ClientID %>").val(v);             }             else {                 return true;             }         } And here us the textbox code to call function :        <asp:TextBox ID="lccode" runat="server" Width="200px" TextMode="MultiLine" Height="30px"                             onKeyDown="checkKey(this,event)"></asp:TextBox>

create html format of data extracted from database in asp.net

Suppose we have a need to print 500 pages a time without using report and every page is on individual page then what we will do.Below is the solution. This thing is very needed now a days as to avoid using reports in asp.net.Reports are used to display data in the output page with proper format and alignment but they are heavy and some extra features are to be included.We cal also generate output in proper format by just using HTML tags.For this we use Jquery (very simple and easy to use). Below is the code : First import namespace using System.Web.Services; Then Create Web method on cs page (code behind model) to get data from database and format it in List. [WebMethod]     public static List<getdata> getlccodedetail(string prefixText, string studymode, string state)     {         try         {             List<getdata> li = new List<getdata>();             if (con.State == ConnectionState.Closed)                 con.Open();             SqlCommand cmd = ne

JSON/Jquery to get data from webservice and add webservice data to Dropdownlist in asp.net

WEB SERVICE :First make web method on cs page .   [WebMethod]     public static List<getdisttdata> getdisttt(string prefixText)     {         List<getdisttdata> li = new List<getdisttdata>();         try         {             if (connection.State == ConnectionState.Closed)                 connection.Open();             SqlCommand cmd = new SqlCommand();             cmd.CommandText = "Your Query";             cmd.Connection = connection;             cmd.CommandType = CommandType.Text;             SqlDataAdapter adp = new SqlDataAdapter(cmd);             DataSet ds = new DataSet();             adp.Fill(ds);             connection.Close();             foreach (DataRow dr in ds.Tables[0].Rows)             {                 getdisttdata bkl = new getdisttdata();                 bkl.distt = dr["District"].ToString();                 bkl.disttcode = dr["CityCode"].ToString();                 li.Add(bkl);             }         }         catch

Rotate Your Website Title With javascript

Rotating Tile of website is very simple and easy with javascript. Here is the code to rotate Title of your website.     <head runat="server">     <title id="title1">Sample Text </title>     <script type="text/javascript">     var tid;     var text = "Sample";     window.onload = (function() {     tid = setInterval(rotateText, 100);     });     function rotateText() {     document.title = document.title.substring(1, document.title.length) + "" + document.title.substring(0, 1);     }     </script>     </head>