Saturday, July 7, 2012

Regular Expression For Specific Time Format("HH:MM")


asp:TextBox ID="txtStartTime" runat="server" Width="100" asp:TextBox
                                                                                    asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ControlToValidate="txtStartTime"
                                                                                            Display="None" ErrorMessage="Start Time missing" SetFocusOnError="True"
                                                                                            ValidationGroup="validComboAddGrp" asp:RequiredFieldValidator
                                                                                            asp:RegularExpressionValidator ID="regextxtSessionTime" runat="server"
    ControlToValidate="txtStartTime"
    ValidationExpression="^([0-1][0-9]|[2][0-3]):([0-5][0-9])$"
    ErrorMessage="You must enter a valid time. Format: HH:MM"
    Display="none"
    SetFocusOnError="true" ValidationGroup="validComboAddGrp"
  asp:RegularExpressionValidator

Saturday, April 28, 2012

Bind Table using javascript like grid or repeater.



Bind Any Table which comes from code behind stored procedure calling....Like this simply make a method which is webmethod into code behind and call it on client side.The Total code is below I am writing here.
//--------------------Bind Elective Papers on Change Of Specialization------------------
        function ShowElectivePapers() {

            var dCID = document.getElementById('<%= ddlCourse.ClientID%>');
            var CourseID = dCID.options[dCID.selectedIndex].value;
            var dSID = document.getElementById('<%= ddlSemester.ClientID%>');
            var SemID = dSID.options[dSID.selectedIndex].value;
            var dSpec = document.getElementById('<%= ddlSpecialization.ClientID%>');
            var SpecID = dSpec.options[dSpec.selectedIndex].value;
            if (SpecID != 0) {
                BindElectivePapers(CourseID, SemID, SpecID);
            }
        }


        function BindElectivePapers(CCode, SemId, Spec) {

            $.ajax({
                type: "POST",
                url: "StudentRegistration.aspx/BindElectivePapers",
                contentType: "application/json; charset=utf-8",
                data: "{'CCode': '" + CCode + "','SemId': '" + SemId + "','Spec': '" + Spec + "'}",
                dataType: "json",
                async: false,
                success: AjaxSucceeded,
                error: AjaxFailed
            });

            function AjaxSucceeded(result) {
                DisplayChildren(result);
            }
            function AjaxFailed(result) {
                alert('no success');
            }
            function DisplayChildren(result) {
                var dtEpaper = eval(result.d);
                if (dtEpaper != null && typeof (dtEpaper) == "object") {
                    document.getElementById('<%= dvElectivePapers.ClientID%>').style.display = '';
                    var s = new Array();
                    s[s.length] = "
Elective Papers
"
                    s[s.length] = "
"
                    s[s.length] = "
"
                    s[s.length] = "
";
                    s[s.length] = "
";
                    s[s.length] = "
";
                    s[s.length] = "
";
                    s[s.length] = "
";
                    for (var i = 0; i < dtEpaper.Table.length; i++) {
                        s[s.length] = "
";
                        s[s.length] = "
";
                        s[s.length] = "
";
                        s[s.length] = "
";
                    }
                    s[s.length] = "
Paper CodePaper Name
" + dtEpaper.Table[i].Code + "" + dtEpaper.Table[i].SubName + "
";
                    s[s.length] = "
";
                    document.getElementById("<%= dvElectivePapers.ClientID%>").innerHTML = s.join("");
                }
                else {
                    document.getElementById('<%= dvElectivePapers.ClientID%>').style.display = 'none';
                }
            }
        }

        // -----------------------.cs Code with stored procedure caliing--------------

 #region "BindElectivePapers"
    [WebMethod]
    public static Dictionary BindElectivePapers(string CCode, string SemId, string Spec)
    {
        CommonManger Obj = new CommonManger();
        DataTable objEPaper = new DataTable();
        objEPaper = Obj.GetTableWithParameter("SP_GetElectivePapers_ViaSpecialization", "@CrsID", CCode, "@Sem", SemId, "@CrsSpl", Spec);
        if (objEPaper.Rows.Count > 0)
        {
            return JsonMethods.ToJson(objEPaper);
        }
        else
        {
            return null;
        }
    }
    #endregion

Wednesday, April 25, 2012

Make custom order in sql



Hi,
I can also make my query according to my customization order called Custom Order .It works as i want in which order my out will show .As simple as it is...
SELECT COUNT(*)StudentCount,SessionCode FROM dbo.tblStudentNEDESROLL GROUP BY SessionCode ORDER BY CASE
            WHEN SessionCode = '0110' THEN 1
            WHEN SessionCode = '0710' THEN 2
            WHEN SessionCode = '0111' THEN 3
            WHEN SessionCode = '0711' THEN 4
            WHEN SessionCode = '0112' THEN 5
           
         END

Friday, April 20, 2012

Set Default database in sql on New Query


This is to set any database when U want any database come to add query.In ur sql.
Exec sp_defaultdb @loginame='login', @defdb='master'

Sunday, January 22, 2012

Check checkbox only in Repeater not outside of this control


This is the code for finding particular checkbox in repeater only .it will leave the checkboxes which  outside repeater  of the page.I hope it will do what you want exactly ....enjoy coding....!!!

function checkAll(cb) {
        var TargetBaseControl = document.getElementById('pnlData');
        var TargetChildControl = "chkisPassout";

       var ctrls = document.getElementsByTagName('input');
     
        for (var i = 0; i < ctrls.length; i++)
          {
              var cbox = ctrls[i];
              if (cbox.type == "checkbox" && cbox.id.indexOf(TargetChildControl,0) >= 0)
            {
                cbox.checked = cb.checked;
            }
        }
    }

Thursday, December 22, 2011

Call JavaScript function Server Side button_onclick

You can easily call any javascript anywhere on page by this code simply....

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Key", "script language='javascript'>alert("msg");script", false);

Monday, December 19, 2011

Sending sms from Asp.Net

I use the following two functions in my application to send sms from my asp.net application.
I use c# as programming language.
I provide some credential which I got from the sms API provider. we use www.smscountry.com API in application.
I call the setupSMS function to send sms from my application which requires mobileNumber and message as input parameter and returns the response of the message sent.


private string setupSMS(string mobileNumber, string message)
{
string strPostBody;
String strPostResponse;


//'Give The Respective Variable Values
string userName = "UserId"; //'Enter Your User Name provided by API Provider
string password = "Password";//'Enter Your Password provided by API Provider
string senderid = "senderId";//' Enter Your Senderid provided by API Provider


string messageType = "N";//' Enter Your Message Type As N for Normal Message, O for Other Laungauge Sms
Char deliveryReports = 'Y';//' if U want To Know Delivery Reports Enter Y it Gives JOBID Otherwise N


//'****If U R Behind The Proxy Server Uncomment And Give Below Details *****
//'objProxy = New WebProxy("Proxy Ip Adress", PortNumber)


//'Call sendSMS Method For Sending The Sms's

message = Server.UrlEncode(message);
strPostBody = "User=" + userName + "&passwd=" + password + "&mobilenumber=" + mobileNumber + "&message=" + message + "&sid=" + senderid + "&mtype=" + messageType + "&DR=" + deliveryReports;
strPostResponse = sendSMS(strPostBody);
return strPostResponse;
}


private string sendSMS(string stringPost)
{

HttpWebRequest objWebRequest = null;
HttpWebResponse objWebResponse;
StreamWriter objStreamWriter = null;
StreamReader objStreamReader = null;
try
{

string stringResult;

objWebRequest = (HttpWebRequest)(WebRequest.Create("http://www.smscountry.com/smscwebservice.asp"));

objWebRequest.Method = "POST";

if (objProxy != null)
{
objWebRequest.Proxy = objProxy;
}
objWebRequest.ContentLength = stringPost.Length;
objWebRequest.ContentType = "application/x-www-form-urlencoded";
objStreamWriter = new StreamWriter(objWebRequest.GetRequestStream());
objStreamWriter.Write(stringPost);
objStreamWriter.Flush();
objStreamWriter.Close();

objWebResponse = (HttpWebResponse)(objWebRequest.GetResponse());
objStreamReader = new StreamReader(objWebResponse.GetResponseStream());
stringResult = objStreamReader.ReadToEnd();
objStreamReader.Close();
return stringResult; //'jobid

}
catch (Exception ex)
{
return ex.ToString();
}
finally
{
if (objStreamWriter != null)
{
objStreamWriter.Close();
}
if (objStreamReader != null)
{
objStreamReader.Close();
}
objWebRequest = null;
objWebResponse = null;
objProxy = null;
}
}