Archive
AngularJS Form Validation – Disable Submit / Confirm Password Custom Directive
How to launch Bootstrap modal on page load
To open bootstrap modal popup on page load use following
You can use the Bootstrap .modal('show')
method for launching the modal window automatically when page load without clicking anything. A common example of this technique is loading the modal when user landed on the home page
Use the Bootstrap .modal('show')
method
Example:
http://jsfiddle.net/rahuladmin/rL4jufcL/
Hope this help !
Add Days to Javascript Date Object
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
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
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
<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
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!
Comments