ciao ragazzi, sto uscendo pazzo. vi posto un paio di esempi che ho scaricato da un sito serio.
realizzano entrambi la stessa cosa; utilizzano entrambi la programmazione codebehind solo che un (il VB) funziona, l'altro no (in c#)
##################VB####################
<%@ page language="VB" debug="true" src="vbCb.vb"
inherits="myVbCodeBehind.vbCb" %>
<html><head></head><body>
<form runat="server">
Select a flower, and click the submit button please:
<asp:ListBox id="lstFlowers" runat="server" rows="3">
</asp:ListBox>
<asp:Button id="btnSubmit" runat="server"
text="Submit" onclick="showSelection" />
<asp:Label id=lblMessage runat="server" />
</body></form></html>
Option Strict Off
Imports System
Imports System.Web.UI.WebControls
Namespace myVbCodeBehind
Public Class vbCb : Inherits System.Web.UI.Page
Public lstFlowers As System.Web.UI.WebControls.ListBox
Public lblMessage As System.Web.UI.WebControls.Label
Public btnSubmit As System.Web.UI.WebControls.Button
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
lblMessage.Text = "No Selection Yet"
lstFlowers.Items.Add(new ListItem("Tulip"))
lstFlowers.Items.Add(new ListItem("Rose"))
lstFlowers.Items.Add(new ListItem("Redbud"))
lstFlowers.SelectedIndex=0
End If
End Sub
Protected Sub showSelection(ByVal obj As Object, ByVal e As EventArgs)
lblMessage.Text = "You have selected " + lstFlowers.SelectedItem.Text
End Sub
End Class
End Namespace
#########################################
@@@@@@@@@@@@@@@@CS@@@@@@@@@@@@@@@@@
<%@ page language="cs" Debug="true" codebehind="CSharpCodeBehind.cs"
inherits="myCsCodeBehind.cSharpCb" %>
<html><head></head><body>
<form runat="server">
Select a flower, and click the submit button please:
<asp:ListBox id="lstFlowers" runat="server" rows="3">
</asp:ListBox>
<asp:Button id="btnSubmit" runat="server"
text="Submit" onclick="showSelection" />
<asp:Label id=lblMessage runat="server" />
namespace myCsCodeBehind
{ using System;
using System.Web.UI.WebControls;
public class cSharpCb : System.Web.UI.Page
{ public System.Web.UI.WebControls.ListBox lstFlowers;
public System.Web.UI.WebControls.Label lblMessage;
public System.Web.UI.WebControls.Button btnSubmit;
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{ lblMessage.Text = "No Selection Yet";
lstFlowers.Items.Add(new ListItem("Tulip"));
lstFlowers.Items.Add(new ListItem("Redbud"));
lstFlowers.Items.Add(new ListItem("Poppy"));
}
}
protected void showSelection(object obj, EventArgs e)
{ lblMessage.Text = "You have selected " + lstFlowers.SelectedItem.Text;
}
}
}
</body></form></html>

Rispondi quotando