 |
|
|
Why do I get this error message? I added a reference to the dll and here is my register tag:
<![CDATA[<%@ Register Namespace="DSHHitCounter" Assembly="DSHHitCounter" TagName="HitCounter" TagPrefix="cc1" %>]]>
However I get the error messages in the subject.
Thank you for your help.
JFercan
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Next both when you put the value 10 in property value of properties window or via code change that he only value in design mode and not in mode of execution in VisualStudio 2005 I look at the response and now I thank
Translated from Portuguese to English by Google
LADEF
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 David, I am using master pages in .Net 2.0 and notice that the counter always increments when the user moves to another page. I presume that I need to include code for the SessionID but, since I am new to ASP.Net and have never done anything in .Net 1.0 I'm a bit lost. This is compounded by my ignorance of C#. If you have time, could you give me a pointer or two on the best way to handle this? This is my first experience with a custom server control so would like to learn how to create and use them. I'm sure it is easier than I am making it since every reference I have found gives it very short shrift. Also, they never seem to work with System.Web.SessionState. Thanks.
Dick
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I got it to work by adding a property called NewSession. This is checked in the OnLoad sub instead of the page.postback. When a session is started, the Session_OnStart event is fired and I set a session variable Session("InitialLoadComplete") = False. In the MasterPage load I check Session("InitialLoadComplete"). If it is False, I set HitCounter1.NewSession = True and Session("InitialLoadComplete") to True. Otherwise, I set Hitcounter1.NewSession = False.
When navigating to other pages than the home page, it seems that the counter is zero if there is no count.txt file in the page's folder. I think I can put a count.txt file in each folder and get a count of hits for each page. I have not tested that yet.
Dick
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
yes, I know the same question has been asked here before, but the answers did not help me out. So, how can I get it working??
kallekula
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I have a gridview with one template column which contain hyperlink control.This will open another website.I want hit counter for this hyperlink. Plz help me...........
Chrisy
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
| I placed the counter in my .NET 2.0 application(It converted nicely). I have the control in a tag to I may position it specifically. When I first hit the site it works great. However on this same page I have buttons that show different views in the Multiview control. When I click them or do refresh, the control still shows, but only with the default value in it. I can't seem to get to leave the current value displayed. Any Ideas? I am sure it is me doing something silly.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Adding the .net componant get's it into the tool box in .net 2003 but when I do it in Visual Studio 2005 it does not show up in the tool box? Can anyone help me to get it to work in VS 2005.
007G
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
Hi David,
I would like to learn how to log image clicks on aspx page to sql database? Would you please give answer to me?
Thanks,
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
ı cant add the counter to my asp.net project.please tell me how can ı do ?but please tell me with asp.net source codes.thankss
turkeyyy
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
The source code is provided at the top of the article. Download it and you can build your own version of DSHHitCounter.dll.
When you have done that, you need to add the assembly to the references folder of your website project. From the solution explorer, right-click on the references folder, browse to the DSHHitCounter.dll file, and click OK.
Now you can add the Hit Counter to the Visual Studio Toolbox. To do this, right-click on the Toolbox in Visual Studio .NET and select Add/Remove Toolbox Items (the exact wording differs between Visual Studio .NET 2002 and 2003). Browse to the DSHHitCounter.dll file and click OK. This will add the control into the Toolbox.
Finally, to add the control to an ASP.NET web page, simply drag the control from the Toolbox onto the web form's design tab.
I hope that helps.
Regards, David Hobbs
|
| Sign In·View Thread·PermaLink | 2.00/5 (3 votes) |
|
|
|
 |
|
|
Hi David,
I have another problem here. When i run my page locally, the hit counter is working perfectly, but after i uploaded it to the server and launch the page, i found out that the counter is not incremented. Why would this be? Is there anything that i have to set to make it work?
It is urgent, please help!
Thanks in advance!
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
It sounds like a permissions thing. Maybe on the server ASP.Net does not have permissions to write the counter value to the text file? To test this theory try changing the WriteDelay paremeter of the control to 5 minutes or something. What will happen then is the file will not be updated during every hit and you'll see if the counter increments.
What will probably happen then is the counter will work for 5 minutes (or whatever value you set) and then it will reset to zero when it tries to write the file (and fails).
If that's what happens I think you'll have to increase the permissions of the ASP.Net worker process so that it can write to the file. The safest way would be just to grant it write access to a particular sub-folder of your application and then put the text file in that folder.
Cheers, David Hobbs
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Hi David,
U r right, it is permissions setting problem. I granted the sub-folder write access but it still doesn't work. So i try to grant the write access to the text file as well, then only it works now.
Thanks a lot! Again, u r cool!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
I am new to ASP.net. Can you tell me how to grant write permissions to the folder and file. The page counter works fine on my system, but not when uploaded to the ftp server.
Plz Help. Thanks.
Ravi
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I found the counter reset to zero at random times, myself. I suspected it was a result of file sharing conflicts between different instances of the counter object trying to read/write at the same time to the count.txt file. I made a simple fix in the code to prevent the counter value being reset to zero. Instead of implementing semaphore locking mechanisms, I simply caught the exception and prevented the update of the counter value displayed in the web control and prevented writing a zero value to the count.txt file. Here are the functions I changed:
protected override void OnLoad(EventArgs e) { if (Context!=null && !Page.IsPostBack) { int val; val = increment(); if (val != -1) { this.Value = val; } } base.OnLoad(e); }
private int incrementWithoutDelay() { int i=getCounterFromFile(); if (i != -1) { i++; setCounterInFile(i); return i; } return i; }
private int getCounterFromFile() { int retval=-1; FileStream fs = null; try { if (!File.Exists(FullPath)) return 0;
fs=new FileStream(FullPath,FileMode.Open); int len=(int)fs.Length; byte[] buffer =new byte[len]; fs.Read(buffer,0,len); fs.Close(); StringBuilder sb=new StringBuilder(); for (int t=0; t retval=Int32.Parse(sb.ToString()); } catch (Exception) { if (fs != null) fs.Close(); } return retval; }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I also changed this function to close the filestream during an exception:
private void setCounterInFile(int t) { FileStream fs = null; try { fs = new FileStream(FullPath,FileMode.Create); string v=t.ToString(); byte[] buffer =new byte[v.Length]; for (int x=0; x fs.Write(buffer,0,v.Length); fs.Close(); } catch (Exception) { if (fs != null) fs.Close( ); } }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
This seems go be good counter. I created a footer control (FooterControl.ascx) and placed that counter control inside it. The problem I am having is that when I do refresh of page it keep incrementing the counter. I want this to be increment at Session or Application level. Please let me know how I can achieve that.
Thanks
Syed Anis
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Hi,
If you look below in my post titled "Re: Reset to zero..." where I responded to Syerwinlee, that will probably contain the solution you're looking for.
Regards, David Hobbs
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
hi, The hit counter will be set to zero when link button and image button is clicked. Any solution for this?
I also noticed that when a user click on a hyperlink that bring him to the next page, the hit counter will also be increased by one. How can this problems be solved?
Thanx!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi,
This bit of replacement code might solve the first problem... I had not allowed for postbacks in the initial version, so any button clicks would make the counter appear to go to zero. Try replacing the Value property with the following code:
[Bindable(true),Category("Appearance"),DefaultValue("9999")] public int Value { get { return (int)ViewState["mCount"]; } set { ViewState["mCount"] = value; } }
This uses ViewState, so the counter should be kept across postbacks. Please let me know if that solves it.
To solve the second problem, I guess you could use a session variable. Something like this:
if (Page.Session["DSHalreadycounted"]==null) { //increment the counter here Page.Session["DSHalreadycounted"]="Y"; }
This would mean that each browser session would only record one hit when the user first uses the application. After that the counter should not increment.
I hope that helps. Let me know how you get on with that.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
So sorry for late reply, have been bz with something else... i added the control to my user control, and use drag and drop in using the hit counter control. I am not really sure where can i add this piece of code. Thanks!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi David,
I have tried out the solution u provided.
Now the hit counter will not increased by one in the same browser or reset to zero when i refresh my page, or click on a hyperlink, or click on a button that does postback or no postback.
I replaced the onLoad method with the following code:
protected override void OnLoad(EventArgs e) { if (Context != null && !Page.IsPostBack) { if (Page.Session["DSHalreadycounted"]==null) { //increment the counter here Value = increment(); Page.Session["DSHalreadycounted"]="Y"; } } Value = getCounterFromFile(); base.OnLoad(e);
}
I have also tried to replace the Value property with the code u provided, but it does not work out. Anyhow, the above code had solved my problems.
Thanks alot David! U r cool!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
It is a fantastic control because I too sometimes do not want to bother with a SQL database or the images.
Having external images for the digits is however nice when you want more than the boring fonts available in a default windows installation.
Although I have not tried it I think one point of concern is the write permissions. It would be good to have a separate folder for this purpose rather than the one the application is (security).
Additionally I am concerned about how the control behaves under stress. For example peak periods. What about conflicts during the update of the text file? perhaps some lock-management code would make it more robust.
But other than that I think it is just fantastic, really!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks for the feedback. If you wanted to put the counter file in another folder you can set the TextFileName parameter to use another folder as long as it is inside the application somewhere, so you could set the parameter to counter\count.txt and have a special folder that way.
Locking would be a great idea also, if I get some time to do more work on this control that will be first on my list.
I personally don't want to put in option of using images, but that's only because I designed the control to be really simple, and it goes against one of my design goals for this control. But if anybody out there wants to implement that for themselves then feel free!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |