Thursday, May 26, 2011

Find from which page the master file is invoked

Scenario

We may sometimes need to know from which page, the master file is invoked. Based on the file, we'll do some operation not for the other pages. For example if the user name in session is empty, it has to redirect to the login page otherwise the requested page should be opened. But at the same time, if the user request a login page, it should not redirect to the same page again.

Solution


In the above said scenario, we have to identify from where the master page is being called. We have the below code to identify from which page its called,

this.Parent.TemplateControl.AppRelativeVirtualPath.ToString() 


If you put this code in master page file, you will get to know the page from where it's invoked. Its taking the parents relativevirtualpath.


Happy Coding...



Wednesday, May 25, 2011

Change the upload file size in ASP.NET application

Problem:


This is a scenario i faced when i worked in web application. Our application supports to upload the documents. When the user tries to upload the file more than 4MB, the browser shows error message and . Initially I did the work around, check the size of the file and notify the user to upload less than 4 MB document.

Solution

I found that thats not the correct solution. We may stop breaking the application and google the web and found a very simple solution to solve the problem.

We need to add the below line in web.config file under System.web tag
<httpRuntime maxRequestLength="5120"/>

The httpRuntime tag has the property called maxRequestLength, which is to be specified in KB. The above shows the 5 MB file can be uploaded.

If you are not specifying the httpRuntime in web.config..the default size is 4MB.

Conclusion:


With that above work around, user can able to upload more than 4 MB and we can fix the size.

Happy Coding... :)

Tuesday, January 25, 2011

JavaScript Error - Object Not Found

Problem:
When you refer JavaScript/css/images files, it will be referred properly and the code works fine in local machine. But you may get JavaScript error "Object Not Found" when deployed in web servers.


Solution:
Kindly use the  symbol to avoid this Object Not Found error to specify the root directory.


Sample Code:
The below code which generates "Object Not Found" JavaScript error,
<link href="/Content/Styles/MasterPage.css" rel="stylesheet" type="text/css" />
Or 
<link href="../Content/Styles/MasterPage.css" rel="stylesheet" type="text/css" />


Working Code:
Use  symbol before the / to refer the root level as shown below,
<link href="~/Content/Styles/MasterPage.css" rel="stylesheet" type="text/css" />
In addition, if you are working in MVC, use Url.Content to get absolute URL as shown below, 
<script src="<%= Url.Content("~/Scripts/jquery-1.4.4.js") %>" type="text/javascript">script>


Conclusion
Make a practice of referring any external files by using the ~ symbol in the root level to avoid Object Not Fund error.


Happy Coding


Thursday, December 23, 2010

"Object Expected" error in MVC JQuery autocomplete

Problem :-


I have been working in MVC and its very interesting to work with it. I just started working on JQuery. I have encountered this problem when implementing autocomplete to Text box in MVC with JQuery. The JavaScript error "Object Expected" will be coming when you reload the page. That means during first time load, there will be no problem. But if you click on paging and try to do autocomplete in text box. You could face this error in autocomplete statement.

Solution :-


Normally  we used to include the Jquery files by dragging to the page. When we drag the files, the following text will be added,

<script src="../../Scripts/jquery-1.4.1.js" type="text/javascript">

The blue color text shows like the Scripts directory is placed inside one folder from the root. But its not like that. Its placed directly under the root.

So change that script include to the below one.

<script src="/Scripts/jquery-1.4.1.js" type="text/javascript">


This will solve your problem.


Conclusion :-


This may be the small issue but kill your time like anything. You won think the problem due to this script include tag. 


Happy Coding.. :)


Friday, November 26, 2010

Assign default text in Html.TextBoxFor


To assign textbox value in MVC view, use the following syntax.

<%= Html.TextBoxFor(x => x.EmployeeName, new { @Value = "Enter Employee Name"}) %>

Here the @Value case is must.

Wednesday, October 6, 2010

MVC Cascading dropdown, Jquery Grid and Resolving circular references

1. Look at the below link by Stephen Walther to work on Cascading dropdowns

http://stephenwalther.com/blog/archive/2008/09/07/asp-net-mvc-tip-41-creating-cascading-dropdown-lists-with-ajax.aspx

You may face this circular reference error due to referring one class in another class for foreign key relation,

can use the below link to solve that problem

http://blogs.telerik.com/atanaskorchev/posts/10-01-25/resolving_circular_references_when_binding_the_mvc_grid.aspx

2. jquery provides the Grid with paging and sorting. check with the below link

http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx

Thanks to respective authors..

Thursday, September 23, 2010

Deploy Webparts in Sharepoint Server 2007

Steps to deploy Webpart in Sharepoint Server 2007 


1. Copy themes files to C:\Inetpub\wwwroot\wss\VirtualDirectories\80\_themes if you have it in webpart.


2. Open web.config file under the port 80 C:\Inetpub\wwwroot\wss\VirtualDirectories\80\ 


3. Add assembly information to safecontrol tag 


    Ex. <<SafeControl Assembly="HelloworldWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f4da00116c38ec5" Namespace="HelloworldWebPart" TypeName="HelloworldWebPart" Safe="True" />>


4. Move the webpart assembly file(.dll under bin folder) to GAC.


5. Restart IIS using iisreset command


6. Go to webpart Gallery and click New on the top.


7. You could find your webpart, select the webpart and click populate button to load the webpart to Gallery.


8. Eventually create a webpart page and add this webpart to the web page.


9. Hope you could see the result displayed in the webpage in the form of webpart.




Happy Coding...