19 January 2013

Assign System.DBNull.Value in SqlParam value instead of 0 using Ternary operator



Assign System.DBNull.Value in SqlParam value instead of 0 using Ternary operator

  int i = 0;
           
  SqlParameter[] SqlParam = null;
  SqlParam = new SqlParameter[1];
  SqlCommand SqlCmd = new SqlCommand();

 SqlParam[0] = new SqlParameter("@SectionCode", SqlDbType.VarChar, 50);
 SqlParam[0].Value = i == 0 ? (object)System.DBNull.Value : i;



3 January 2013

Javascript Confirm button ok and cancel

Javascript Confirm button ok and cancel

var r=confirm("Press a button");
if (r==true)
  {
  x="You pressed OK!";
  }
else
  {
  x="You pressed Cancel!";
  }



18 December 2012

Click the button using Javascript


Click the button using Javascript 

document.getElementById("btnSearch").click();



Javascript Empty validation in Asp.net


Javascript Empty validation

function CheckEmpty() {

           try {
               if (document.getElementById("txtClientNumber").value.trim() == "") {
                   alert("Must enter a Client Number");
                   return false;
               }
           }
           catch (e) {
           }
       }
     

calling javascript from server side
btnAdd.Attributes.Add("onclick", "return CheckEmpty();")



Asp.net Gridview mouseover, mouseout color change in C#


Asp.net Gridview mouseover, mouseout color change in C#


protected void grd_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.color='Red'";
                e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';this.style.color='Black'";

                e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.grd, "Select$" + e.Row.RowIndex);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }

Confirm ok/cancel in Javascript in Asp.net


Confirm ok/cancel in Javascript in Asp.net


function askConfirm()
{
    if (confirm("Are you sure want to overwrite the file")) {
    }
    else {

        return false;
    }


Calling js from server side coding in Asp.net

 ScriptManager.RegisterStartupScript(this, GetType(), "YourUniqueScriptKey", "askConfirm();", true);






Stored Procedure used to search the word in the Database Sql Server


Below Stored Procedure used to search the word in the Database Sql Server
/*


Test Script:
exec Find_Text_In_SP 'Searchword'


*/

CREATE Procedure dbo.Find_Text_In_SP(
@SearchString AS VARCHAR(500)
)
AS
BEGIN
SET NOCOUNT ON
SELECT name
FROM
 sysobjects
WHERE
 id IN
 (SELECT id
  FROM
   syscomments
  WHERE
   text LIKE '%' + @SearchString + '%')
ORDER BY
 name
END





Implementing OAuth validation in a Web API

 I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...