Wednesday, September 28, 2011

Dopostback event coding if it doPostBack not available


<script type="text/javascript">
         //<![CDATA[
        
        
         function __doPostBack(eventTarget, eventArgument)
         {
             var theForm = document.getElementById("<%=form1.ClientID %>");
             if (!theForm.onsubmit || (theForm.onsubmit() != false))
             {
                 theForm.__EVENTTARGET.value = eventTarget;
                 theForm.__EVENTARGUMENT.value = eventArgument;
                 theForm.submit();
             }
         }
         //]]>
</script>

    <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />

Disable button using javascript


function disableButton(btnId) {
            var btn = document.getElementById(btnId);
            btn.enabled = false;
            btn.disabled = true;
        }

 OnClientClick="if(CheckEmptyRecordComment()==true)javascript:disableButton(this.id); else
return false;"

How to send mail using C#


string from = "", to = "", smtpServer = "", username = "", password = "", smtpport = "";
          
            smtpServer = ConfigurationSettings.AppSettings["Comment_Mail_SmptHost"];
            from = ConfigurationSettings.AppSettings["Comment_Onbehalf_Mail"];
            to = ConfigurationSettings.AppSettings["Comment_To_Mail"];
            username = ConfigurationSettings.AppSettings["Comment_From_Mail"];
            password = ConfigurationSettings.AppSettings["Comment_From_Password"];
            smtpport = ConfigurationSettings.AppSettings["Comment_Mail_Port"];

            StringBuilder strbuild = new StringBuilder();
            strbuild.Remove(0, strbuild.Length);
            strbuild.Append("Body");
            MailMessage msg = new MailMessage(from, to, "Subject", strbuild.ToString());
            msg.BodyEncoding = Encoding.ASCII;
            msg.IsBodyHtml = true;
            msg.SubjectEncoding = System.Text.Encoding.UTF8;
            msg.Priority = MailPriority.High;

            SmtpClient smtpClt = new SmtpClient(smtpServer, Convert.ToInt32(smtpport));
            smtpClt.Credentials = new NetworkCredential(username, password);
            smtpClt.Send(msg);
Note: when hosting on server change SMTPHost as localhost if it deployed in same server

Set Serial number for asp repeater


< %# Container.ItemIndex + 1 %>

Converting Dataset column to Array


String[] rowValuesForColumn =
Array.ConvertAll<DataRow, String>(
dataTable.Select(),
delegate(DataRow row) { return (String) row[columnName]; }
);