Archive

Posts Tagged ‘JavaScript’

AngularJS Form Validation – Disable Submit / Confirm Password Custom Directive

January 21, 2016 Leave a comment

http://jsfiddle.net/rahuladmin/9ew85Lp3/

Hope this help !

Bootstrap collapse: Change display of icons and text

December 17, 2015 Leave a comment

To Change display of icons and text for bootstrap Collapse use following

http://jsfiddle.net/rahuladmin/s52h0sbj/

Hope this help !

Add Days to Javascript Date Object

November 19, 2015 Leave a comment

To add days to javascript date object use following syntax

var dayOffset = 20;

var millisecondOffset = dayOffset * 24 * 60 * 60 * 1000;

december.setTime(december.getTime() + millisecondOffset);

Open FancyBox from Code behind on button click

November 25, 2014 Leave a comment

Add link like following which redirect to popup page that you want to open on button click using fancybox

[1] <a href=”../Scripts/ValidationMessage.aspx” class=”fancybox fancybox.iframe” id=”hiddenlink_confirm” />

Add following js function on head of page along with fancybox script

[2] <script type=”text/javascript”>

function OpenValidationMessagePopup() {
var alink = document.getElementById(“hiddenlink_confirm”);
alink.click();
}

[3] Write following code on button click event

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click

Dim sb As New StringBuilder()

sb.AppendFormat(“OpenValidationMessagePopup();”)
ScriptManager.RegisterStartupScript(Me.Page, Me.[GetType](), “OpenValidationMessagePopup” + DateAndTime.Now, sb.ToString(), True)

End Sub

Will add some more information to the above steps, hope this help !

Javascript ‘confirm()’ Cancelling Post Back

November 24, 2014 Leave a comment

Problem : Postback is not working on javascript confirm() Click

Solution :

 <asp:Button runat="server" ID="btnSubmit" Text="Submit" OnClick="BtnSubmit_Click"
 OnClientClick="if (!confirm('Are you sure you want to Submit?')) return false;"/>

Hope this help !

 

 

How to find control with in repeater on button click event

December 10, 2013 Leave a comment

<asp:Repeater ID=”RptInfo” runat=”server”>

<ItemTemplate>

<asp:Panel ID=”pnlReadonly” runat=”server”>

….

</asp:Panel>

</ItemTemplate>

</asp:Repeater>

Code : 

Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click

Dim pnlReadonly As Panel = DirectCast(RptSoccerInfo.Items(0).FindControl(“pnlReadonly”), Panel)

If (Not pnl Is Nothing) Then
‘ some code
End If

End Sub

Will add some more detail soon .

Bundling and minification in MVC3 and Asp.Net 4.0

March 6, 2013 1 comment

Adding references:

First of all add the references of System.Web.Optimization.dll and WebGrease.dll to your MVC3 and Asp.Net 4.0 projects as shown below. You can download the dll by using download link.


Creating Bundle:

Now create the bundle for your css and js files with in the Global.asax file as shown below.

Here, I have created the bundle of all required css and js files. You can also add your own css and js files with complete path using Include method.

Registering Bundle:

Adding Bundles to Layout Page in MVC3:

Now you can add the above created style and script bundles to the Layout page or where you want to use as shown below:

Adding Bundles to Master Page in Asp.Net 4.0:

Now you can add the above created style and script bundles to the Master page or where you want to use as shown below:

In Asp.Net 4.0 you also required to add System.Web.Optimization namespace and assembly Microsoft.AspNet.Web.Optimization.WebForms reference to the web.config file of your Asp.Net 4.0 project as shown below:

You need not to do any changes in web.config file of your MVC3 project.

Enabling Bundling and Minification in debug mode

Bundling and minification doesn’t work in debug mode. So to enable this features you need to add below line of code with in Application_Start event of Global.asax.

How it works..

Now run your application and you will see that all the css and js files are converted to single css and js file as shown below:

Minification

Minification is technique for removing unnecessary characters (like white space, newline, tab) and comments from the JavaScript and CSS files to reduce the size which cause improved load times of a webpage. There are so many tools for minifying the js and css files. JSMin and YUI Compressor are two most popular tools for minifying the js and css files. Use these tools for minifiying your css and js files and use in your application with “.min” suffix. So that you can easily identified that this is a minimize version of your css or js file.

Hope it helps!