Posts

Access UserControl from Page

Image
Hi.. To perform some reparative operation in application, its preferred to use UserControls. Not necessary to have same display and bindings at everyplace. In that case we need to set values or call methods or pass values accordingly. Here I have tried to figure out three cases, Hope it is helpful. Pass Table to Usercontrol and Set dynamically value to Controls Set Properties of control Call Usercontrol's Methods

Set Default Value as Function to column of a Table

Image
Hello, Generally we need to set default value to particular column in Database Table like isActive is true, IsDeleted is false. same way many times we set CreatedOn Date as CurrentDate and that is by query of insert GetDate(). Static Values : Its very easy to set some static value as Default value for column and that is as follow : Functions : Set Default Date for Createdon Field as Follow : User Defined Functions : Set User Defined function as Default Value as follow: In my case I am supposed to get Random Hexa Code for Color. so I Have created an User Defined function for that CREATE FUNCTION [dbo].[GetRandomColorCode] ( ) RETURNS varchar(6) AS BEGIN Declare @Color varchar(6) RETURN (SELECT MyNewID FROM dbo.MyNewID) END Now set the function in columns as follow : If this do not allow us to set Default value try following query to set ALTER TABLE dbo.Table_1 ADD CONSTRAINT DF_Table_1_ColorCode DEFAULT ([dbo].[GetRandomColorCode]()) FOR ColorCode GO Al...

Track Error in Javascript Page

Hi Many times we have faced problems to find what is javascript errors and exactly where?? To track javascript error, It is a good practice to write code in Try..Catch but sometimes some small syntax error are not allowing to execute the whole js file. so to track such error during development, we can track by this sample code <script type="text/javascript"> onerror = CallOnError; function CallOnError(msg, url, line) { var strErrMessage = ""; strErrMessage += "Message: " + msg + "\n"; strErrMessage += "Page: " + url + "\n"; strErrMessage += "Line Number: " + line + "\n\n"; alert(strErrMessage); return true; } </script> Here is a sample error try to put on your page <script type="text/javascript"> alert('This is First Test Page); </script...

Second Highest Salary- Sql Query

Image
Create Table #Emp(id int identity primary key, Emp varchar(100), Salary int) insert into #Emp select 'XXXX',17000 union all select 'DDDD',21000 union all select 'WWWW',30000 union All Select 'HHHH',21000 union All select 'CCCC',30000 union All Select 'TTTT',21000 union All SElect 'PPPP',21000 select * from #Emp select #Emp.* from (select ROW_NUMBER() over (order by salary desc) as RowNumber, Salary from #Emp group by Salary) as tempEmp inner join #Emp on tempEmp.Salary = #Emp.Salary where tempEmp.RowNumber=2 Drop Table #Emp Data Will Look like this Output will be like this

Protect image from being copied

Image
Hello Friends, Many times I am asked to protect some copyrighted images over web, so finally I have found a better way to protect from being copied. There are some cases by which we can copy the image Here I have taken care of following cases Right click on image and Save the Image Save the Entire page and all images displayed on page will be downloaded to its Data Folder in mozila Firefox, We can save the media files by following steps Right click on Page, select “View Page Info” It will open a window, Select “Media” tab, here a list of all files will be available select particular file and click on “Save As” button to save the media Now Let’s Start our main topic,that is protect image from being copied There is a concept called Data URI scheme . Generally to display any image on page, we use Relative_URL and if we display image using this, the images can be easily copied. Here we will save image in database and retrieve the same To Create table CR...

Fetch Data from Control Without Loop- Best Use of LINQ

Hi friends…. Many times I need to generate collection type Data from GridView or Repeater or any other control.. and in that case I used to loop through each rowitem of particular control.. here each row of repeater is listitem of LINQ query. same way you can perform for all DataBound Controls like GridView, Repeater, DataList, DropDownlist, CheckboxList, Radiobuttonlist etc… but after using LINQ , I am able to do that very easily here is sample of Repeater control to Get List of data List ctrls = (from item in rptctrlList.Items.Cast () where ((CheckBox)item.FindControl("chkctrl")).Checked select new ctrlInfo() { ctrlId = Convert.ToInt32(((HiddenField)item.FindControl("hdnctrlId")).Value), UserctrlId = Convert.ToInt64(((HiddenField)item.FindControl("hdnUserctrlId")).Valu...

Apply Frame to Image with CSS

Image
Hello Many times we need to display image like profile image or advertisements and at that time we need to decorate it within frame…   Here we have a simplest way to apply frame which will help to set frame to any size image and unique for all.. here I have a sample code for it <html> <head> <style> img { background: url("shadow.gif") no-repeat scroll right bottom transparent; border-color: #EEEEEE -moz-use-text-color -moz-use-text-color #EEEEEE; border-right: medium none; border-style: solid none none solid; border-width: 1px medium medium 1px; padding: 4px 10px 10px 4px;} </style> </head> <body> <img src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxKSyD46sNlLs8yYLBFMz_YGOiYANzbKSUPo5YT5f2K34QvZgGOWTWF_s_aWPoe4zuVafRytM6346dkW7bkjptRImMMCLWyaCxtGgAjPD97wa7HWZ_l94H2uWxlU8V2UKIJPgvyj7sTO5x/s220/Sandeep.JPG'> </body> </html> and the you can have any kind of frame imag...