tag:blogger.com,1999:blog-89967953977101658392024-03-19T02:28:14.253-07:00Dot Net Gorilla - A Technical Community for Developers and ProgrammersASP.NET Interview questions and answers,ASP.NET MVC Interview,C#,Sql Server,java script,AJAX error and help while development. ASP.NET Error & Solution,ASP.NET page life cycle.asp.net tutorials,WCF interview,a complete software development blog for help to developer.Unknownnoreply@blogger.comBlogger163125tag:blogger.com,1999:blog-8996795397710165839.post-65541561445095695932018-11-22T07:56:00.000-08:002018-11-22T07:56:28.349-08:00Specified argument was out of the range of valid values. Parameter name: site<div dir="ltr" style="text-align: left;" trbidi="on">
<h1 class="grid--cell fs-headline1 fl1 wb-break-all" itemprop="name" style="background-color: white; border: 0px; box-sizing: inherit; color: #242729; flex: 1 1 auto !important; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; font-weight: inherit; line-height: 1.3; margin: 0px 0px 0.5em; padding: 0px; vertical-align: baseline; word-break: break-all !important;">
<span style="font-size: small;">Specified argument was out of the range of valid values. Parameter name: site</span></h1>
<div>
While development many time we face this issue.It come generally when we change pc or laptop ,we just install visual studio and sql server and start our project.We forget to enable IIS setting so this error comes.</div>
<div>
Solution : </div>
<div>
Please open </div>
<div>
<span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;"> </span><strong style="background-color: white; border: 0px; box-sizing: inherit; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">Control Panel</strong><span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;"> -> </span><strong style="background-color: white; border: 0px; box-sizing: inherit; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">Programs</strong><span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;"> -> </span><strong style="background-color: white; border: 0px; box-sizing: inherit; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">Programs and Features</strong><span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;"> -> </span><strong style="background-color: white; border: 0px; box-sizing: inherit; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">Turn Windows features on or off</strong><span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;"> -> </span><strong style="background-color: white; border: 0px; box-sizing: inherit; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">Internet Information Services</strong><span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;"> and check the Internet Information Service if unchecked.</span></div>
<div>
<span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;"><br /></span></div>
<div>
<span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;">Image for reference :</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-qNwn_oOPU5E/W_bRXbEHPGI/AAAAAAAARp0/cWGVghlGwOEaIhbLDQwZdv_NbQDmp-CSACLcBGAs/s1600/dotneterr.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="367" data-original-width="420" height="279" src="https://3.bp.blogspot.com/-qNwn_oOPU5E/W_bRXbEHPGI/AAAAAAAARp0/cWGVghlGwOEaIhbLDQwZdv_NbQDmp-CSACLcBGAs/s320/dotneterr.png" width="320" /></a></div>
<div>
<span style="background-color: white; color: #242729; font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 15px;"><br /></span></div>
</div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-59783814141010593212018-11-19T01:16:00.002-08:002018-11-19T01:16:50.620-08:00 Action Filters in asp.net MVC<div dir="ltr" style="text-align: left;" trbidi="on">
<strong style="background-color: white; box-sizing: border-box; color: #212121; font-family: "open sans", sans-serif; font-size: 14px;"><span style="box-sizing: border-box; font-size: 14pt;">What are Action Filters in asp.net MVC?</span></strong><br />
<strong style="background-color: white; box-sizing: border-box; color: #212121; font-family: "open sans", sans-serif; font-size: 14px;"><span style="box-sizing: border-box; font-size: 14pt;"><br /></span></strong>
<span style="color: #212121; font-family: open sans, sans-serif;">ASP.NEt MVC provides a very clean way of injecting the pre-processing and post-processing logic for actions and controllers. We can put</span><span style="color: #212121; font-family: "open sans", sans-serif;"> the pre-processing and post-processing logic is by decorating the actions with attributes which will invoke an attribute class implementing </span><span style="color: #212121; font-family: "open sans", sans-serif;"> the filter's logic.</span><br />
<span style="color: #212121; font-family: open sans, sans-serif;"><br /></span>
<span style="color: #212121; font-family: open sans, sans-serif;">For example, If we need some action to be executed when the user has authenticated after that we can adorn the action with the [Authorize] </span><span style="color: #212121; font-family: "open sans", sans-serif;">attribute. This implements the authorization filter to check whether the user has is </span><br />
<span style="color: #212121; font-family: open sans, sans-serif;">authorized or not.</span><br />
<span style="color: #212121; font-family: open sans, sans-serif;"><br /></span>
<span style="color: #212121; font-family: open sans, sans-serif;">[Authorize]</span><br />
<span style="color: #212121; font-family: open sans, sans-serif;">public ActionResult Index()</span><br />
<span style="color: #212121; font-family: open sans, sans-serif;">{</span><br />
<span style="color: #212121; font-family: open sans, sans-serif;"> return View();</span><br />
<span style="background-color: white; box-sizing: border-box;"><span style="color: #212121; font-family: open sans, sans-serif;"><span style="box-sizing: border-box;"></span></span></span><br />
<span style="color: #212121; font-family: open sans, sans-serif;">}</span><br />
<span style="color: #212121; font-family: open sans, sans-serif;"><br /></span>
<span style="color: #212121; font-family: open sans, sans-serif;">Actually action Filters are additional attributes that can be applied to either a controller or the entire controller to modify the</span><span style="color: #212121; font-family: "open sans", sans-serif;"> way in which action is executed. These attributes are special .NET classes derived from System.Attribute which can be attached to </span><span style="color: #212121; font-family: "open sans", sans-serif;"> classes, methods, properties and fields.</span><br />
<span style="color: #212121; font-family: open sans, sans-serif;"><br /></span>
<span style="color: #212121; font-family: open sans, sans-serif;">MVC provides the following action filters:</span><br />
<span style="color: #212121; font-family: open sans, sans-serif;"><b>Output Cache:</b> This action filter caches the output of a controller action for a specified amount of time.</span><br />
<span style="color: #212121; font-family: open sans, sans-serif;"><b>Handle Error:</b> This action filter handles errors raised when a controller action executes.</span><br />
<span style="color: #212121; font-family: open sans, sans-serif;"><b>Authorize:</b> This action filter enables you to restrict access to a particular user or role.</span><br />
<span style="color: #212121; font-family: open sans, sans-serif;"><br /></span>
<h2 style="background-color: white; box-sizing: border-box; color: #212121; font-family: Roboto, sans-serif; font-weight: 400; line-height: 1.1; margin-bottom: 0px; margin-top: 0px;">
<span style="font-size: large;">Types of filters</span></h2>
<div style="background-color: white; box-sizing: border-box; color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">
</div>
<div style="background-color: white; box-sizing: border-box; color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">
ASP.NET MVC supports following types of filters:</div>
<div style="background-color: white; box-sizing: border-box;">
<ol style="box-sizing: border-box; color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">
<li style="box-sizing: border-box;"><span style="box-sizing: border-box;">Action Filters</span></li>
<li style="box-sizing: border-box;"><span style="box-sizing: border-box;">Authorization Filters</span></li>
<li style="box-sizing: border-box;"><span style="box-sizing: border-box;">Result Filters</span></li>
<li style="box-sizing: border-box;"><span style="box-sizing: border-box;">Exception Filters</span></li>
</ol>
<div style="color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><b>Action filter</b></span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">Action filter will be called before and after the action starts executing and after the action has executed. We can put our custom pre-processing and post-processing logic in this filter.</span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">Now to implement this filter we need to create a custom filter attribute class and implement the</span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<br /></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<b><span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">IActionFilter </span></span><span style="color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">interface</span></b></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">This interface provides us two methods OnActionExecuting and OnActionExecuted which will be called before and after the action gets executed respectively.</span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<br /></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">public class CustomActionAttribute : FilterAttribute, IActionFilter</span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">{</span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext)</span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> {</span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> filterContext.Controller.ViewBag.OnActionExecuted = "IActionFilter.OnActionExecuted filter called";</span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> }</span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)</span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> {</span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> filterContext.Controller.ViewBag.OnActionExecuting = "IActionFilter.OnActionExecuting filter called";</span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> }</span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">}</span></span></div>
<div style="color: black; font-family: "Times New Roman"; font-size: medium;">
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
</div>
<div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><b>Authorization filter</b></span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">This filter provides authentication and authorization logic. It will be executed before the action gets executed. To implement this action the interface IAuthorizationFilter should be implemented by the custom attribute class.</span></span></div>
<div>
<br /></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">public class CustomAuthorizationAttribute : FilterAttribute, IAuthorizationFilter</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">{</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> void IAuthorizationFilter.OnAuthorization(AuthorizationContext filterContext)</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> {</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> filterContext.Controller.ViewBag.OnAuthorization = "IAuthorizationFilter.OnAuthorization filter called";</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> }</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">}</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<br /></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><b>Result filter</b></span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">Result filter will execute before and after the result of the action method has been executed. We can use this filter if we want some modification to be done in the action's result.</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<b><span style="color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">IResultFilter </span><span style="color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">interface</span></b></div>
<div>
<span style="color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">This interface provides two methods OnResultExecuting and OnResultExecuted which will be called before and after the action result respectively.</span></div>
<div>
<br /></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">public class CustomResultAttribute : FilterAttribute, IResultFilter</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">{</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> void IResultFilter.OnResultExecuted(ResultExecutedContext filterContext)</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> {</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> filterContext.Controller.ViewBag.OnResultExecuted = "IResultFilter.OnResultExecuted filter called";</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> }</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> void IResultFilter.OnResultExecuting(ResultExecutingContext filterContext)</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> {</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> filterContext.Controller.ViewBag.OnResultExecuting = "IResultFilter.OnResultExecuting filter called";</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> }</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">}</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><b>Exception filter</b></span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">Exception filter will be invoked whenever a controller or action of the controller throws an exception. This is particularly useful when we need custom error logging module.</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">To implement this filter we need to create a custom filter attribute class which implements IExceptionFilter. This interface gives us a methods called OnException which is a perfect place to call the exception logging module and to redirect to some error page.</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<span style="color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">public class CustomExceptionAttribute : FilterAttribute, IExceptionFilter</span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">{ </span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> void IExceptionFilter.OnException(ExceptionContext filterContext)</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> {</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> filterContext.Controller.ViewBag.OnException = "IExceptionFilter.OnException filter called";</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"> }</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">}</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><b>Order of Execution of action filter as following</b></span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<span style="color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">IAuthorizationFilter.OnAuthorization</span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">IActionFilter.OnActionExecuted</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">IActionFilter.OnActionExecuting</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">IResultFilter.OnResultExecuted</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">IResultFilter.OnResultExecuting</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;">IExceptionFilter.OnException</span></span></div>
<div>
<span style="color: #212121; font-family: open sans, sans-serif;"><span style="font-size: 14px;"><br /></span></span></div>
<div>
<br /></div>
</div>
</div>
</div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-60749965169592977342018-09-17T22:35:00.000-07:002018-09-17T22:42:14.765-07:00Cascading drop-down list in asp.net Grid view | Dependent Dropdownlist inside GridView<div dir="ltr" style="text-align: left;" trbidi="on">
<pre nbsp="" style="background-image: URL(https://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;">
</pre>
Here i am going to explain how to do cascading drop down list in asp.net webform.code is copied from my project so not able to formatted properly due to lack of time.but you see the code and understand the implementation.<br />
<div>
<br /></div>
<div>
<b>.aspx code</b></div>
OnRowCommand="gvCity_RowCommand" OnRowEditing="gvCity_RowEditing" OnRowCancelingEdit="gvCity_RowCancelingEdit"<br />
OnRowUpdating="gvCity_RowUpdating" OnRowDeleting="gvCity_RowDeleting" ShowFooter="True"<br />
PageSize="20" Width="100%"&gt;<br />
runat="server"&gt;<br />
AutoPostBack="true" OnSelectedIndexChanged="ddlNewCountrygvCity_SelectedIndexChanged"<br />
Visible="false" runat="server"&gt;<br />
runat="server"&gt;<br />
Visible="false" Enabled="false" runat="server"&gt;<br />
Visible="false"&gt;<br />
OnClientClick="return CityUpdateValidate();" ImageUrl="~/Image/update.png" ToolTip="Update"<br />
ToolTip="Cancel" ImageUrl="~/Image/cancel.png" /&gt;<br />
CommandName="AddNew" ToolTip="Add New" /&gt;<br />
OnClick="ibtnNewCityInsert_Click" ImageUrl="~/Image/add.png" Visible="false"<br />
ToolTip="Insert" /&gt; <br />
ToolTip="Cancel" ImageUrl="~/Image/cancel.png" Visible="false" /&gt;<br />
ImageUrl="~/Image/img_edit.png" ToolTip="Edit" /&gt;<br />
ImageUrl="~/Image/img_delete.png" OnClientClick="return ConfirmDelete();" ToolTip="Delete"<br />
<br />
<b> .cs code</b><br />
public void gvCityBind()<br />
{<br />
dsCity = SqlHelper.ExecuteDataset(connectionString, "genCityMaster_SelectDelete", 0, "NULL", "S");<br />
if (dsCity.Tables[0].Rows.Count &gt; 0)<br />
{<br />
gvCity.DataSource = dsCity;<br />
gvCity.DataBind();<br />
}<br />
else<br />
{<br />
NoDataFound(dsCity, gvCity);<br />
SrNoCity = 1;<br />
}<br />
}<br />
protected void gvCity_PageIndexChanging(object sender, GridViewPageEventArgs e)<br />
{<br />
gvCity.PageIndex = e.NewPageIndex;<br />
gvCityBind();<br />
}<br />
protected void gvCity_RowDataBound(object sender, GridViewRowEventArgs e)<br />
{<br />
if (e.Row.RowType == DataControlRowType.DataRow)<br />
{<br />
Label lblSrNo = (Label)e.Row.FindControl("lblSrNo");<br />
lblSrNo.Text = Convert.ToString(gvCity.PageIndex * gvCity.PageSize + SrNoCity);<br />
SrNoCity++;<br />
DropDownList ddlCountry = (DropDownList)e.Row.FindControl("ddlCountry");<br />
DropDownList ddlState = (DropDownList)e.Row.FindControl("ddlState");<br />
if (ddlCountry != null)<br />
{<br />
ddlCountry.DataSource = objCountryBLL.SelectCounrty();<br />
ddlCountry.DataBind();<br />
ddlCountry.SelectedValue = dsCity.Tables[0].Rows[e.Row.RowIndex]["CountryId"].ToString();<br />
}<br />
if (ddlState != null)<br />
{<br />
ddlState.DataSource = objStateBLL.SelectState(Convert.ToInt32(ddlCountry.SelectedValue));<br />
ddlState.DataBind();<br />
ddlState.SelectedValue = dsCity.Tables[0].Rows[e.Row.RowIndex]["StateId"].ToString();<br />
}<br />
}<br />
if (e.Row.RowType == DataControlRowType.Footer)<br />
{<br />
DropDownList ddlNewCountry = (DropDownList)e.Row.FindControl("ddlNewCountry");<br />
DropDownList ddlNewState = (DropDownList)e.Row.FindControl("ddlNewState");<br />
if (ddlNewCountry != null)<br />
{<br />
ddlNewCountry.DataSource = objCountryBLL.SelectCounrty();<br />
ddlNewCountry.DataBind();<br />
}<br />
if (ddlNewState != null)<br />
{<br />
ddlNewState.DataSource = objStateBLL.SelectState(Convert.ToInt32(ddlNewCountry.SelectedValue));<br />
ddlNewState.DataBind();<br />
}<br />
}<br />
}<br />
protected void gvCity_RowCommand(object sender, GridViewCommandEventArgs e)<br />
{<br />
try<br />
{<br />
if (e.CommandName.Equals("AddNew"))<br />
{<br />
gvCity.EditIndex = -1;<br />
gvCityBind();<br />
gvCity.FooterRow.CssClass = objCommonDAL.GetGrigViewFooterStyle();<br />
Label lblNewSrNo = (Label)gvCity.FooterRow.FindControl("lblNewSrNo");<br />
lblNewSrNo.Text = SrNoCity.ToString();<br />
ImageButton ibtnNewCityInsert = (ImageButton)gvCity.FooterRow.FindControl("ibtnNewCityInsert");<br />
ImageButton imgbtnNewCancel = (ImageButton)gvCity.FooterRow.FindControl("imgbtnNewCancel");<br />
ImageButton imgbtnNewAdd = (ImageButton)gvCity.FooterRow.FindControl("imgbtnNewAdd");<br />
ibtnNewCityInsert.Visible = true;<br />
imgbtnNewCancel.Visible = true;<br />
imgbtnNewAdd.Visible = false;<br />
DropDownList ddlNewCountry = (DropDownList)gvCity.FooterRow.FindControl("ddlNewCountry");<br />
ddlNewCountry.Visible = true;<br />
ddlNewCountry.Focus();<br />
DropDownList ddlNewState = (DropDownList)gvCity.FooterRow.FindControl("ddlNewState");<br />
ddlNewState.Visible = true;<br />
TextBox txtNewCity = (TextBox)gvCity.FooterRow.FindControl("txtNewCity");<br />
txtNewCity.Visible = true;<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
throw ex;<br />
}<br />
}<br />
protected void ibtnNewCityInsert_Click(object sender, ImageClickEventArgs e)<br />
{<br />
try<br />
{<br />
objCity.StateId = Convert.ToInt32(((DropDownList)gvCity.FooterRow.FindControl("ddlNewState")).SelectedValue);<br />
objCity.CityName = Convert.ToString(((TextBox)gvCity.FooterRow.FindControl("txtNewCity")).Text);<br />
objCity.CreatedBy = Convert.ToInt32(UserId);<br />
objCity.ModifiedBy = Convert.ToInt32(UserId);<br />
objCity.CreatedOn = System.DateTime.Now;<br />
objCity.ModifiedOn = System.DateTime.Now;<br />
try<br />
{<br />
int intResultInsert = objCityBLL.InsertCity(objCity);<br />
if (intResultInsert &gt; 0)<br />
{<br />
exceptionMessage.Text = "Record Added Successfully !";<br />
gvCity.EditIndex = -1;<br />
gvCityBind();<br />
}<br />
else<br />
{<br />
exceptionMessage.Text = "This record already exists !";<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
exceptionMessage.Text = ex.Message.ToString();<br />
}<br />
finally<br />
{<br />
objCityBLL = null;<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
throw ex;<br />
}<br />
}<br />
protected void gvCity_RowEditing(object sender, GridViewEditEventArgs e)<br />
{<br />
gvCity.EditIndex = e.NewEditIndex;<br />
gvCityBind();<br />
}<br />
protected void gvCity_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)<br />
{<br />
gvCity.EditIndex = -1;<br />
gvCityBind();<br />
}<br />
protected void gvCity_RowUpdating(object sender, GridViewUpdateEventArgs e)<br />
{<br />
try<br />
{<br />
objCity.CityId = Convert.ToInt32(((Label)gvCity.Rows[e.RowIndex].FindControl("lblCityId")).Text);<br />
objCity.StateId = Convert.ToInt32(((DropDownList)gvCity.Rows[e.RowIndex].FindControl("ddlState")).SelectedValue);<br />
objCity.CityName = Convert.ToString(((TextBox)gvCity.Rows[e.RowIndex].FindControl("txtCity")).Text);<br />
objCity.CreatedBy = Convert.ToInt32(UserId);<br />
objCity.ModifiedBy = Convert.ToInt32(UserId);<br />
objCity.CreatedOn = System.DateTime.Now;<br />
objCity.ModifiedOn = System.DateTime.Now;<br />
int intResultUpdate = objCityBLL.UpdateCity(objCity);<br />
if (intResultUpdate &gt; 0)<br />
{<br />
exceptionMessage.Text = "Record Updated Successfully !";<br />
gvCity.EditIndex = -1;<br />
gvCityBind();<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
exceptionMessage.Text = ex.Message.ToString();<br />
}<br />
finally<br />
{<br />
objCityBLL = null;<br />
}<br />
}<br />
protected void gvCity_RowDeleting(object sender, GridViewDeleteEventArgs e)<br />
{<br />
try<br />
{<br />
objCity.CityId = (int)gvCity.DataKeys[e.RowIndex].Value;<br />
int result = objCityBLL.DeleteCity(objCity);<br />
if (result &gt; 0)<br />
{<br />
exceptionMessage.Text = "Row Deleted Successfully...!";<br />
gvCity.EditIndex = -1;<br />
gvCityBind();<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
exceptionMessage.Text = ex.Message.ToString();<br />
}<br />
}<br />
protected void ddlNewCountrygvCity_SelectedIndexChanged(object sender, EventArgs e)<br />
{<br />
DropDownList ddlNewCountry = (DropDownList)gvCity.FooterRow.FindControl("ddlNewCountry");<br />
DropDownList ddlNewState = (DropDownList)gvCity.FooterRow.FindControl("ddlNewState");<br />
if (Convert.ToInt32(ddlNewCountry.SelectedValue) &gt; 0)<br />
{<br />
ddlNewState.Enabled = true;<br />
ddlNewState.DataSource = objStateBLL.SelectState(Convert.ToInt32(ddlNewCountry.SelectedValue));<br />
ddlNewState.DataBind();<br />
}<br />
else<br />
{<br />
ddlNewState.Enabled = false;<br />
}<br />
} </div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-67652422978711001332018-09-16T22:18:00.004-07:002018-09-16T22:26:46.419-07:00Different return types of asp.net mvc controller action method<div dir="ltr" style="text-align: left;" trbidi="on">
<strong style="background-color: white; box-sizing: border-box; color: #212121; font-family: "open sans", sans-serif;"><span style="box-sizing: border-box;">Q.What are different return types of a controller action method?</span></strong><br />
<div style="background-color: white; font-family: "segoe ui", tahoma, arial, "helvetica neue", helvetica, sans-serif;">
<strong style="background-color: transparent; box-sizing: border-box; color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">Answer: </strong><span style="background-color: transparent; color: #212121; font-family: "open sans" , sans-serif; font-size: 14px;">There are total nine return types we can use to return results from controller to view. </span><span style="background-color: transparent; color: #212121; font-family: "open sans" , sans-serif; font-size: 14px;">The base type of all these result types is ActionResult.</span></div>
<ol style="background-color: white; box-sizing: border-box; color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">ViewResult (View)</strong>: View Result is used to return a webpage from an action method.</li>
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">PartialviewResult (Partialview)</strong>: PartialViewResult is used to send a part of a view which will be rendered in another view.</li>
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">RedirectResult (Redirect)</strong>: <span style="box-sizing: border-box;">RedirectResult</span> is used to redirect to any other controller and action method depending on the URL.</li>
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">RedirectToRouteResult (RedirectToAction, RedirectToRoute):</strong> This return type is used when we want to redirect to any other action method.</li>
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">ContentResult (Content)</strong>: <span style="box-sizing: border-box;">RedirectToRouteResult</span> is used to return HTTP content type like text/plain as the result of the action.</li>
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">jsonResult (json):</strong> <span style="box-sizing: border-box;">jsonResult</span> is used when we want to return a JSON message.</li>
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">javascriptResult (javascript):</strong> <span style="box-sizing: border-box;">javascriptResult</span> is used to return JavaScript code that will run in browser.</li>
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">FileResult (File):</strong> <span style="box-sizing: border-box;">FileResult</span> is used to send binary output in response.</li>
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">EmptyResult:</strong> <span style="box-sizing: border-box;">EmptyResult</span> is used to return nothing (void) in the result.</li>
</ol>
</div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-8996795397710165839.post-19344766906429055572018-09-16T22:15:00.002-07:002018-09-16T22:27:22.498-07:00Page lifecycle of an ASP.NET MVC | ASP.NET page life cycle<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Q.Explain “Page Life Cycle” of an ASP.NET MVC?</b><br />
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "segoe ui", tahoma, arial, "helvetica neue", helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
<b>Ans.</b>In traditional ASP.NET webform application each asp.net page implements the IHTTPHandler interface.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "segoe ui", tahoma, arial, "helvetica neue", helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
This interface has a ProcessRequest() method that gets called when you request the page. The ProcessRequest() method is responsible for processing the request and generating the response. So in asp.net application it is simple, you request for a page in the url like <a href="http://mysite1/default.aspx" style="background-color: transparent; box-sizing: border-box; color: #337ab7;">http://mylocalsite1\default.aspx</a> and then it search for that page on the local disk and execute the processrequest method and generate the html response.</div>
<div align="left" style="background-color: white; box-sizing: border-box; color: #333333; font-family: "segoe ui", tahoma, arial, "helvetica neue", helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
However in MVC application ,request response process is different from webform. In MVC there are no physical page exist for a particular request. All the requests are routed to a special class called Controller. The controller is responsible for generating the response and sending the content back to the browser.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "segoe ui", tahoma, arial, "helvetica neue", helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
When you build a MVC application you can define a bunch of controllers. Each controller can handle multiple requests. For example, all the following will route to same Controller.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "segoe ui", tahoma, arial, "helvetica neue", helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
These requests will execute the same Controller Controller1 and in that it will extract the id from the URL and process the request. This gives more readable URL then asp.net page.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "segoe ui", tahoma, arial, "helvetica neue", helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
So how these requests are routed to particular controller. Now the RouteTable come into the picture. Every ASP.NET MVC application has a RouteTable. This routetable is responsible to map the mvc requests to particular controller.</div>
<div style="background-color: white; box-sizing: border-box; margin-bottom: 10px;">
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;">public class MvcApplication : System.Web.HttpApplication</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;">{</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"><span style="white-space: pre;"> </span>public static void RegisterRoutes(RouteCollction routes)</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"><span style="white-space: pre;"> </span>{</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"><span style="white-space: pre;"> </span>routes.IgnoreRoute("{resource}.axd/{*pathInfo}");</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"><span style="white-space: pre;"> </span>routes.MapRoute(</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"><span style="white-space: pre;"> </span>"Default", // Route name</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"><span style="white-space: pre;"> </span>"{controller}/{action}/{id}", // URL with parameters</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"><span style="white-space: pre;"> </span>new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"><span style="white-space: pre;"> </span>);</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"> }</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"><br /></span></span><span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"><span style="white-space: pre;"> </span>protected void Application_Start()</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"><span style="white-space: pre;"> </span>{</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"><span style="white-space: pre;"> </span>AreaRegistration.RegisterAllAreas();</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"><span style="white-space: pre;"> </span>RegisterRoutes(RouteTable.Routes);</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;"><span style="white-space: pre;"> </span>}</span></span><br />
<span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 14px;">}</span></span></div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "segoe ui", tahoma, arial, "helvetica neue", helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
When Application Start the Application_Start events will get called and it will call the method RegisterRoutes which will send the collection of Routes as the parameter and the routes will be added to this Collection which is a Dictionary of NamedMaps.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "segoe ui", tahoma, arial, "helvetica neue", helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
Each route also references a handler which will handle the rest of the request. When we use MapRoute, what we really do is creating a route by instantiating the 3 dictionaries and defining the default MVC handler: PageRouteHandler. Each RouteHandler implements an interface IRouteHandler.</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; border-spacing: 0px; box-sizing: border-box; color: #333333; font-family: "segoe ui", tahoma, arial, "helvetica neue", helvetica, sans-serif; font-size: 14px;"><tbody style="box-sizing: border-box;">
<tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0px;" valign="top"><div style="box-sizing: border-box; margin-bottom: 10px;">
public Route MapPageRoute(string routeName, string routeUrl, string physicalFile, bool checkPhysicalUrlAccess, RouteValueDictionarydefaults, RouteValueDictionary constraints, RouteValueDictionary dataTokens)<br />
{<br />
<span style="white-space: pre;"> </span>if (routeUrl == null)<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>throw new ArgumentNullException("routeUrl");<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>Route item = new Route(routeUrl, defaults, constraints, dataTokens, new PageRouteHandler(physicalFile, checkPhysicalUrlAccess));<br />
<span style="white-space: pre;"> </span>this.Add(routeName, item);<br />
<span style="white-space: pre;"> </span>return item;<br />
}<br />
<div>
<br /></div>
</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
<span style="box-sizing: border-box; font-weight: 700;">Step 2: The URL Routing Module intercepts the request.</span></div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
Whenever you make a request against an ASP.NET MVC application, the request is intercepted by the UrlRoutingModule HTTP Module. </div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
When the UrlRoutingModule intercepts a request, the first thing the module does is to wrap up the current HttpContext in an HttpContextWrapper object.</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
The HttpContextWrapper object derives from HTTPContextBase class.</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
<br /></div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
private void OnApplicationPostResolveRequestCache(object sender, EventArgs e)<br />
{<br />
<span style="white-space: pre;"> </span>HttpApplication application = (HttpApplication) sender;<br />
<span style="white-space: pre;"> </span>HttpContextBase context = new HttpContextWrapper(application.Context);<br />
<span style="white-space: pre;"> </span>this.PostResolveRequestCache(context);<br />
}</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
Then the module send this contextBase object to the method called PostResolveRequestCache .</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
Based on the Context it will return the correct RouteData from the RouteTable which was created in the earlier step based on the URL, form parameters and query string parameters associated with the HTTPContext object. </div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
If the UrlRoutingModule successfully retrieves a RouteData object then the module next creates a RouteContext object that represents the current HttpContext and RouteData.</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
The module then instantiates a new HttpHandler based on the RouteTable and passes the RouteContext to the new handler’s constructor. </div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
In the case of an ASP.NET MVC application,the handler returned from the RouteTable will always be an MvcHandler. This MVCHandler also derive from interface IHTTPHandler and implement the method ProcessRequest().</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
The last step is it will call the RemapHandler method which will set the MVCHandler just obtained to be the Current HTTP Handler.</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
<br /></div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
public virtual void PostResolveRequestCache(HttpContextBase context)<br />
{<br />
<span style="white-space: pre;"> </span>RouteData routeData = this.RouteCollection.GetRouteData(context);<br />
<span style="white-space: pre;"> </span>if (routeData != null)<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>IRouteHandler routeHandler = routeData.RouteHandler;<br />
<span style="white-space: pre;"> </span>if (routeHandler == null)<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.GetString("UrlRoutingModule_NoRouteHandler"), new object[0]));<br />
<span style="white-space: pre;"> </span>}<br />
<br />
<span style="white-space: pre;"> </span>if (!(routeHandler is StopRoutingHandler))<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>RequestContext requestContext = new RequestContext(context, routeData);<br />
<span style="white-space: pre;"> </span>context.Request.RequestContext = requestContext;<br />
<span style="white-space: pre;"> </span>IHttpHandler httpHandler = routeHandler.GetHttpHandler(requestContext);<br />
<span style="white-space: pre;"> </span>if (httpHandler == null)<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, SR.GetString("UrlRoutingModule_NoHttpHandler"), new object[] { routeHandler.GetType() }));<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>if (httpHandler is UrlAuthFailureHandler)<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>if (!FormsAuthenticationModule.FormsAuthRequired)<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>throw new HttpException(0x191, SR.GetString("Assess_Denied_Description3"));<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>UrlAuthorizationModule.ReportUrlAuthorizationFailure(HttpContext.Current, this);<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>else<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>context.RemapHandler(httpHandler);<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>}<br />
}</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
<br /></div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
<span style="box-sizing: border-box; font-weight: 700;">Step 4: MVC Handler Executes</span></div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
MVCHandler also inherit from the IHTTPAsyncHandler. When MVC Handler executes it will call the BeginProcessRequest method of the httpAsyncHandler asynchronously.</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
When the process request method is called a new controller gets created. The controller is created from a ControllerFactory. There is a ControllerBuilder Class which will set the ControllerFactory. </div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
You can create your own ControllerFactory as well but by default it will be DefaultControllerFactory. The RequestContext and the name of the Contoller will be passed to the method CreateController Method to get the particular Contoller.</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: transparent; border-collapse: collapse; border-spacing: 0px; box-sizing: border-box;"><tbody style="box-sizing: border-box;">
<tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0px;" valign="top"><div style="box-sizing: border-box; margin-bottom: 10px;">
public virtual IController CreateController(RequestContext requestContext, string controllerName)<br />
{<br />
<span style="white-space: pre;"> </span>if (requestContext == null)<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>throw new ArgumentNullException("requestContext");<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>if (string.IsNullOrEmpty(controllerName))<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>throw new ArgumentException(MvcResources.Common_NullOrEmpty, "controllerName");<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>Type controllerType = this.GetControllerType(requestContext, controllerName);<br />
<span style="white-space: pre;"> </span>return this.GetControllerInstance(requestContext, controllerType);<br />
}</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
Next, a ControllerContext object is constructed from the RequestContext and the controller by using the method GetContollerInstance.</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
Finally, the Execute() method is called on the controller class. The ControllerContext is passed to the Execute() method when the Execute() method is called.</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
<br /></div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
<span style="box-sizing: border-box; font-weight: 700;">Step 4: The Controller Executes</span></div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
The Execute() method starts by creating the TempData object. TempData is a dictionary derived from TempDataDictionary class and stored in short lives session and it is a string key and object value. </div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
The Execute() method gets the Action from the RouteData based on the URL.The Controller Class then call the ContollerActionInvoker that builds a list of parameters from the request.</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
These parameters, extracted from the request parameters, will act as method parameters.The parameters will be passed to whatever controller method gets executed.</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
Finally It will call the InvokeAction method to execute the Action.</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
protected override void ExecuteCore()<br />
{<br />
<span style="white-space: pre;"> </span>this.PossiblyLoadTempData();<br />
<span style="white-space: pre;"> </span>try<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>string requiredString = this.RouteData.GetRequiredString("action");<br />
<span style="white-space: pre;"> </span>if (!this.ActionInvoker.InvokeAction(base.ControllerContext, requiredString))<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>this.HandleUnknownAction(requiredString);<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>finally<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>this.PossiblySaveTempData();<br />
<span style="white-space: pre;"> </span>}<br />
}<br />
public virtual bool InvokeAction(ControllerContext controllerContext, string actionName)<br />
{<br />
<span style="white-space: pre;"> </span>if (controllerContext == null)<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>throw new ArgumentNullException("controllerContext");<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>if (string.IsNullOrEmpty(actionName))<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>throw new ArgumentException(MvcResources.Common_NullOrEmpty, "actionName");<br />
<span style="white-space: pre;"> </span>}<br />
<br />
ControllerDescriptor controllerDescriptor = this.GetControllerDescriptor(controllerContext);<br />
ActionDescriptor actionDescriptor = this.FindAction(controllerContext, controllerDescriptor, actionName);<br />
if (actionDescriptor == null)<br />
{<br />
<span style="white-space: pre;"> </span>return false;<br />
}<br />
FilterInfo filters = this.GetFilters(controllerContext, actionDescriptor);<br />
try<br />
{<br />
<span style="white-space: pre;"> </span>AuthorizationContext context = this.InvokeAuthorizationFilters(controllerContext, filters.AuthorizationFilters, actionDescriptor);<br />
<span style="white-space: pre;"> </span>if (context.Result != null)<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>this.InvokeActionResult(controllerContext, context.Result);<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>else<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>if (controllerContext.Controller.ValidateRequest)<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>ValidateRequest(controllerContext);<br />
<span style="white-space: pre;"> </span>}<br />
<span style="white-space: pre;"> </span>IDictionary<string, object> parameterValues = this.GetParameterValues(controllerContext,actionDescriptor);<br />
<span style="white-space: pre;"> </span>ActionExecutedContext context2 = this.InvokeActionMethodWithFilters(controllerContext,filters.ActionFilters, actionDescriptor, parameterValues);<br />
<span style="white-space: pre;"> </span>this.InvokeActionResultWithFilters(controllerContext, filters.ResultFilters, context2.Result);<br />
<span style="white-space: pre;"> </span>}<br />
}<br />
catch (ThreadAbortException)<br />
{<br />
<span style="white-space: pre;"> </span>throw;<br />
}<br />
catch (Exception exception)<br />
{<br />
<span style="white-space: pre;"> </span>ExceptionContext context3 = this.InvokeExceptionFilters(controllerContext,filters.ExceptionFilters, exception);<br />
<span style="white-space: pre;"> </span>if (!context3.ExceptionHandled)<br />
<span style="white-space: pre;"> </span>{<br />
<span style="white-space: pre;"> </span>throw;<br />
<span style="white-space: pre;"> </span>}<br />
this.InvokeActionResult(controllerContext, context3.Result);<br />
}<br />
return true;<br />
}<br />
<br />
<div style="box-sizing: border-box; margin-bottom: 10px;">
<span style="box-sizing: border-box; font-weight: 700;">Step 5: The Render View Method is called</span></div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
The Controller typically either executes either the RedirectToAction Method or the RenderView Method. When you call a controller’s RenderView() method,the call is delegated to the current ViewEngine’s RenderView() method.</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
The WebFormViewEngine.RenderView() method uses a class named the ViewLocator class to find the view. Next, it uses a BuildManager to create an instance of a ViewPage class from its path.</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
Next, if the page has a master page, the location of the master page is set If the page has ViewData, the ViewData is set. Finally, the RenderView() method is called on the ViewPage.</div>
<pre style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgb(204, 204, 204); box-sizing: border-box; color: #333333; font-family: menlo, monaco, consolas, "courier new", monospace; font-size: 13px; line-height: 1.42857; margin-bottom: 10px; overflow-wrap: break-word; overflow: auto; padding: 9.5px; word-break: break-all;"></pre>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: transparent; border-collapse: collapse; border-spacing: 0px; box-sizing: border-box;"><tbody style="box-sizing: border-box;">
<tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0px;" valign="top"><div style="box-sizing: border-box; margin-bottom: 10px;">
<br /></div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
The ViewPage class derives from the base System.Web.UI.Page class. This is the same class that is used for pages in classic ASP.NET.</div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
The final action that RenderView() method performs is to call ProcessRequest() on the page class. Calling ProcessRequest() generates content from the view in the same way that<span style="background-color: transparent; color: #333333; font-size: 14px;">content is generated from a normal ASP.NET page.</span></div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
</div>
</td></tr>
</tbody></table>
</div>
</td></tr>
</tbody></table>
</td></tr>
</tbody></table>
</div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com7tag:blogger.com,1999:blog-8996795397710165839.post-48912035513642087162018-09-16T22:11:00.001-07:002018-09-16T22:27:57.518-07:00What are the advantages of ASP.NET MVC <div dir="ltr" style="text-align: left;" trbidi="on">
<b>Q.What are the advantages of ASP.NET MVC </b><br />
<b>Answer: </b><br />
<b>Multi view support</b><br />
Due to the separation of the model from the view, the user interface can display multiple views of the same data at the same time.<br />
<br />
<b>Separation of Concerns</b><br />
Separation of Concerns is one of the core advantages of ASP.NET MVC .Since code-behind concept has been removed from MVC<br />
The MVC framework provides a clean separate logic for the UI, Business Logic, Model or Data.This feature enable code re-usability.<br />
<br />
<b>More Control</b><br />
The ASP.NET MVC framework provides more control over HTML, JavaScript and CSS than the traditional Web Forms.<br />
<br />
<b>Testability Is Easy</b><br />
ASP.NET MVC framework provides better testability of the Application and good support for the test driven development too.<br />
<br />
<b>Lightweight</b><br />
ASP.NET MVC framework doesn’t use View State and thus reduces the bandwidth of the page.</div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-88792543548461300842018-08-23T23:15:00.003-07:002018-09-16T22:06:42.131-07:00JQuery Interview Questions and answers<div dir="ltr" style="text-align: left;" trbidi="on">
<b>1.What are the basic selectors in jQuery?</b><br />
<b><br /></b>
Following are the basic selectors in jQuery:<br />
<br />
<b>A)Element ID</b><br />
A ID available the DOM Using ID we can axxess the control in JQuery.<br />
<br />
using JQuery<br />
$("#EmpId")<br />
<br />
<b>B)CSS Name</b><br />
A class name will be available in the DOM usinf class name we can access this in JQuery.<br />
<br />
using JQuery<br />
$(".Menu")<br />
<br />
<b>C)Tag Name</b><br />
A tag name available in the DOM. For example $('a') selects anchor tags in the DOM.<br />
<br />
using JQuery<br />
$("a")</div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-8996795397710165839.post-50348442278023408532018-08-20T06:15:00.002-07:002018-09-16T22:07:33.310-07:00Free source code Version Control Systems <div dir="ltr" style="text-align: left;" trbidi="on">
<b>SVN</b><br />
Subversion is the most used version control used in worldwide. Most open-source projects use Subversion as a repository because other larger projects, such as SourceForge, Apache, Python, Ruby and many others, use it as well.Because of its popularity, there are many versions and IDEs available.<br />
<br />
<b>Git</b><br />
Git is the new fast-rising version control systems. Initially developed by Linux kernel creator Linus Torvalds, Git has recently taken the Web development community by storm. Now Git has quickly emerged as a preferred version control system in nowadays.<br />
Thanks to its distributed form of control without any master copy of the software, many open<br />
source projects and system administrators prefer Git. Let us have a look at the key pros and cons of this system.</div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-52877958649520448912018-08-19T00:13:00.000-07:002018-08-19T00:13:16.121-07:00Required Field Validator not Working For DropDownList asp.net<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif; font-size: 15px;">You need to set the value as </span><code style="background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #242729; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;">0</code><span style="background-color: white; color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif; font-size: 15px;"> in the </span><code style="background-color: #eff0f1; border: 0px; box-sizing: inherit; color: #242729; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; font-size: 13px; font-stretch: inherit; font-variant-east-asian: inherit; font-variant-numeric: inherit; line-height: inherit; margin: 0px; padding: 1px 5px; vertical-align: baseline; white-space: pre-wrap;">InitialValue</code><span style="background-color: white; color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif; font-size: 15px;"> of validator or change the value of first item of DropDown.</span><br />
<span style="background-color: white; color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif; font-size: 15px;"><br /></span>
<span style="background-color: white; color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif; font-size: 15px;"><br /></span>
<span style="color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 15px;"><asp:requiredfieldvalidator controltovalidate="ddlCustomer" runat="server" span=""></asp:requiredfieldvalidator></span></span><br />
<span style="color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 15px;">cssclass="required" display="dynamic" errormessage="*" setfocusonerror="true"</span></span><br />
<span style="color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="background-color: white; font-size: 15px;"></span></span><br />
<span style="color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 15px;">InitialValue="0"></span></span></div>
<span style="color: #242729; font-family: "arial" , "helvetica neue" , "helvetica" , sans-serif;"><span style="font-size: 15px;"><br /></span></span></div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-40940100205199314142018-08-15T21:36:00.001-07:002018-09-16T22:08:22.664-07:00State Management techniques In ASP.NET MVC<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"><b>State Management In ASP.NET MVC</b>.
We all know that HTTP is a state less protocol. Hence, If we want to pass data from one page to another page or even on multiple
visits of the same page, then we need to use the State management techniques to store user specific data.
Here, i am going discuss various techniques to pass the data from a Controller to View or Controller to Controller.
ASP.NET MVC doesn’t support ViewState or Server controllers.
To achieve state management in ASP.NET MVC, there are four basic ways which are given as following.
1.ViewData
2.ViewBag
3.TempData
4.Sessions
1.ViewData
ViewData is used to pass the data from Controller to View.It is derived from ViewDataDictionary class, it requires typecasting for complex datatypes
and it requires a null check to void exceptions.
Controller
public ActionResult Index()
{
ViewData["CurrTime"] = DateTime.Now;
return View();
}
HTML Index.cshtml Code
@ViewData["CurrentTime"];
2.ViewBag
ViewBag is also used to pass data from Controller to View. It is a dynamic property which uses the Dynamic feature of C# 4.0. And, the
Dynamic keyword internally uses reflection.
Controller Code
public ActionResult Index()
{
ViewBag.CurrTime = DateTime.Now;
return View();
}
html Index.cshtml code
@ViewBag.CurrentTime
3.TempData
TempData is used to pass the data from Action to Action or Controller to Controller, and then to View. It keeps the information for single HTTP Request.
It is derived from TemDataDictionary and along with this, it requires typecasting for complex data types and it requires a null check to void exceptions.
Controller Code
public ActionResult Index()
{
TempData["CurrTime"] = DateTime.Now;
return View();
}
Html Index.cshtml code
@TempData["CurrTime"];
4.Session
If you want to store the data and maintain it for multiple requests, then use session variables.
Controller Code
public ActionResult Index()
{
Session["CurrTime"] = DateTime.Now;
return View();
}
Html Index.cshtml Code
@Session["CurrentTime"];
</code></pre>
</div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-4164230334595518142018-08-15T09:18:00.001-07:002018-08-15T09:21:07.658-07:00How to Upload Files in ASP.NET MVC<div dir="ltr" style="text-align: left;" trbidi="on">
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"><b> Upload Files In ASP.NET MVC</b></code></pre>
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;">Here i am going to explain File Upload example in ASP.Net MVC
Below code is quite limited and simple functionality for single file upload, and it will work in any browser.
Before uploading the file, we will check whether Directory exists if not exist then the Directory will be created.
View
View consists of an HTML form containing the submite button, which open a select file dialog, and Submit, which sends the chosen file to
the server in a POST request.
<html>
<head>
<meta name="viewport" content="width=device-width"/>
<title>Index</title>
</head>
<body>
<div>
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<span>Select File:</span>
<input type="file" name="postedFile"/>
<hr/>
<input type="submit" value="Upload"/>
<br/>
<span style="color:green">@ViewBag.Message</span>
}
</div>
</body>
</html>
Controller
public class HomeController : Controller
{
// GET: Home
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(HttpPostedFileBase postedFile)
{
if (postedFile != null)
{
string path = Server.MapPath("~/Upload/");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
postedFile.SaveAs(path + Path.GetFileName(postedFile.FileName));
ViewBag.Message = "File uploaded successfully.";
}
return View();
}
}
</code></pre>
</div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-72651880337459336312018-08-15T06:53:00.000-07:002018-08-15T09:21:19.481-07:00JQ GRID in ASP.NET MVC 4 using Razor<div dir="ltr" style="text-align: left;" trbidi="on">
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <b>JQ GRID Using MVC with Razor View Engine in ASP.NET MVC 4</b>
Friends,Here i am going to explain how to use jqgrid in asp.net mvc4 with rzor view engine.JQGrid is one of the most flexible and stable
gird you can find in the current tech market. It’s free to use. Here i am going to write basic step to do where data will come from
database to show in JQgrid.
Following are step by step sequence to create the JQGRID.
1.Create a new ASP.NET MVC 4 Web Project
2.Select Empty template with Razor
4.Right Click on the Controller and Add new Controller
5.Copy and paste the below code in the controller as fllowing
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using JQGridExample.Models;
namespace JQGridExample.Controllers
{
public class EMPLOYEEController : Controller
{
public ActionResult EmpDetails()
{
return View();
}
public JsonResult getEmpDetails()
{
List<Employee> items = new List<Employee>();
items = getData();
var a = Json(items, JsonRequestBehavior.AllowGet);
a.MaxJsonLength = int.MaxValue;
return a;
}
public List<Employee> getEmpData()
{
string connString = ConfigurationManager.ConnectionStrings["Mycon"].ConnectionString;
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand();
cmd.CommandTimeout = 6000;
cmd.CommandText = "select * from employee";
cmd.Connection = conn;
conn.Open();
DataTable dataTable = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dataTable);
conn.Close();
da.Dispose();
List<Employee> items = new List<Employee>();
foreach (DataRow row in dataTable.Rows)
{
items.Add(new MEmployee
{
Id = row["ID"].ToString(),
Name = row["Name"].ToString(),
Gender = row["Gender"].ToString(),
Contact = row["Contact"].ToString(),
Address = row["Address"].ToString(),
State = row["State"].ToString(),
Country = row["Country"].ToString()
});
}
return items;
}
}
}
6.Add new class to the Model folder and paste the below code in the Model.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace JQGridExample.Models
{
public class Employee
{
public string Id { get; set; }
public string NAME { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public string Contact { get; set; }
public string Address { get; set; }
public string State { get; set; }
public string Country { get; set; }
}
}
8. Right Click on the Controller and Add the View ,name should be EmpDetails
9. Add below code to the created EmpDetails view
@{
ViewBag.Title = "JQGrid Esample";
}
<html>
<head>
<title>My First JQGrid Example</title>
<script src="~/Scripts/jquery-1.11.0.min.js"></script>
<link href="yourlocalpath/ajax/libs/jqueryui/1.8.13/themes/base/jquery-ui.css" rel="stylesheet" />
<script src="yourlocalpath/jqgrid/4.6.0/jquery.jqGrid.min.js"></script>
<script src="yourlocalpath/jqgrid/4.6.0/i18n/grid.locale-en.js"></script>
<script src="yourlocalpath/jqgrid/4.6.0/jquery.jqGrid.min.js"></script>
<link href="yourlocalpath/jqgrid/4.6.0/css/ui.jqgrid.css" rel="stylesheet" />
<style type="text/css">
.ui-jqgrid .ui-widget-header {
background-color: #336699;
background-image: none;
color: white;
}
.ui-jqgrid .ui-jqgrid-labels th.ui-th-column {
background-color: #FFCC66;
background-image: none;
color: #336699;
height: 30px;
font-weight: bold;
}
</style>
<script type="text/javascript">
$(function () {
$("#myEmpGrid").jqGrid({
url: '@Url.Action("getEmpDetails")',
datatype: 'json',
mytype: 'get',
colNames: ['Id','Name', 'Gender', 'Contact', 'Address', 'State','Country'],
colModel: [
{ name:'Id', width:'35px' },
{ name:'Name', width:'160px' },
{ name:'GENDER' },
{ name:'Gender' },
{ name:'Address' },
{ name:'State'},
{ name:'Country'}
],
pager: $('#myPager'),
rowNum: 5,
sortname: 'ID',
gridview: true,
sortorder: 'desc',
loadonce: true,
rowList: [5, 10, 20, 50],
width: 600,
height: 110,
viewrecords: true,
caption: 'Emp details in JQ Grid'
});
});
</script>
</head>
<body>
<div>
<table id="myEmpGrid"></table>
<div id="myPager"></div>
</div>
</body>
</html>
Run your application and test
</code></pre>
</div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-46572610222022367542017-08-22T03:54:00.000-07:002018-08-22T04:08:29.932-07:00JQuery date picker in asp.net<div dir="ltr" style="text-align: left;" trbidi="on">
Here am going to explained with an example , how to implement jQuery UI DatePicker Calendar with ASP.Net TextBox.<br />
.aspx code
<br />
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <script src="../Scripts/jquery-1.12.4.min.js" type="text/javascript"></script>
<script src="../Scripts/jquery-ui-1.12.1.min.js" type="text/javascript"></script>
<link href="../Content/themes/base/jquery-ui.css" rel="stylesheet" rel="Stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$("[id*=txtDate]").datepicker({
showOn: 'button',
buttonImageOnly: true,
buttonImage: 'images/calendar.png'
});
});
</script>
<div class="form-inline" role="form">
<div class="form-group">
<asp:TextBox ID="txtDate" runat="server" ReadOnly = "true"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
onclick="btnSubmit_Click" />
</div>
</div
</code></pre>
<br /></div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-37162971861549667252017-08-10T06:33:00.000-07:002018-11-19T01:20:02.807-08:00ASP.NET MVC interview questions & answers<div dir="ltr" style="text-align: left;" trbidi="on">
<b>What is MVC (Model View Controller)?</b><br />
<b>Answer: </b><br />
MVC is an architectural pattern which separates the UI and Data Model and business logic. It’s divided into three parts, Model, View, and Controller.<br />
<br />
1. The Model represents the data and pass it to view (Database objects).<br />
2. The View displays the data and responsible for look and feel of the page (from database).<br />
3. The Controller handles the user input(request) and load appropriate model and view.<br />
<br />
<b>What are the advantages of MVC?</b><br />
<b>Answer: </b><br />
Multi view support<br />
Due to the separation of the model from the view, the user interface can display multiple views of the same data at the same time.<br />
<br />
Separation of Concerns<br />
Separation of Concerns is one of the core advantages of ASP.NET MVC .Since code-behind concept has been removed from MVC<br />
The MVC framework provides a clean separate logic for the UI, Business Logic, Model or Data.This feature enable code re-usability.<br />
<a href="https://www.dotnetgorilla.in/2018/09/what-are-advantages-of-aspnet-mvc.html"><span style="font-size: large;">Read More...</span></a><br />
<br />
<b>Q.Explain “page lifecycle” of an ASP.NET MVC?</b><br />
<div style="background-color: white; box-sizing: border-box; margin-bottom: 10px;">
<span style="box-sizing: border-box; font-size: 14px;"><span style="color: #333333; font-family: "segoe ui" , "tahoma" , "arial" , "helvetica neue" , "helvetica" , sans-serif;">When a page is requested first following process are performed by ASP.Net MVC </span></span></div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Segoe UI", Tahoma, Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
<span style="box-sizing: border-box; font-weight: 700;">Step 1: Routing</span></div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Segoe UI", Tahoma, Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
In traditional ASP.NET webform application each asp.net page implements the IHTTPHandler interface.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Segoe UI", Tahoma, Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
This interface has a ProcessRequest() method that gets called when you request the page. The ProcessRequest() method is responsible for processing the request and generating the response. So in asp.net application it is simple, you request for a page in the url like <a href="http://mysite1/default.aspx" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration-line: none;">http://mylocalsite1\default.aspx</a> and then it search for that page on the local disk and execute the processrequest method and generate the html response.</div>
<div align="left" style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Segoe UI", Tahoma, Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
However in MVC application ,request response process is different from webform. In MVC there are no physical page exist for a particular request. All the requests are routed to a special class called Controller. The controller is responsible for generating the response and sending the content back to the browser.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Segoe UI", Tahoma, Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
When you build a MVC application you can define a bunch of controllers. Each controller can handle multiple requests. For example, all the following will route to same Controller.</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Segoe UI", Tahoma, Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
<a href="http://mysite1/Controller1/1" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration-line: none;">http://mylocalsite1/Controller1/1</a></div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Segoe UI", Tahoma, Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
<a href="http://mysite1/Controller1/2" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration-line: none;">http://</a><a href="http://mysite1/Controller1/1" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration-line: none;">mylocalsite1</a>/Controller1/2</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "Segoe UI", Tahoma, Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 14px; margin-bottom: 10px;">
<a href="http://mysite1/Controller1/3" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration-line: none;">http://</a><a href="http://mysite1/Controller1/1" style="background-color: transparent; box-sizing: border-box; color: #337ab7; text-decoration-line: none;">mylocalsite1</a>/Controller1/3</div>
<div style="background-color: white; box-sizing: border-box; color: #333333; font-family: "segoe ui", tahoma, arial, "helvetica neue", helvetica, sans-serif; margin-bottom: 10px;">
<a href="https://www.dotnetgorilla.in/2018/09/page-lifecycle-of-aspnet-mvc-aspnet.html"><b><span style="font-size: large;">Read More...</span></b></a></div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: white; border-collapse: collapse; border-spacing: 0px; box-sizing: border-box; color: #333333; font-family: "Segoe UI", Tahoma, Arial, "Helvetica Neue", Helvetica, sans-serif; font-size: 14px;"><tbody style="box-sizing: border-box;">
<tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0px;" valign="top"><table border="0" cellpadding="0" cellspacing="0" style="background-color: transparent; border-collapse: collapse; border-spacing: 0px; box-sizing: border-box;"><tbody style="box-sizing: border-box;">
<tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0px;" valign="top"><div style="box-sizing: border-box; margin-bottom: 10px;">
</div>
<table border="0" cellpadding="0" cellspacing="0" style="background-color: transparent; border-collapse: collapse; border-spacing: 0px; box-sizing: border-box;"><tbody style="box-sizing: border-box;">
<tr style="box-sizing: border-box;"><td style="box-sizing: border-box; padding: 0px;" valign="top"><div style="box-sizing: border-box; margin-bottom: 10px;">
<br /></div>
<div style="box-sizing: border-box; margin-bottom: 10px;">
<br />
<strong style="box-sizing: border-box; color: #212121; font-family: "open sans", sans-serif;"><span style="box-sizing: border-box;">Question 4: What are different return types of a controller action method?</span></strong><strong style="background-color: transparent; box-sizing: border-box; color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">Answer: </strong><span style="background-color: transparent; color: #212121; font-family: "open sans" , sans-serif; font-size: 14px;">There are total nine return types we can use to return results from controller to view. </span><span style="background-color: transparent; color: #212121; font-family: "open sans" , sans-serif; font-size: 14px;">The base type of all these result types is ActionResult.</span><br />
<ol style="box-sizing: border-box; color: #212121; font-family: "open sans", sans-serif; font-size: 14px;">
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">ViewResult (View)</strong>: View Result is used to return a webpage from an action method.</li>
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">PartialviewResult (Partialview)</strong>: PartialViewResult is used to send a part of a view which will be rendered in another view.</li>
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">RedirectResult (Redirect)</strong>: <span style="box-sizing: border-box;">RedirectResult</span> is used to redirect to any other controller and action method depending on the URL.</li>
<li style="box-sizing: border-box;"><strong style="box-sizing: border-box;">RedirectToRouteResult (RedirectToAction, RedirectToRoute):</strong> This return type is used when we want to redirect to any other action method.</li>
</ol>
<div>
<span style="color: #212121; font-family: "open sans" , sans-serif;"><span style="font-size: large;"><b><a href="https://www.dotnetgorilla.in/2018/09/different-return-types-of-aspnet-mvc.html">Read More...</a></b></span></span><br />
<span style="color: #212121; font-family: "open sans" , sans-serif;"><span style="font-size: large;"><br /></span></span>
<span style="color: #212121; font-family: "open sans" , sans-serif;"><span style="font-size: medium;"><b>Question 5 : What are action filters in aspnet mvc?</b></span></span><br />
<span style="color: #212121; font-family: "open sans" , sans-serif;"><span style="font-size: medium;">Answer : </span></span><span style="background-color: transparent; color: #212121; font-family: "open sans", sans-serif; font-size: 13px;">ASP.NET MVC provides a very clean way of injecting the pre-processing and post-processing logic for actions and controllers. We can put</span><span style="background-color: transparent; color: #212121; font-family: "open sans", sans-serif; font-size: 13px;"> the pre-processing and post-processing logic is by decorating the actions with attributes which will invoke an attribute class implementing </span><span style="background-color: transparent; color: #212121; font-family: "open sans", sans-serif; font-size: 13px;"> the filter's logic.</span><br />
<a href="https://www.dotnetgorilla.in/2018/11/action-filters-in-aspnet-mvc.html"><b><span style="color: blue; font-size: large;">Read More...</span></b></a></div>
</div>
</td></tr>
</tbody></table>
</td></tr>
</tbody></table>
</td></tr>
</tbody></table>
</div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-24934275709412843262015-07-02T06:07:00.001-07:002018-08-21T22:13:35.166-07:00how to work with Entity Framework project<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Steps to create entity frmawork project<br />
1.Create a class library project for Context name YourProjectNameContext.<br />
2.Right click the project and add new edmx.<br />
3.Before creating edmx ensure that your Database is ready with proper relationship.<br />
4.Open edmx file -> right click -> Add code generation Item -> select ADO.Net Self-tracking Entity Generator.<br />
5.Add new Class library project for Entity named yourProjectNameEntities<br />
6.Drag the .tt from Context project and drop it to Entity project.<br />
7.Delete .tt files from Context project.<br />
7.Reference - install entity framework,add refernce system.runtime.services.<br />
8.Create your website/webapi project and add above created projects to here.</div>
<br />
<br />
Regards<br />
Santosh Singh<br />
<a href="https://kclsocietyservices.blogspot.com/2018/07/rain-water-harvesting-panvel-navi-mumbai.html">Rain Water Harvesting System Click here for info</a><br />
<br />
<a href="http://technologiescrunch.blogspot.com/2018/08/best-android-smart-phones-under-rs-15000.html">Best Android Phones Below Rs- 5000</a><br />
<br /></div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com9tag:blogger.com,1999:blog-8996795397710165839.post-62942728675425805612015-06-04T00:59:00.000-07:002018-08-21T22:11:25.692-07:00Sticky menu on scroll in html5 and jquery<div dir="ltr" style="text-align: left;" trbidi="on">
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> Here, we will create a sticky menu bar in very simple way which is built only with CSS and jQuery.
1.Write this jquery code in top of your html page
<script type="text/javascript">
$(document).ready(function () {
var stickyTopPos = $('.navbar').offset().top;
var stickyNavbar = function () {
var scrollTop = $(window).scrollTop();
if (scrollTop > stickyTopPos) {
$('.navbar').addClass('sticky');
} else {
$('.navbar').removeClass('sticky');
}
};
stickyNavbar();
$(window).scroll(function () {
stickyNavbar();
});
});
</script>
2.Add this stylesheet
<style>
.sticky
{
position: fixed;
width: 100%;
left: 0;
top: 0;
z-index: 100;
border-top: 0;
background-color: #808080;
}
</style>
3.This is our menu
<div class="navbar">
<ul class="tabs" data-tab>
<li class="tab-title active"><a href="#panel1">Menu-1</a></li>
<li class="tab-title"><a href="#panel2">Menu-2</a></li>
<li class="tab-title"><a href="#panel3">Menu-3</a></li>
<li class="tab-title"><a href="#panel4">Menu-4</a></li>
<li class="tab-title"><a href="#panel5">Menu-5</a></li>
<li class="tab-title"><a href="#panel6">Menu-6</a></li>
<li class="tab-title"><a href="#panel7">Menu-7</a></li>
</ul>
<div class="clear">
</div>
</div>
</code></pre>
<pre style="background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); font-family: arial; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="word-wrap: normal;"><a href="http://technologiescrunch.blogspot.com/2018/08/best-mobiles-under-rs-8000-in-india.html"><b><span style="color: blue; font-size: large;">Best Mobiles Below Rs 8000</span></b></a><span style="font-size: 12px;">
</span></code></pre>
</div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-8996795397710165839.post-91422033214050269122014-08-11T00:02:00.000-07:002018-08-01T02:37:30.165-07:00Read a single node from xml (C# String) in C#/.net<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> I want to pass the ID as a input parameter of the given xml that will search the XML document for that value within the <id> node.
Once ID found ,I want to find the next node and return it's name as a string.
Given xml as folloing:
<Set>
<Setting>
<Name>username1</Name>
<ID>1234</ID>
<Add>Mumbai</Add>
<Path>name/userdata/img</Path>
</Setting>
<Setting>
<Name>username2</Name>
<ID>4534</ID>
<Add>Navi Mumbai</Add>
<Path>name/userdata/img</Path>
</Setting>
</Settings>
Solution:
This Linq to xml query will return IEnumerbale<string> of value elements, which matched your id. You need to sure ID should be
unquine in given xml.
string value = doc.Descendants("Setting")
.Where(v => (string)v.Element("ID") == Id)
.Select(v => (string)v.Element("Name"))
.SingleOrDefault();
</code></pre>
</div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com337tag:blogger.com,1999:blog-8996795397710165839.post-50192194449124761542014-01-21T10:00:00.000-08:002018-08-11T09:02:41.743-07:00Caching in ASP.NET ?<div dir="ltr" style="text-align: left;" trbidi="on">
Caching is technique of persisting the data in memory for immediate access to requesting program calls.Caching is feature to improve application performance of web application.There are three types of caching available in asp.net.<br />
<br />
<b>Output Caching : </b><br />
This is at the page level and one of the easiest way of caching a page.<br />
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <%@ OutputCache Duration="60" VaryByParam="none" %>
</code></pre>
<br />
VaryByParam attribute makes sure that there is a single cached page available for this duration specified.<br />
<br />
<b>Fragment Caching :</b> <br />
Some times we might want to cache just portions of a page.<br />
Eg.Suppose we want to cache header of our page which will have the some content for all users.There might be some Text/Images in the header which might change everyday.In this case we will cache this header for a duration of a day.
The solution will be put header in a user control and then cached the user control as output caching.As below<br />
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> <% OutputCache Duration="10" VaryByParam="None"%>
</code></pre>
<br />
This technique is known as fragment Cachng.<br />
<br />
<b>Data Caching :</b><br />
ASP.NET also support caching of data as objects.We can store objects in memory and use then across various pages in our application.This feature is impemented using the cache class.The cache class has life time equivalent to that of the applicaton objects can be stored as name pairs in the cache.<br />
<pre style="background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> Cache["name"] ="santosh";
if(Cache["name"] != null)
{
lbl.text = Cache["name"].ToString();
}
</code></pre>
<br />
<a href="https://kclsocietyservices.blogspot.com/2018/07/rain-water-harvesting-panvel-navi-mumbai.html">Rain Water Harvesting</a></div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-8996795397710165839.post-5664719226007635702014-01-21T05:47:00.001-08:002018-08-01T02:41:32.283-07:00Types of session management in ASP.NET<div dir="ltr" style="text-align: left;" trbidi="on">
Session object is used to store state specific information per user basis.Session object can be configured 3 ways based on availability and scalability of web application.<br />
<br />
<b>In Process Mode:</b><br />
This is default mode and useful for small application which is hosted on single server.<br />
<b>Advantages:</b><br />
-Fastest mode.<br />
-Simple configuration.<br />
<b>Disadvantages:</b><br />
-Session data will be lost if worker process or application domain recycle.<br />
-Not ideal for web garden and web form.<br />
<br />
<b>Out-of-process session mode</b>(State server mode):<br />
This mode is useful for highly available and scalable applications.Session state is stored in a process called aspnet_state.exe that runs as a windows service which listens on TCP port 42424 by default.<br />
<b>Advantages:</b><br />
-Supports web farm and web garden configuration.<br />
-Session data is persisted across application domain recycles.This is achieved by using separate worker process for maintaining state.<br />
<b>Disadvantages:</b><br />
-Out-of-process mode provides slower access compared to in process.<br />
-Requires serializing data.<br />
<br />
<b>
Sql-Backed Session State:</b>
Session can also be stored in sql server database.Storing session in DB offers resilience that can serve session to a large web farm that persists across IIS restarts.SQL based session state is configured with aspnet_regsql.exe.<br />
<b>Advantages:</b><br />
-Supports web farm and web garden configuration.<br />
-Session State is persisted across application domain recycles and even IIS restarts.<br />
<b>Disadvantages:</b><br />
-Required serialized of objects.<br />
<br /></div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-89365798823103143622014-01-21T01:48:00.000-08:002014-01-21T01:51:32.949-08:00Which control would you see if you need to make sure the values in two different controls matched ?<div dir="ltr" style="text-align: left;" trbidi="on">
Compare Validator
<br /></div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-34054671281829214602014-01-20T19:42:00.000-08:002014-01-20T19:42:59.751-08:00Difference between Server.Transfer and Response.RedirectServer.Transfer transfer page processing from one page to another page directory to the next page without
making a round trip back to the client browser.This provides a faster response with a little less overhead on the server.Server.Transfer does not update the url.<br/><br/>
Response.Redirect is used to redirect the user browser to another page or website.This performs a tripback to the client where client browser redirected to the new page.The user browser url is updated to reflect the new address.<br/><div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-4728511087431360792014-01-20T19:29:00.001-08:002014-01-20T19:29:42.573-08:00What are the differences between user control and server control<b>User Control</b><br/>
1.Re-usability in web pages<br/>
2.Can not add to toolbox<br/>
3.Drag and drop from solution explorer to page<br/>
3.You can register user control to .aspx page by Register tag<br/>
4.This is good for static layout<br/>
5.Easier to create<br/>
6.Can not compiled into DLL<br/>
7.Can not use in other web application.<br/><br/>
<b>Custom Control</b><br/>
1.It can be compile into DLL.<br/>
2.Re-usability of control<br/>
3.We can Add to toolbox<br/>
4.We can drag and drop from toolbox<br/>
5.Good for dynamic layout.<br/>
6.We can register user control to .aspx by registering<br/>
7.A single copy of control can be used in any other web application.<br/><br/><div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-9800540769572629692014-01-20T19:15:00.000-08:002014-04-12T01:15:42.880-07:00How to fetch ricord between 3 and 15 only, if a dataset contains 100 rows<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> SqlDataAdapter da = new SqlDataAdapter("usp_GetData",con);
DataSet ds1 = new DataSet();
da.Fill(ds1);
int rowcount = ds1.Table[0].Rows.Count;
if(rowcount >=15)
{
for(int i=3;i<=15;i++)
{
lbl.Text = Convert.ToSting(ds1.Table[0].Row[i].ToString());
}
}
</code></pre>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-33423028354891315412014-01-19T21:06:00.000-08:002014-01-20T21:06:53.698-08:00What is Viewstate ? What are the advantages and disadvantages of it view state?<div dir="ltr" style="text-align: left;" trbidi="on">
View state is used to retain the state of the server side objects between post backs.<br /><br />
<b>Advantages :</b><br />
-Simple for page level data<br />
-Encrypted<br />
-Can be set at the control level.<br /><br />
<b>Disadvantages :</b><br />
-Overhead in encoding view state values<br />
-Makes a page heavy<br />
<br /></div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-8996795397710165839.post-50479697509446157102014-01-19T19:44:00.000-08:002014-01-20T21:00:07.276-08:00What is diffgram<div dir="ltr" style="text-align: left;" trbidi="on">
The Diffgram is one of the two XML format that you can use to render Dataset object content to XML.For example if you are reading database data to on XML file to be sent to a web service.
<br /></div>
<div class="blogger-post-footer">Santosh Singh
http://kclsocietyservices.blogspot.com</div>Unknownnoreply@blogger.com0