Voting system like SO - C #, Asp.net, Webforms

There are many questions like this, but none of them relate to webforms and C # that I found.

I have Linq-to-SQL, Vote table, where I want to record voting records (Voteup / down / time / ipaddress / user, etc.)

Is this a way to do this or is there a better way:

Make updown imgs, hide the identifier of the object that voted somewhere there (where?), When you click img jquery, it sends you to the ashx page, which returns true if it is able to create a vote record, and then set img for color / shades gray based on the response of the ashx page?

Bonus points for examples or links to examples = D

PS. I see a lot of comments about this in a short amount of time. I will post my last code tonight.

+4
source share
2 answers

I think you have a general idea. You can do this using traditional AJAX WebForms or use jQuery to call $ .ajax () to do all this: register a vote, return the result and change the image.

Here is the framework for the jQuery approach:

JavaScript:

function registerVote(voteType){ $.ajax(function (){ //get the name of the parent DIV //(using the jQuery selector), which is the ID of the thing you're voting on //Use Success and Error callbacks to register a success or error. //On success, change the selected vote image to the highlighted version }) } 

HTML:

 <div id="ThingToVoteOn1"> <img src="voteUp" onclick="registerVote('UP')"> <img src="voteDown" onclick="registerVote('DOWN')"> </div> 
+1
source

I would do it the way you say, but in the database I use the relational database functions more.

For example, the presence of a user table with a one-to-many relationship to the question table. If you want them (users) to be able to ask questions, you need a table with each user question, this is another one-to-many relationship. Then you also need a vote table that has a one-to-many relationship with a question table and a user table, so you can keep track of which user voted on the question and what question he had.

The main thing is that if you use the relational database system correctly, it will simplify your life to keep track of things in the background and therefore you will give the user the best experience.

That is one thing. Then make your voting images clickable, so use the onclick event, with jQuery, which should be pretty simple.

Use AJAX to perform postback when you click on an image, so you donโ€™t need to post all over the page every time a user votes. It will also enhance the user interface. Lots of tutorials on AJAX with ASP.NET.

Hope this helps!

+1
source

Source: https://habr.com/ru/post/1303021/


All Articles