You are on page 1of 13

1. Te ndertohet nje faqe LogIn ne ASP.

NET, ku username dhe password ruhen ne skedarin e


konfigurimit te programit , web.config

Zgjidhje
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="Leksion4.WebForm2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
UserName
</td>
<td>
<asp:TextBox ID="UserNameTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
PassWord
</td>
<td>
<asp:TextBox ID="PassWordTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="LogInButton" runat="server" Text="LogIn"
OnClick="LogInButton_Click"/></td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="ErrorLabel" runat="server"></asp:Label>

</td>
</tr>

</table>

1
</div>
</form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Leksion4
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void LogInButton_Click(object sender, EventArgs e)


{
if(this.UserNameTextBox.Text!=Leksion4.Properties.Settings.Default.UserName
&&
this.PassWordTextBox.Text!=
Leksion4.Properties.Settings.Default.PassWord)
{
this.ErrorLabel.Text = Leksion4.Properties.Settings.Default.ErrorText;
this.ErrorLabel.ForeColor = System.Drawing.Color.Red;
}
else
{
this.ErrorLabel.Text =string.Format(
Leksion4.Properties.Settings.Default.SuccesText,
this.UserNameTextBox.Text, this.PassWordTextBox.Text) ;
this.ErrorLabel.ForeColor = System.Drawing.Color.SeaGreen;
}
}
}
}

2. Ndertoni nje program ne ASP.Net si me poshte. Ne momentin qe perdoruesi te klikoj mbi


butonin Dergo te dhenat, te afishohet teksti ne fund te faqes. Rezultati do te afishohet nese te
gjithe kontrollet kane vlere. DropDownList per kurset duhet te permbaj vlerat ASP-XML, DotNET,
JavaPro ,Unix,C,C++.

2
Zgjidhje

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SurveyForm.aspx.cs"


Inherits="Leksion4.SurveyForm" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Feeback Form:
<table>
<tr>
<td>
Emri Mbiemri i Studentit:
</td>
<td>
<asp:TextBox ID="NameTextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Gjinia:
</td>
<td>
<asp:RadioButtonList ID="GenderRadioButtonList"
runat="server"></asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
Kurset:
</td>
<td>
<asp:DropDownList ID="CoursesDropDownList"
runat="server"></asp:DropDownList>

3
</td>
</tr>
<tr>
<td>
Teknika e Mesimdhenies:
</td>
<td>
<asp:RadioButtonList ID="TechnicRadioButtonList"
runat="server"></asp:RadioButtonList>
</td>
</tr>
<tr>
<td>
Sugjerime:
</td>
<td>
<asp:TextBox ID="SuggestionTextBox" runat="server"
TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="SendButton" runat="server" Text="Dergo te dhenat"
OnClick="SendButton_Click"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label runat="server" ID="ResultLabel"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Leksion4
{
public partial class SurveyForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
FillGender();
FillCourses();
FillEvaluations();
}
}

4
private void FillGender()
{
GenderRadioButtonList.Items.Clear();
ListItem itemM = new ListItem();
itemM.Text = "Mashkull";
itemM.Value = "M";
ListItem itemF = new ListItem();
itemF.Text = "Femer";
itemF.Value = "F";
GenderRadioButtonList.Items.Add(itemM);
GenderRadioButtonList.Items.Add(itemF);

}
private void FillCourses()
{
CoursesDropDownList.Items.Clear();
CoursesDropDownList.Items.Add( new ListItem("ASP-XML", "ASP-XML"));
CoursesDropDownList.Items.Add(new ListItem("DotNET", "DotNET"));
CoursesDropDownList.Items.Add(new ListItem("JavaPro", "JavaPro"));
CoursesDropDownList.Items.Add(new ListItem("Unix", "Unix"));
CoursesDropDownList.Items.Add(new ListItem("C", "C"));
CoursesDropDownList.Items.Add(new ListItem("C++", "C++"));
}
private void FillEvaluations()
{
TechnicRadioButtonList.Items.Clear();
TechnicRadioButtonList.Items.Add(new ListItem("Shkelqyeshem", "4"));
TechnicRadioButtonList.Items.Add(new ListItem("Mesatare", "3"));
TechnicRadioButtonList.Items.Add(new ListItem("Mire", "2"));
TechnicRadioButtonList.Items.Add(new ListItem("Dobet", "1"));

protected void SendButton_Click(object sender, EventArgs e)


{
this.ResultLabel.Text = string.Empty;
this.ResultLabel.ForeColor = System.Drawing.Color.DeepSkyBlue;
if (GenderRadioButtonList.SelectedValue == "M")
{
this.ResultLabel.Text = "Zoti ";
}
else if (GenderRadioButtonList.SelectedValue == "F")
{
this.ResultLabel.Text = "Zonja/Zonjusha ";
}
else
{
this.ResultLabel.Text = "Kujdes gjinia nuk eshte perzgjedhur!";
this.ResultLabel.ForeColor = System.Drawing.Color.Red;
this.GenderRadioButtonList.BackColor = System.Drawing.Color.Red;
return;
}
this.GenderRadioButtonList.BackColor = System.Drawing.Color.Transparent;
if (NameTextBox.Text!=string.Empty)
{
this.ResultLabel.Text += NameTextBox.Text;

5
this.ResultLabel.Text += " faleminderit per vleresimin ";
}
else
{
this.ResultLabel.Text = "Kujdes Fusha Emri eshte bosh!";
this.ResultLabel.ForeColor = System.Drawing.Color.Red;
this.NameTextBox.BorderColor= System.Drawing.Color.Red;
return;
}
this.NameTextBox.BorderColor = System.Drawing.Color.Black;
if (TechnicRadioButtonList.SelectedValue != string.Empty)
{
this.ResultLabel.Text += TechnicRadioButtonList.SelectedItem.Text;
this.ResultLabel.Text += " qe keni dhene mbi kursin ";
}
else
{
this.ResultLabel.Text = "Kujdes duhet te perzgjidhni nje kurs!";
this.ResultLabel.ForeColor = System.Drawing.Color.Red;
this.TechnicRadioButtonList.BackColor = System.Drawing.Color.Red;
return;
}
this.TechnicRadioButtonList.BackColor = System.Drawing.Color.Transparent;
if (CoursesDropDownList.SelectedIndex>=0)
{
this.ResultLabel.Text += CoursesDropDownList.SelectedValue;
}
else
{
this.ResultLabel.Text = "Kujdes duhet te perzgjidhni nje kurs!";
this.ResultLabel.ForeColor = System.Drawing.Color.Red;
this.CoursesDropDownList.BackColor = System.Drawing.Color.Red;
return;
}
this.CoursesDropDownList.BackColor = System.Drawing.Color.Transparent;

}
}
}

3. Te ndertohet nje program ne ASP.Net qe permban


a. ListBox
b. Button
c. Image
d. 2 Label
e. TextBox

ListBox do te perdoret per Produktet e vlefshme te nje dyqani. TextBox dhe nje nga kontrollet Label do
te perdoret per vendosjen e tekstit “Vendos Sasine:” dhe vleren perkatese. Ne momentin qe
perdoruesi klikon mbi button do te shfaqet imazhi I produktit, si dhe ne kontrollin Label te mbetur
afishohet vlera totale mbi baze te produktit te zgjedhur.

6
Zgjidhje

Skedari : SampleStyleSheet.css
body {
}
.table-td{
padding:5px;
font-size:small;
color:brown;
width:50%
}
.labelS
{
color:orangered;
font-size:medium;
}
.buttonS
{
border-color:blue;
background-color:coral;

7
font-size:small;
color:antiquewhite;
//position:center;
}

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ShopForm.aspx.cs"


Inherits="Leksion4.ShopForm" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="Stylesheet" href="SampleStyleSheet.css" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
Dyqani ABC
<hr />
<table>
<tr >
<td class="table-td">Lista e Produkteve</td>
<td class="table-td">
<asp:DropDownList ID="ProductDropDownList"
runat="server"></asp:DropDownList>
</td>
</tr>
<tr>
<td class="table-td">Sasia: </td>
<td class="table-td">
<asp:TextBox ID="AmountTextBox" runat="server"></asp:TextBox> </td>
</tr>
<tr>
<td class="table-td" colspan="2">

<asp:Image runat="server" ID="ProductImg"/>


<hr />

</td>
</tr>
<tr>
<td class="table-td" colspan="2">
<asp:Label runat="server" ID="ResultLabel" CssClass="labelS"
> </asp:Label>
<hr /></td>
</tr>

<tr>
<td class="table-td" colspan="2">

<asp:Button ID="ResultButton" runat="server" Text="shfaq"


CssClass="buttonS" OnClick="ResultButton_Click"/>

</td>
</tr>
</table>

8
</div>
</form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Leksion4
{
public partial class ShopForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
FillProductList();
}
}
private void FillProductList()
{

ProductDropDownList.Items.Add(new ListItem("Produkti1", "50"));


ProductDropDownList.Items.Add(new ListItem("Produkti2" , "45,5"));
ProductDropDownList.Items.Add(new ListItem("Produkti3", "70"));
}

protected void ResultButton_Click(object sender, EventArgs e)


{
int amount;
bool result = int.TryParse(this.AmountTextBox.Text, out amount);
if(!result || amount<0)
{
ResultLabel.Text = "Kujdes sasia nuk eshte vendosur ne rregull!";
this.AmountTextBox.BorderColor = System.Drawing.Color.Red;
return;

}
else
{
this.AmountTextBox.BorderColor = System.Drawing.Color.Black;
double price = Convert.ToDouble(ProductDropDownList.SelectedValue);
double total = price * amount;
ProductImg.ImageUrl = "images\\image" + ProductDropDownList.SelectedIndex
+ ".jpg";
ResultLabel.Text = "Totali: "+total;

}
}
}

9
4. Te ndertohet forma me poshte ne Asp.Net

Te plotesohen kerkesat me poshte

a. Te mos lejohet pjesetimi me 0


b. Te merren parasysh rastet e vendosjes si input te teksteve
c. Te llogariten rezultatet ne klik te butonit “Llogarit”
d. Te pastrohen te dhenat ne klik te butonit “Pastro Rezultatin”

Zgjidhje
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ActionNrForm.aspx.cs"
Inherits="Leksion4.ActionNrForm" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Kryej veprimet
<table>
<tr>
<td >
<asp:RadioButtonList ID="ActionRadioButtonList"
runat="server"></asp:RadioButtonList>
</td>
<td></td>
</tr>
<tr>
<td>
<asp:TextBox ID="Nr1TextBox" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="Nr2TextBox" runat="server"></asp:TextBox>
</td>
</tr>
<tr>

10
<td>
<asp:Button ID="CalculateButton" runat="server" Text="Llogarit"
OnClick="CalculateButton_Click"/></td>
<td>
<asp:Label ID="ResultLabel" runat="server" Text=""></asp:Label></td>
</tr>
<tr>
<td> <asp:Button ID="ClearButton" runat="server" Text="Pastro Rezultatin"
OnClick="ClearButton_Click" /></td>

<td></td>
</tr>
</table>
</div>
</form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Leksion4
{
public partial class ActionNrForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
FillActionList();
}
}
private void FillActionList()
{
ActionRadioButtonList.Items.Clear();
ActionRadioButtonList.Items.Add( new ListItem("Mbledhje", "1"));
ActionRadioButtonList.Items.Add(new ListItem("Zbritje", "2"));
ActionRadioButtonList.Items.Add(new ListItem("Shumezim", "3"));
ActionRadioButtonList.Items.Add(new ListItem("Pjesetim", "4"));
}

protected void CalculateButton_Click(object sender, EventArgs e)


{
double result=0,nr1, nr2;
bool result1 = double.TryParse(Nr1TextBox.Text, out nr1);
bool result2 = double.TryParse(Nr2TextBox.Text, out nr2);
// check if convert is OK for 2 inputs
if (result1 && result2)
{
int selectedItem;
if (ActionRadioButtonList.SelectedValue != string.Empty)
selectedItem =
Convert.ToInt32(ActionRadioButtonList.SelectedValue.ToString());

11
else
selectedItem = 0;
switch (selectedItem)
{
case 1:
result = nr1 + nr2;
break;
case 2:
result = nr1 - nr2;
break;
case 3:
result = nr1 * nr2;
break;
case 4:
if (nr2 != 0)
result = nr1 + nr2;
else
{
ResultLabel.Text = "Kujdes: Pjesetuesi eshte 0";
return;
}
break;
default:
ResultLabel.Text = "Nuk keni perzgjedhur asnje veprim!";

break;

}
ResultLabel.Text +=string.Format("Rezultati eshte:{0}",result);
}
else
{
ResultLabel.Text = "Nuk mund te kryhet konvertimi ne numra!";
}
}

protected void ClearButton_Click(object sender, EventArgs e)


{
Nr1TextBox.Text = string.Empty;
Nr2TextBox.Text = string.Empty;
ResultLabel.Text = string.Empty;
ActionRadioButtonList.SelectedIndex = -1;
}
}
}

5. Te ndertohet forma student.aspx si meposhte.


Te plotesohen kerkesat.
a. Te mos lejohen fushat bosh. Sa here te kemi nje fushe bosh, kontrolli perkates te kaloj
me border ngjyre te kuqe.
b. Te kontrollohen fushat (kontrollet me input numra) qe te mos lejojne vlera negative ose
tekste.
c. Fusha Email te kontrollohet per permbajtjen e karakterit @.
d. Ne rast te klikimit mbi butonin Regjistro, te afishohet mesazhi “Urime Emer Mbiemer,
regjistrimi u krye me sukses” nese validimet kalojne me sukses.

12
e. Fusha Password te paraqitet si ne figure.

13

You might also like