Posts

Showing posts from 2013

How to get jQuery version

use Console or write a jquery to get version: 1- jQuery.fn.jquery 2- $.fn.jquery; 3- jQuery().jquery; 4- $().jquery

colorbox lightbox style with Close and title in top.

Image
To change style to bellow style: download code from here :            https://github.com/msm2020/colorbox/tree/master/example5

get submit button id in Page_Load

The sender argument to the handler contains a reference to the control which raised the event. private void MyClickEventHandler(object sender, EventArgs e) { Button theButton = (Button)sender; ... } Edit: Wait, in the Load event? That's a little tricker. One thing I can think of is this: The Request's Form collection will contain a key/value for the submitting button, but not for the others. So you can do something like: protected void Page_Load(object sender, EventArgs e) { Button theButton = null; if (Request.Form.AllKeys.Contains("button1")) theButton = button1; else if (Request.Form.AllKeys.Contains("button2")) theButton = button2; ... } Not very elegant, but you get the idea..

Escape an Underscore Like cause

if you search about Underscore this query will not get a true value Where Username Like '%_d' so you need to use : Where Username LIKE '%[_]d'

string contains in Jquery

Like this: if (str.indexOf("Yes") >= 0) Note that this is case-sensitive. If you want a case-insensitive search, you can write if (str.toLowerCase().indexOf("yes") >= 0) Or, if (/yes/i.test(str))

Operation must use an updateable query

One quite likely reason is that the user running the program doesn't have read-write access to the database file, especially if it is located in program files folder,make sure excel not mark as "Read Only" So check the directory and file permissions and moodify them if needed. You can also consider changing the location of the database file to another, more asily accessible folder.

Gridview RowDataBound - extract data from a field

Use DataItem of the GridViewRow instead of DataBinder.Eval to get the underlying datasource: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState == DataControlRowState.Edit)) { DataRow row = ((DataRowView)e.Row.DataItem).Row; String name = row.Field ("Name"); // OR name = row[1]; // String is a reference type, so you just need to compare with null if(name != null){/* do something */} } }

Changing the color of a row in a GridView in ASP.NET

Change the color of a row depending on whether the Doctor is Active or Inactive protected void grdview_RowDataBound(object sender, GridViewRowEventArgs e) { { if (e.Row.RowType == DataControlRowType.DataRow) { if ((string.IsNullOrEmpty(e.Row.Cells[3].Text) != true) || (e.Row.Cells[3].Text != " ")) { Char result = Convert.ToInt32(e.Row.Cells[3].Text); if (result == ‘Y’) e.Row.BackColor = System.Drawing.Color.Aqua; else if (result ==’N’) e.Row.BackColor = System.Drawing.Color.Cornsilk; } } } } Change the Color of the cells depending on the Value of a column protected void grd_RowDataBound(object sender, GridViewRowEventArgs e) { { if (e.Row.RowType == DataControlRowType.DataRow) { if ((string.IsNullOrEmpty(e.Row.Cells[3].Text) != true) || (e.Row.Cells[3].Text != " "))

Run A Macro When Worksheet Opens Excel

In the VBA editor, put the following code in the "This Workbook" sheet: Private Sub Workbook_Open() MsgBox "I just opened my workbook" End Sub then save the workbook, close it, and open it again to see if this is what you want.

check radio button is checked using JQuery

Given a group of radio buttons: <input type="radio" id="radio1" name="radioGroup" value="1"> <input type="radio" id="radio2" name="radioGroup" value="2"> You can test whether a specific one is checked using jQuery as follows: if ($("#radio1").prop("checked")) { // do something } // OR if ($("#radio1").is(":checked")) { // do something } // OR if you don't have ids set you can go by group name and value // (basically you need a selector that lets you specify the particular input) if ($("input[name='radioGroup'][value='1']").prop("checked"))

C# Crop white space from around the image

This code will crop the image based on all white and transparent pixels from around the image public static Bitmap CropWhiteSpace(Bitmap bmp) { int w = bmp.Width; int h = bmp.Height; int white = 0xffffff; Func allWhiteRow = r => { for (int i = 0; i < w; ++i) if ((bmp.GetPixel(i, r).ToArgb() & white) != white) return false; return true; }; Func allWhiteColumn = c => { for (int i = 0; i < h; ++i) if ((bmp.GetPixel(c, i).ToArgb() & white) != white) return false; return true; }; int topmost = 0; for (int row = 0; row < h; ++row) { if (!allWhiteRow(row)) break; topmost = row; } int bottommost = 0; for (int row = h - 1; row >= 0; --row) { if (!allWhiteRow(row)) break; bottommost = row; } int leftmost = 0, rightmost = 0; for (int col = 0; col < w; ++col) { if (!allWhiteColumn(col)) break; leftmost = col; } for (int col =

A generic error occurred in GDI+. Outputting image to response output stream giving GDI+ error

Some format needs to be saved to a seekable stream. Using an intermediate MemoryStream will do the trick: using (Bitmap image = new Bitmap(context.Server.MapPath("images/stars_5.png"))) { using(MemoryStream ms = new MemoryStream()) { image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); ms.WriteTo(context.Response.OutputStream); } }

Using CASE Statements In A SQL UPDATE Query

user following CASE statement: UPDATE [account] SET balance = ( CASE WHEN ((balance - 10.00) < 0) THEN 0 ELSE (balance - 10.00) END ) WHERE id = 1

Unsupported Operation. A document processed by the JRC engine cannot be opened in the C++ stack. Crystal Report

Image
First, you have to check your ReportPath if is correct rpt.Load(Server.MapPath("crMembers.rpt"));

Convert a string to an enum

User Enum.Parse is your friend enum StatusEnum {Active,Inactive} StatusEnum MyStatus = (StatusEnum) Enum.Parse( typeof(StatusEnum), "Active");

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=xx.0.0.0, Culture=neutral, PublicKeyToken='xxx' or one of its dependencies.

Scenarios: -If you get the following errors:  Could not load file or assembly Microsoft.ReportViewer.Common Could not load file or assembly Microsoft.ReportViewer. ProcessingObjectModel Server Error in '/' Application. Parser Error Description:  An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message:  Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

Using NULLIF() To Prevent Divide-By-Zero Errors In SQL

In case you want to return zero, in case a zero devision would happen, you can use: SELECT ( 45 / NULLIF( 0, 0 ) ) AS value For every divisor that is zero, you will get a zero in the result set

SQL SERVER – Dividing of Two Integer to get Float Value

if you make simple devide you will get integer without round value so you need to cast int to float Ex : SELECT (CAST(Number1)AS FLOAT)/Number1) AS AnswerFloat1

How do I flip a bit in SQL Server, Boolean 'NOT' in T-SQL

Use the ~ operator: DECLARE @Bool bit SET @Bool = 0 SET @Bool = ~@Bool SELECT @Boole

change chartset from Code

You can use Like this Code private string ConvertUnicode(string Str) { Encoding latinEncoding = Encoding.GetEncoding("Windows-1252"); Encoding ArabicEncoding = Encoding.GetEncoding("Windows-1256"); byte[] latinBytes = latinEncoding.GetBytes(Str); return ArabicEncoding.GetString(latinBytes); }

jQuery lightbox

prettyPhoto is a jQuery lightbox clone. Not only does it support images, it also support for videos, flash, YouTube, iframes and ajax. It’s a full blown media lightbox. http://www.no-margin-for-errors.com/projects/prettyphoto-jquery-lightbox-clone/#prettyPhoto

How to call object in Parent Iframe by jQuery

To find in the parent of the iFrame use: $('#parentPrice', window.parent.document).html(); The second parameter for the $() wrapper is the context in which to search. This defaults to document.

SessionID in ASP.NET MVC

session Id every 2-3 request will be changes shouldn't it remain the same because : ASP.NET keeps assigning new session ids until you place something into the Session variable Session.SessionID so you can't use it for make it use Session Start and save a variable on Session. Like this : void Session_Start(object sender, EventArgs e) { session["SessionID"] = Guid.NewGuid().ToString(); }

Mobile Device Detection ASP.NET

In ASP.NET, you can easily detect the mobile device request using Request.Browser.IsMobileDevice property and Request.UserAgent. The following code checks the IsMobileDevice property and redirects to the mobile specific page: protected void Page_Load(object sender, EventArgs e) { if (Request.Browser.IsMobileDevice) { Response.Redirec("~/default_mobile.aspx"); } } In MVC3 exposes an IsMobileDevice flag in the Request.Browser object. So in your razor code, you can query this variable and render accordingly. For example, @if (Request.Browser.IsMobileDevice) { HTML here for mobile device } else { HTML for desktop device }

add option to select combobox

To add option to select you can use : $('#selectname').append($(" ").attr("value", value).text(text)); If you need to append multi value you can user: $.each(data, function(i, option) { $('#selectname').append($(' ').attr("value", option.id).text(option.name)); }); If you need to add option to first "top" of list use $('#sel_bat1').children(":first").before($(" ").attr("value", value).text(text));

Show a message when DataList is Empty

you can add on footer or header template as show on code below : <footertemplate> <asp:label id="lblNoData" runat="server" text="No Rows Found!" visible="<%#bool.Parse((DataListName.Items.Count==0).ToString())%>"></asp:label> </footertemplate>

Get absolute URL on Javascript MVC 4

to get absolute URL on Javascript @Url.Action("Numbers","Home"),

deployment - Deployed ASP.NET MVC 4

Update runAllManagedModulesForAllRequests to true in web.config: ...

How to use Resource files in javascript

to access the Global Resources var globalResource = '<%= Resources.Class.ResourceKey %>'; to access the Local resources var localResource = '<%= GetLocalResourceObject("ResourceKey").ToString() %>';

Select n random rows from SQL Server table

select top 10 percent * from [yourtable] order by newid() In response to the "pure trash" comment concerning large tables: you could do it like this to improve performance. select * from [yourtable] where [yourPk] in (select top 10 percent [yourPk] from [yourtable] order by newid()) The cost of this will be the key scan of values plus the join cost, which on a large table with a small percentage selection should be reasonable.

Verifying that a string contains only letters in C#

Only letters: Regex.IsMatch(input, @"^[a-zA-Z]+$"); Only letters and numbers: Regex.IsMatch(input, @"^[a-zA-Z0-9]+$"); Only letters, numbers and underscore: Regex.IsMatch(input, @"^[a-zA-Z0-9_]+$");

Reset Identity column after deleting record from table

DBCC CHECKIDENT can reseed (reset) the identity value of the table. For example, YourTable has 25 rows with 25 as last identity. If we want next record to have identity as 35 we need to run following T SQL script in Query Analyzer DBCC CHECKIDENT (yourtable, reseed, 34)

The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine

changed the application configuration to x86

get mouse click if inside a div or not

Use this Code : $("body > div").click(function() { if ($(this).attr("id") == "in_or_out") { // inside } else { // not inside } }); OR $(document).mouseup(function (e) { var container = $("YOUR CONTAINER SELECTOR"); if (container.has(e.target).length === 0) { container.hide(); } });

Unsafe JavaScript attempt to access frame with URL from frame with URL youtube

best solution to use youtube API : jQuery(document).ready(function() { var Vid = 'youtubeId'; var params = { allowScriptAccess: "always" }; var atts = { id: "myytplayer" }; swfobject.embedSWF("http://www.youtube.com/v/" + Vid + "?enablejsapi=1&playerapiid=ytplayer&version=3", "ytapiplayer", "320", "315", "8", null, null, params, atts); }); and add Div with ID "ytapiplayer"

HttpContext.Current.Session is null (Inside WebService)

[WebMethod(EnableSession = true)] public void SomeMethod() { ... code here }

numeric up down "spinner"

use Jquery UI $( "#spinner" ).spinner();

sum int array values

we will loop to sum all values : if we have an array like <ul> <li class='price'>10</li> <li class='price'>5</li> <li class='price'>3</li> <li class='price'>11</li> </ul> summ will get by : $('.price').blur(function () { var sum = 0; $('.price').each(function() { sum += Number($(this).html()); }); });​​​​​​​​​

Parse to Int - Float Javascript

convert to Int var intvar = parseInt('1'); var Floatvar = parseFloat('10.52');

Ubuntu intallation is stuck at vmware tools installation

Problem is : When I finish the intallation Ubuntu , the VMware automatically installed the VMware Tools, and it was stuck at this scene. The scene is like this: ****************************************************************** ****************************************************************** Vmware Easy Install PLEASE WAIT! VMware Tools is currently being installed on your system. Depending on the version of Ubuntu you are installing, you may log in below and use the system during intallation. Otherwise, please wait for the graphical environment to launch. Thank you. ****************************************************************** ****************************************************************** ubuntu login:_ Solution : 1- Restore the /etc/issue file: sudo mv /etc/issue.backup /etc/issue 2- Restore the /etc/rc.local file: sudo mv /etc/rc.local.backup /etc/rc.local 3- Restore the /etc/init/lightdm.conf file: sudo mv /opt/vmware-tools-installer/lightdm.conf /etc/

Event for user pressing enter in a textbox

to make event when click to any input you can use : $('textarea').keyup(function(e){ if(e.keyCode == 13) { // code here } });

FTP upload, download, delete ,get files asp.net

you first need to download FtpClient.cs from here once you add this file to your project you can upload - download - delete and get files from FTP servers - To get all files from ftp: FTPclient ftPclient = new FTPclient("XXX.XXX.X.XX", "xx-xx", "xx-xx"); foreach (FTPfileInfo ky in ftPclient.ListDirectoryDetail("")) { TreeNode trParent = new TreeNode(); trParent.Text = ky.Filename; trParent.Value = ky.FullName; trVFiles.Nodes.Add(trParent); } - To Upload Files if (Fileupload1.HasFile) { FTPclient ftPclient = new FTPclient("XXX.XXX.X.XX", "xx-xx", "xx-xx"); ftPclient.Upload(fu_FtFile.FileContent, fu_FtFile.FileName); } - To Download Files: FTPclient ftPclient = new FTPclient("XXX.XXX.X.XX", "xx-xx", "xx-xx"); byte[] _downFile = ftPclient.Download(e.CommandArgument.T

max File size can upload to ASp.net servers

- default upload file size if 4MB - To increase it, please use this below section in your web.config - Max value to upload : 2,147,483,647 = 2GB <configuration> <system.web> <httpRuntime maxRequestLength="2147483647" /> </system.web> </configuration> - Max value to upload: 4,294,967,295 = 4GB - you can upload Files more than 2GB use below code : <system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="4294967295" /> </requestFiltering> </security> </system.webServer>