Hello, Welcome to my blog. If you like feel free to refer others

Tuesday, 27 November 2012

window.showModalDialog Page Load not being executed everytime

Problem : Loading a page as a modal dialog box as window.showModalDialog("myurl.aspx"). The first time the modal dialog is poped up the page load event gets called. When i close it and call the same again, the Control does not come to the Page_Load(). Instead the page pops up with the previous values in all its controls. What we want is the Page_Load() to be triggered every time the modal dialog pops up.

Solution: First of all showModalDialog is an proprietary IE only feature its not supported by all browsers

Solution 1 :   You need to add a unique query string value to the URL that you are using to avoid IE showing the cached version. So generate a random number and append it to the URL e.g myurl.aspx?rnd=12237827348273. This should bust the cache and make a fresh request

Solution 2 : Turn caching of on the page by using @OutputCache directive 

<%@ OutputCache Duration="1" Location="None" VaryByParam="none" %>

Solution 3 :  Call----- Response.Cache.SetCacheability(HttpCacheability.NoCache);

Hope that will help you. Happy Learning...... :)

Monday, 26 November 2012

Dropdown list binding with financial year

Problem: Sometimes we need to get a result of financial years(...2011-2012, 2012-2013, 2013-2014) starting from the date given by me to till 5 year in a dropdown list.

Solution: Lets say we received the given date from text box:-
DateTime GivenDate = Convert.ToDateTime(textBox1.Text);
int GivenYear = GivenDate.Year;
for(int i=0; i<5; i++)
comboBox1.Items.Add(GivenYear + i + "-" + (GivenYear + 1 + i));

Hope this will solve your problem.....