AspNetSource.com's Official BlogAspNetSource's Official Blog

Articles for ASP.NET, AJAX, SQL, C#, VB.NET, etc.


Top Articles

<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

Categories

AJAX  ASP.NET  C#  CSS  Design  fun  General  SEO  SQL  VB.NET 

Links

Link to Us

(just copy-paste the text below in your page)

Author(s)

 
Posted by Tihomir Ivanov on 20 December 2008 12:35
Posted in: ASP.NET 

We've decided to change the products and articles voting system. Now you can vote only with yes or no:

Yes No Control

Few words how it works: when user view page it has two pictures for voting (for yes and no), both are grey and he can vote by clicking on some of them. If he vote yes (clicking on yes picture) it becomes green and everytime he open the page, he'll see the green image, and the both picture won't be enabled for voting.

in this article we'll describe all issues when creating such control:

0. created neccessary db tables.

We have a table when save all votes:

...
CREATE TABLE [DB_CHEME].[Ratings](
...
[HostAddress] [nvarchar](20) NOT NULL,
[Vote] [bit] NOT NULL,

...
)

it's important to have HostAddress (the IP) of the user (next time he visits the page, you'll be able to check if he has already pass a vote),

Vote is bit (true or false), it's his vote.

1. create user control (ascx) and add this code there:

<asp:ImageButton ID="_yesBtn" runat="server" onclick="_yesBtn_Click" CausesValidation="false" />&nbsp;<asp:Label ID="_yesLbl" runat="server"></asp:Label>&nbsp;&nbsp;&nbsp;<asp:ImageButton
ID="_noBtn" runat="server" onclick="_noBtn_Click" CausesValidation="false" />&nbsp;<asp:Label ID="_noLbl" runat="server"></asp:Label>

2. code behind class:

private const string _none_yes = "grey_y.gif"; // picture for yes (before user vote)
private const string _none_no = "grey_n.gif"; // picture for no (before user vote)
private const string _no = "no.gif"; // picture for no, after user vote no
private const string _yes = "yes.gif"; // picture for yes, after user vote yes

private string _images_path = "../images/yn/"; // path for the necessary pictures

#region Events

protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{

//TODO Add code here to check if the current user has already voted.

if (didntVote)
{
  FillNone(); // you can see this function below
}
else if (votedYes)
{
FillYes(); // // you can see this function below
}
else
{
FillNo(); // // you can see this function below
}
}

protected void _yesBtn_Click(object sender, ImageClickEventArgs e)
{
//TODO: register new vote for yes

FillYes();
}

protected void _noBtn_Click(object sender, ImageClickEventArgs e)
{

//TODO: register new vote for no

FillNo();

}

#endregion

#region Private Methods

private void FillNone()
{
_yesBtn.ImageUrl = _images_path + _none_yes;
_noBtn.ImageUrl = _images_path + _none_no;

_yesBtn.Attributes.Add("onmouseover", "src='" + _images_path + _yes + "' ");
_yesBtn.Attributes.Add("onmouseout", "src='" + _images_path + _none_yes + "' ");

_yesBtn.AlternateText = "it's cool!";
_noBtn.AlternateText = "it's NO cool!";

_noBtn.Attributes.Add("onmouseover", "src='" + _images_path + _no + "' ");
_noBtn.Attributes.Add("onmouseout", "src='" + _images_path + _none_no + "' ");
}

private void FillYes()
{
_yesBtn.ImageUrl = _images_path + _yes;
_yesBtn.Enabled = false;

_noBtn.ImageUrl = _images_path + _none_no;
_noBtn.Enabled = false;
}

}

#endregion

 

That's All, I hope this article'll be useful to someone else too :)

 

Posted by Tihomir Ivanov on 20 December 2008 12:33
Posted in: fun 

We've added a page with our team: Visit it

Maybe it'll be funny to see us :)

Posted by Tihomir Ivanov on 15 December 2008 18:01
Posted in: ASP.NET 

In this article I'll try to explain some common xml isue. Let's look at the example:

we have some xml file (list.xml):

<?xml version="1.0" encoding="utf-8" ?>

<Root>
<Item>
<Title>AspNetSource.com</Title>
<ID>1</ID>
</Item>
<Item>
<Title>dev-the-web.com</Title>
<ID>2</ID>
</Item>
</Root>

and we want to select Title of this Item which ID is 2. Follows the code:

XmlDocument xmlDocument = new XmlDocument();
XmlNode xmlDocument.Load(Server.MapPath("~") + "App_Data\\list.xml");


xmlNode = xmlDocument.SelectSingleNode("Root/Item[ID='2']");

string OUR_TEXT = xmlNode["Title"].InnerText;

That's all. Happy Coding :)

Posted by Tihomir Ivanov on 03 December 2008 07:45
Posted in: ASP.NET General 

Let's begin with an example of simple asp.net code:

<asp:ImageButton ID="_imgBtn" runat="server" ImageUrl="~/images/Img.jpg" Height="50px" 
Width="50px" BorderWidth="0px" BorderStyle="None" />


That's a valid asp.net code and it works fine, BUT when you try to validate it 
through W3C (http://validator.w3.org/) you will see error like this:

Error Line X column X : there is no attribute "border".

This is a problem caused by W3C running validation whilst reading the HTML rendered for a simple browser like Netscape !

Do you want your pages to be valid for old-fashioned browsers which nobody uses anymore?

If the answer of last question is 'No' here's a solution:

Add a BrowserFile.browser file with the content below inside an App_Browsers folder in the app's root. The section for validation tells it

to use the same code as IE 7 or Firefox will. Add this and your page should validate:

<!--
You can find existing browser definitions at
<windir>\Microsoft.NET\Framework\<ver>\CONFIG\Browsers
-->
<browsers>
<browser id="NewBrowser" parentID="Mozilla">
<identification>
<userAgent match="Unique User Agent Regular Expression" />
</identification>

<capture>
<userAgent match="NewBrowser (?'version'\d+\.\d+)" />
</capture>

<capabilities>
<capability name="browser" value="My New Browser" />
<capability name="version" value="${version}" />
</capabilities>
</browser>

<browser refID="Mozilla">
<capabilities>
<capability name="xml" value="true" />
</capabilities>
</browser>
<browser id="w3cValidator" parentID="default">
<identification>
<userAgent match="^W3C_Validator" />
</identification>

<capture>
<userAgent match="^W3C_Validator/(?'version'(?'major'\d+)(?'minor'\.\d+)\w*).*" />
</capture>

<capabilities>
<capability name="browser" value="w3cValidator" />
<capability name="majorversion" value="${major}" />
<capability name="minorversion" value="${minor}" />
<capability name="version" value="${version}" />
<capability name="w3cdomversion" value="1.0" />
<capability name="xml" value="true" />
<capability name="tagWriter" value="System.Web.UI.HtmlTextWriter" />
</capabilities>
</browser>
</browsers>

 

That's All :) Happy Coding :)

12345678910...


 
AspNetSource.com


 
Our Sponsors:  Asp.net file upload component