Help to design this requirement

Hello All,

 I have to design a counter.aspx page which will taken any number of counter names. Only one counter name can be supplied each counter.aspx request. As a response I need to show a single pixel image. Each counter name and their hits are tracked in DB periodically.

Additional I also need to have a provision of how many hits each name received today and yesterday and so on.


Who is Participating?
ssanghavi82Connect With a Mentor Author Commented:
I have to pass name with a null parameter , after that when we see the /Counter.aspx?name= url on the browser the user will give some name and then hit enter

I have 2 then collect this parameter ....

pls suggest an implementation.

 for eg ....

 protected void Page_Load(object sender, EventArgs e)
        if (!Page.IsPostBack)

        if (Request.QueryString["name"].ToString() != null)
                string strName = Request.QueryString["name"].ToString();
                //do corresponding work



    protected void QueryString()

        Response.Redirect("Counter.aspx?name="+ "");

Daniel WilsonConnect With a Mentor Commented:
Is this homework?

Even so ... I can give a few hints ...

Start w/ your DB design.  That's the core of this project.

Not sure on the next one ... but I think Server.Transfer may be a slick way of returning your little image when the page is requested.  You can dynamically generate an image ... but that's probably more work than you need to do.
ssanghavi82Author Commented:
Yes this is a home work. I have already created my DB. Its 1 table with id,datecreated, time, countername, counterhits.

I have also created a image.

On the counter.aspx file what shd i do .... can u give me some hints
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Daniel WilsonConnect With a Mentor Commented:
The key thing your counter.aspx file will do is execute a SQL statement.  Could be a stored procedure ... but the statement will look something like:

If exists (Select 1 from MyTable where convert(varchar(10), getdate(), 102 ) = convert(varchar(10), DateCreated, 102 ) and CounterName = @counterName)  Update MyTable set counterHits = counterHits+1 where convert(varchar(10), getdate(), 102 ) = convert(varchar(10), DateCreated, 102 ) and CounterName = @counterNameElseInsert Into MyTable (DateCreated, CounterName, counterHits) Values (getdate(), @CounterName, 1)

It will then show the image ... I'm suggesting a server.transfer for that.
ssanghavi82Author Commented:
yeah thats fine. But my main concern is Counter.aspx file ..... not database related.

Let me explain .....

Can u give me a sample code snippet for counter.aspx which will

pass counter names ..... dnt knw how 2 input counter names .... but only 1 counter name should be passed in the url ..... so i shd use cookie or querystring eg /counter.aspx?name=countername .......

but i m only required to used 1 aspx page so this page should pass as well as recieve the counter name
1. Counter.aspx should pass countername eg /counter.aspx?name=countername (any 1 counter name)
2. Now this counter name should be incremented in database ....
3. Then a single pixel image will be shown as a response ....
4. if /coutner.aspx?admin=password is passed then show summary on front end .....

so should i use a textbox to collect the counter name a button to pass the name of counter to the same page and then once the button is clicked show him a single pixel image .....

let me knw on my thoughts ....

Daniel WilsonConnect With a Mentor Commented:
1. querystring, not cookie
2. My SQL code above handles that
3. try Server.Transfer(MyImage.gif)
4. do an If statement based on your querystring.  See for ASP.Net querystring usage.
ssanghavi82Author Commented:
I had a question .....

Do u have a sample code where

/counter.aspx?name=countername ..... counter name

is the url and my code reads this querystring .... once it takes the counter name ..... it should store that in database ..... if the counter name is repeated then it will just update the counter hit ....  Expect there could be 1 or there could be 1,000,000.  Your app should be able to handle n number of counters.

ssanghavi82Author Commented:
no sorry let me reframe what i actually want

say i have 50 oages on a web app calling counter.aspx .... each with a different counter name ...
The idea is to track how many hits occur on each counter.  Imagine you were tracking hits to your web site.  Youd want to see how many page loads you had across your site
Daniel WilsonConnect With a Mentor Commented:
Sample code for the query string -- see the link at #4 in my last post.

SQL code to either update or insert to the DB -- see the code I put in bold in my second post.

Start writing your page ... write what you know ... start with comments telling what you're trying to do, fill in the code you know ... when you get stuck post it and ask your questions.

You're going to find this isn't as hard as you think.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.