Custom Control Data Binding

mohsine tahri asked on December 11, 2015 23:09

Hi, we have one particular issue when we clear our cache.

Our company specialize on jobboard, we have many differents websites, each one is specialized in a different domain, we have IT jobs, accounting jobs...etc

The issue is, when we clear our cache and try to browse to our website, we end up with jobs from a different field, for example for my tests, i took two websites, the first one is HRjob, a website specialized in human resource jobs, my second website is jobwings, a website specialized in financial job offers.

What i was trying to reproduce, is a concurency issue, which means, i tried to browse my two websites, both at the same time, after clearing my cache, i noticed that both websites list the same job offers, actualy, the second website always list the same jobs as the first website i called.

I started debugging the issue, i noticed that both calls, with each a different site code name, call upon my methods, get the job offers correctly, then bind them to the datasource, but when rendrering the website, i end up with job offers in the financial field in my HR website, which shouldnt be the case, i reproduced it many times, but it still happen.

Im beggining to think that maybe there is an issue with the databinding, when using custom controls, so i came here asking for support.

I use Kentico 7.0.34.

Thank you.

Recent Answers


Roman Hutnyk answered on December 11, 2015 23:25

DO you use Kentico caching? Is there site dependency setup for caching?

0 votesVote for this answer Mark as a Correct answer

mohsine tahri answered on December 14, 2015 16:05

Not really.

Like i said, when debugging, i saw the calls, and each one call the right methods and get the right job offers, depending on the site code name, then bind them to the datasource, i checked the datasource on the code behind, just before rendering the web site, and it contained the right job offers for the current web site call, but the moment the web site is rendered, it display the job offer of the first web site, which doesnt make any sense to me, cause i saw the databiding was correct.

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on December 14, 2015 21:43

If running through the code, you clearly see the two different datasets, then I would imagine that the issue would have to do with caching. Have you checked your site settings and webpart settings? Try to disable the cache and possibly viewstate(depends on if your webpart uses this or not) and let us know what results you have. I would start at the particular webparts that are giving you issues, and see if disabling the caching and partial caching fixes the issue.

0 votesVote for this answer Mark as a Correct answer

mohsine tahri answered on December 14, 2015 22:01

Actually, after running some more tests, the behavior i had before was caused by my localhost environement, i didnt set it right.

Now that i have the right config, i end up with the same result, but the behavior is different.

In our code, we created a custom control web part, which use a custom data source, i put a break point on each class, and when running the same test, both web sites at the same time, i noticed that my custom web part was called by both web sites, but the data source was only called by the first web site, on the cache side, now that i have the right settings, i see that only the first web site job offers are registred, thus when the websites are rendred, they both contain the same job offers.

Normaly, the custom web part and the custom data source, should both be called by my web sites, but only the custom web part is called by both, my custom data source is only called by the first website.

We implemented both classes according to Kentico 7 deveoper`s guide.

0 votesVote for this answer Mark as a Correct answer

Timothy Fenton answered on December 15, 2015 03:32

hello, this is really entirely dependent on how you have coded this custom webpart and custom data source. Can you give some code snippet of how you are doing this? Have you implemented some caching in your custom datasource? Are you using the same cache keys for the datasources? What about for the webparts do they share any caching? It might be helpful to provide the code files or some snippets for us to review

Thanks

0 votesVote for this answer Mark as a Correct answer

mohsine tahri answered on December 15, 2015 16:42

We noticed that when we get the datasource, it doesnt always call "GetDataSourceFromDB" in our custom datasource control, see the code below:

public override object DataSource { get { return mDataSource ?? (mDataSource = GetDataSource()); } set { mDataSource = (DataSet)value; } }

This is the implementation for the property "DataSource", the method "GetDataSource()" will call another method "GetDataSourceFromDB()", which contain our BL, basically it will get data from DB.

Now the problem is, while trying to simulate a concurrency issue and debugging it, we noticed that in the property "DataSource", we only call the method "GetDataSource()" once, it isnt called the other time.

Actually, it happens when we clear our runtime cache, when we try to access to two websites at the same time, we noticed we get the same Data on both websites, which shouldnt be the case, each website has its own data.

When that happens, we debbuged it and found that in the datasource concerned, in the property "DataSource", we call the method "GetDataSource()" only once.

So when calling two websites at the same time, the first website will access the "DataSource" property, try reading it, it verify if its null, which will be the case, cause we just cleared the runtime cache, so it will call the method "GetDataSource()" and get the data related to the current site, then come the second website call, but in this case, we noticed that it verify if "mDataSource" is null, and it isnt, it contains the data from the first call, so the second website doesnt call the method "GetDataSource()", and we end up with the same data as the first website.

My question is, is this behavior normal, should we directly call "GetDataSourceFromDB()" int the "DataSource" reader property instead of calling the method "GetDataSource()" which do some caching.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.