Che succede se cambio da
acodice:Protected WithEvents txtCommessa As System.Web.UI.WebControls.TextBox
Public ?
Che succede se cambio da
acodice:Protected WithEvents txtCommessa As System.Web.UI.WebControls.TextBox
Public ?
Gran Duca del Fancazzismo, con Pieni Poteri per la Sezione Toscana del Clan, e Comandante Supremo delle Forze Aeree
Non Esistono Cose Impossibile, ma Solamente la Nostra Limitata Percezione di Ciò che è Possibile!
Ciao a tutti bellee rutti :maLOL:
Esplode il PC....
:quote:
Scherzo, semplicemente cambi la visibilità del controllo.
In termini generali, impostando a Public la visibilità di una proprietà/metodo/membro, riesci a "vederlo" anche dall'esterno della tua classe.
Es.:
Public Class MyClass
Dim P as MyClass
....
....
Dim Text as String=P.txtCommessa.Text
Ciao, javalon
Scusa, mi è scappato l'invio messaggio prima di finire...![]()
riscrivo l'esempio:
Ciao, javaloncodice:Public Class MyClass 'specifico un metodo, lo dichiaro Protected Protected Sub Pippo() .... end sub End Class 'in un modulo esterno alla classe Dim P as new MyClass P.Pippo() -> da' errore di compilazione perché il metodo non è "esposto all'esterno" 'Se invece Sub Pippo fosse Public: Dim P as new MyClass P.Pippo() -> non dà errore![]()
Ti spiego a cosa mi serve.
Ho 2 classi in 2 pagine diverse ( Intervento e Ricerca )
Devo riuscire a passare il valore di un TextBox della classe Ricerca ad una TextBox della classe Intervento!
Sia con le variabili di sessione che con request.querystring non funziona per tutta una serie di motivi troppo lunhi da spiegare.
Mi era venuta in mente questa possibilità.
Di cambiare da Protected With Events a Public lo stato delle 2 TextBox interessate così da poter scrivere
WebApplication1.Intervento.txtCommessa.Text = txtID.Text
Dici che va bene ?
Gran Duca del Fancazzismo, con Pieni Poteri per la Sezione Toscana del Clan, e Comandante Supremo delle Forze Aeree
Non Esistono Cose Impossibile, ma Solamente la Nostra Limitata Percezione di Ciò che è Possibile!
Ciao a tutti bellee rutti :maLOL:
:master:
Se non vuoi usare session e querystring, eccoti un esempio da applicare al tuo caso.
Con due pagine, Pagina1.aspx (classe Pag1) e Pagina2.aspx (classe Pag2):
Nella parte HTML di Pag1 specifica:
Quindi, nella Pag1 rendi Public il Controllo, o meglio, la proprietà del controllo che ti serve:codice:<%@ Page Language="VB" ClassName="Pag1" %>
Immagino che dovrai passare da una pagina all'altra alla pressione di un bottone, o comunque devi agire con un postback:codice:Public ReadOnly Property IDText() As String Get Return txtID.Text End Get End Property
Nell'HTML dell'altra pagina aggiungi questa direttiva:codice:Sub Button1_Click(sender As Object, e As EventArgs) Server.Transfer("Pagina2.aspx") End Sub
In Pag2 aggiungi questo codicecodice:<%@ Reference Page="Pagina1.aspx" %>
Ciao, javaloncodice:Dim Chiamante As Pag1 Sub Page_Load(sender As Object, e As EventArgs) If Not IsPostBack Then Chiamante = CType(Context.Handler, Pag1) 'hai referenziato l'oggetto, puoi usarlo es. txtCommessa.text=Chiamante.IDText End If End Sub![]()
Il mio problema è che dentro Intervento.aspx ho un HyperLink che mi rimanda a Ricerca.aspx e ha la proprietà Target = _blank ( ossia la apre in un'altra finestra )
L'utente cerca l'ID della Commessa su cui inserire un Intervento, una volta trovato( l'ID viene messo in una TextBox ) c'è il pulsante Conferma che chiude la finestra di Ricerca e il focus torna su Intervento.aspx che nel frattempo è restata aperta e dentro la txtCommessa ci Deve essere l'ID della Commessa.
In Intervento.aspx io uso il CodeBehind.
Come posso aggiustare ciò che mi hai suggerito tu in modo che mi funzioni ?
Vuoi che ti posti il codice delle pagine ?
Gran Duca del Fancazzismo, con Pieni Poteri per la Sezione Toscana del Clan, e Comandante Supremo delle Forze Aeree
Non Esistono Cose Impossibile, ma Solamente la Nostra Limitata Percezione di Ciò che è Possibile!
Ciao a tutti bellee rutti :maLOL:
Usa Javascript.
Nella pagina Ricerca inserisci questo script da richiamare alla pressione del tasto conferma:
codice:function SendIDAndClose() { window.opener.WriteID(document.getElementById(<idtextbox>).value); // inserire codice x chiusura finestra e focus.... } La funzione javascript nella pagina chiamante: function WriteID(theID) { document.getElementById(<idtextbox>).value = theID; }
Ciao, javalon![]()
Perchè non ci ho capito niente..Originariamente inviato da javalon
Usa Javascript.
Nella pagina Ricerca inserisci questo script da richiamare alla pressione del tasto conferma:
codice:function SendIDAndClose() { window.opener.WriteID(document.getElementById(<idtextbox>).value); // inserire codice x chiusura finestra e focus.... } La funzione javascript nella pagina chiamante: function WriteID(theID) { document.getElementById(<idtextbox>).value = theID; }
Ciao, javalon![]()
![]()
![]()
Gran Duca del Fancazzismo, con Pieni Poteri per la Sezione Toscana del Clan, e Comandante Supremo delle Forze Aeree
Non Esistono Cose Impossibile, ma Solamente la Nostra Limitata Percezione di Ciò che è Possibile!
Ciao a tutti bellee rutti :maLOL:
Intervento.aspx
codice:<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Intervento.aspx.vb" Inherits="WebApplication1.Intervento"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>Inserisci Intervento</title> <% @ Reference Page = "Ricerca.aspx" %> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE"> <meta content="JavaScript" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> <LINK href="Styles.css" type="text/css" rel="stylesheet"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <div>|<asp:button id="btnBye" onblur="javascript:this.className='bottone'" onmouseover="javascript:this.className='prova'" onfocus="javascript:this.className='prova'" tabIndex="1" onmouseout="javascript:this.className='bottone'" CssClass="bottone" CausesValidation="False" Text="Chiudi il Programma" Runat="server"></asp:button>| <asp:button id="btnVia" onblur="javascript:this.className='bottone'" onmouseover="javascript:this.className='prova'" onfocus="javascript:this.className='prova'" tabIndex="2" onmouseout="javascript:this.className='bottone'" CssClass="bottone" CausesValidation="False" Text="Log Out" Runat="server"></asp:button>| <asp:button id="btnCasa" onblur="javascript:this.className='bottone'" onmouseover="javascript:this.className='prova'" onfocus="javascript:this.className='prova'" tabIndex="3" onmouseout="javascript:this.className='bottone'" CssClass="bottone" CausesValidation="False" Text="Home Page" Runat="server"></asp:button>|</div> <asp:label id="Label1" style="Z-INDEX: 111; LEFT: 16px; POSITION: absolute; TOP: 144px" runat="server" Font-Bold="True" Font-Size="Medium" Font-Names="Arial" ForeColor="RoyalBlue">Il tuo Codice Persona è: </asp:label><asp:textbox id="txtPersona" style="Z-INDEX: 105; LEFT: 280px; POSITION: absolute; TOP: 144px" tabIndex="4" runat="server" Font-Names="Tahoma" ReadOnly="True"></asp:textbox><asp:label id="Label4" style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 72px" runat="server" Font-Bold="True" Font-Size="X-Large" Font-Names="Arial" ForeColor="DarkBlue"></asp:label><asp:regularexpressionvalidator id="RegularExpressionValidator3" style="Z-INDEX: 110; LEFT: 280px; POSITION: absolute; TOP: 344px" runat="server" Font-Names="Arial" ValidationExpression="(((0[1-9]|[12][0-9]|3[01])([-./])(0[13578]|10|12)([-./])(\d{4}))|(([0][1-9]|[12][0-9]|30)([-./])(0[469]|11)([-./])(\d{4}))|((0[1-9]|1[0-9]|2[0-8])([-./])(02)([-./])(\d{4}))|((29)(\.|-|\/)(02)([-./])([02468][048]00))|((29)([-./])(02)([-./])([13579][26]00))|((29)([-./])(02)([-./])([0-9][0-9][0][48]))|((29)([-./])(02)([-./])([0-9][0-9][2468][048]))|((29)([-./])(02)([-./])([0-9][0-9][13579][26])))" ErrorMessage="Data Non Valida" ControlToValidate="txtDay"></asp:regularexpressionvalidator><asp:label id="Label2" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 232px" runat="server" Font-Names="Arial" ForeColor="#3300CC">Codice Sotto Commessa</asp:label><asp:label id="Label5" style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 312px" runat="server" Font-Names="Arial" ForeColor="#3300CC">Data Intervento</asp:label><asp:label id="Label6" style="Z-INDEX: 104; LEFT: 16px; POSITION: absolute; TOP: 376px" runat="server" Font-Names="Arial" ForeColor="#3300CC">Ore</asp:label><asp:dropdownlist id="DropDownList1" style="Z-INDEX: 106; LEFT: 280px; POSITION: absolute; TOP: 232px" tabIndex="7" runat="server" Font-Names="Tahoma"></asp:dropdownlist><asp:textbox id="txtDay" style="Z-INDEX: 107; LEFT: 280px; POSITION: absolute; TOP: 312px" tabIndex="9" runat="server" Font-Names="Tahoma" Width="156"></asp:textbox><asp:textbox id="txtHours" style="Z-INDEX: 108; LEFT: 280px; POSITION: absolute; TOP: 376px" tabIndex="10" runat="server" Font-Names="Tahoma" Width="156"></asp:textbox><asp:button id="Button1" onblur="javascript:this.className='altro'" onmouseover="javascript:this.className='altri'" style="Z-INDEX: 109; LEFT: 280px; POSITION: absolute; TOP: 488px" onfocus="javascript:this.className='altri'" tabIndex="11" onmouseout="javascript:this.className='altro'" runat="server" CssClass="altro" Text="Inserisci"></asp:button><asp:requiredfieldvalidator id="RequiredFieldValidator1" style="Z-INDEX: 112; LEFT: 552px; POSITION: absolute; TOP: 192px" runat="server" Font-Names="Arial" ErrorMessage="Campo Obbligatorio" ControlToValidate="txtCommessa"></asp:requiredfieldvalidator><asp:requiredfieldvalidator id="RequiredFieldValidator2" style="Z-INDEX: 113; LEFT: 552px; POSITION: absolute; TOP: 232px" runat="server" Font-Names="Arial" ErrorMessage="Campo Obbligatorio" ControlToValidate="DropDownList1"></asp:requiredfieldvalidator><asp:requiredfieldvalidator id="RequiredFieldValidator3" style="Z-INDEX: 114; LEFT: 552px; POSITION: absolute; TOP: 312px" runat="server" Font-Names="Arial" ErrorMessage="Campo Obbligatorio" ControlToValidate="txtDay"></asp:requiredfieldvalidator><asp:requiredfieldvalidator id="RequiredFieldValidator4" style="Z-INDEX: 115; LEFT: 552px; POSITION: absolute; TOP: 376px" runat="server" Font-Names="Arial" ErrorMessage="Campo Obbligatorio" ControlToValidate="txtHours"></asp:requiredfieldvalidator><asp:label id="Label7" style="Z-INDEX: 116; LEFT: 16px; POSITION: absolute; TOP: 440px" runat="server" Font-Bold="True" Font-Size="Large" Font-Names="Tahoma" ForeColor="Red"> N.B. : Tutti i Campi sono Obbligatori!</asp:label><asp:label id="Label8" style="Z-INDEX: 117; LEFT: 16px; POSITION: absolute; TOP: 272px" runat="server" Font-Names="Arial" ForeColor="#3300CC">Nome Intevento</asp:label><asp:textbox id="txtNome" style="Z-INDEX: 118; LEFT: 280px; POSITION: absolute; TOP: 272px" tabIndex="8" runat="server" Width="224px"></asp:textbox><asp:requiredfieldvalidator id="RequiredFieldValidator5" style="Z-INDEX: 119; LEFT: 552px; POSITION: absolute; TOP: 272px" runat="server" Font-Names="Arial" ErrorMessage="Campo Obbligatorio" ControlToValidate="txtNome"></asp:requiredfieldvalidator><asp:comparevalidator id="CompareValidator1" style="Z-INDEX: 120; LEFT: 280px; POSITION: absolute; TOP: 408px" runat="server" Font-Names="Arial" ErrorMessage="Inserisci Cifre" ControlToValidate="txtHours" Type="Double" Operator="DataTypeCheck"></asp:comparevalidator><asp:textbox id="txtCommessa" style="Z-INDEX: 121; LEFT: 280px; POSITION: absolute; TOP: 189px" runat="server" tabIndex="6" ReadOnly="True"></asp:textbox> <asp:HyperLink id="HyperLink1" style="Z-INDEX: 122; LEFT: 16px; POSITION: absolute; TOP: 192px" runat="server" CssClass="beke" NavigateUrl="Ricerca.aspx" Target="_blank" tabIndex="5">Scegli la Commessa >></asp:HyperLink> </form> </body> </HTML>
Gran Duca del Fancazzismo, con Pieni Poteri per la Sezione Toscana del Clan, e Comandante Supremo delle Forze Aeree
Non Esistono Cose Impossibile, ma Solamente la Nostra Limitata Percezione di Ciò che è Possibile!
Ciao a tutti bellee rutti :maLOL:
Intervento.aspx.vb
codice:Imports System.Data Imports System.Data.OleDb Imports System.Web.UI.WebControls Public Class Intervento Inherits System.Web.UI.Page #Region " Codice generato da Progettazione Web Form " 'Chiamata richiesta da Progettazione Web Form. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Protected WithEvents Label2 As System.Web.UI.WebControls.Label Protected WithEvents Label5 As System.Web.UI.WebControls.Label Protected WithEvents Label6 As System.Web.UI.WebControls.Label Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList Protected WithEvents Button1 As System.Web.UI.WebControls.Button Protected WithEvents txtDay As System.Web.UI.WebControls.TextBox Protected WithEvents txtHours As System.Web.UI.WebControls.TextBox Protected WithEvents RegularExpressionValidator3 As System.Web.UI.WebControls.RegularExpressionValidator Protected WithEvents Label4 As System.Web.UI.WebControls.Label Protected WithEvents txtPersona As System.Web.UI.WebControls.TextBox Protected WithEvents Label1 As System.Web.UI.WebControls.Label Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents RequiredFieldValidator3 As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents RequiredFieldValidator4 As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents btnVia As System.Web.UI.WebControls.Button Protected WithEvents btnCasa As System.Web.UI.WebControls.Button Protected WithEvents Label7 As System.Web.UI.WebControls.Label Protected WithEvents Label8 As System.Web.UI.WebControls.Label Protected WithEvents RequiredFieldValidator5 As System.Web.UI.WebControls.RequiredFieldValidator Protected WithEvents txtNome As System.Web.UI.WebControls.TextBox Protected WithEvents btnBye As System.Web.UI.WebControls.Button Protected WithEvents CompareValidator1 As System.Web.UI.WebControls.CompareValidator Public txtCommessa As System.Web.UI.WebControls.TextBox Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink 'NOTA: la seguente dichiarazione è richiesta da Progettazione Web Form. 'Non spostarla o rimuoverla. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: questa chiamata al metodo è richiesta da Progettazione Web Form. 'Non modificarla nell'editor del codice. InitializeComponent() End Sub #End Region Dim Chiamante As Ricerca Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Session("Vialibera") = 1 Then If Not IsPostBack Then Dim connessione As String Dim conn As OleDbConnection Dim cmdSotto As OleDbCommand Dim dtrSotto As OleDbDataReader 'If txtCommessa.Text = " " Then ' DropDownList1.Enabled = False ' txtNome.Enabled = False ' txtDay.Enabled = False ' txtHours.Enabled = False 'End If Label4.Text = Session("Nome") & " " & Session("Cognome") connessione = ConfigurationSettings.AppSettings("conString") conn = New OleDbConnection(connessione) conn.Open() cmdSotto = New OleDbCommand("Select Id_Sotto FROM tblSottoCommesse ", conn) dtrSotto = cmdSotto.ExecuteReader() DropDownList1.DataSource = dtrSotto DropDownList1.DataTextField = "Id_Sotto" DropDownList1.DataValueField = "Id_Sotto" DropDownList1.DataBind() DropDownList1.Items.Insert(0, New ListItem("", "")) dtrSotto.Close() txtPersona.Text = Session("ID") txtCommessa.Text = Session("Chosen") conn.Close() Chiamante = CType(Context.Handler, Ricerca) txtCommessa.Text = Chiamante.IDText End If Else Response.Redirect("Login.aspx") End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim connessione As String Dim conn As OleDbConnection Dim cmdInsert As OleDbCommand Dim strInsert As String connessione = ConfigurationSettings.AppSettings("conString") conn = New OleDbConnection(connessione) conn.Open() strInsert = "INSERT INTO tblInterventi(Id_Sotto, Num_Comm, Codice, Nome_Inter, Data_Inter, Ore_Inter) VALUES ([@und], [@comm], [@pers], [@intername], [@day], [@hours])" cmdInsert = New OleDbCommand(strInsert, conn) cmdInsert.Parameters.Add("@und", DropDownList1.SelectedItem.Value) 'cmdInsert.Parameters.Add("@comm", txtCommessa.Text) cmdInsert.Parameters.Add("@pers", txtPersona.Text) cmdInsert.Parameters.Add("@intername", txtNome.Text) cmdInsert.Parameters.Add("@day", txtDay.Text) cmdInsert.Parameters.Add("@hours", txtHours.Text) cmdInsert.ExecuteNonQuery() conn.Close() DropDownList1.SelectedIndex = 0 txtDay.Text = "" txtHours.Text = "" txtNome.Text = "" If Session("MyType") = "Admin" Then Response.Redirect("HomeAdmin.aspx") Else If Session("MyType") = "Usr" Then Response.Redirect("Home.aspx") End If End If End Sub Private Sub btnVia_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVia.Click Session.Abandon() Response.Redirect("Benvenuto.aspx") End Sub Private Sub btnCasa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCasa.Click If Session("MyType") = "Admin" Then Response.Redirect("HomeAdmin.aspx") Else If Session("MyType") = "Usr" Then Response.Redirect("Home.aspx") End If End If End Sub Private Sub btnBye_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBye.Click Session.Abandon() Page.RegisterStartupScript("s", "<script>self.close();</script>") End Sub End Class
Gran Duca del Fancazzismo, con Pieni Poteri per la Sezione Toscana del Clan, e Comandante Supremo delle Forze Aeree
Non Esistono Cose Impossibile, ma Solamente la Nostra Limitata Percezione di Ciò che è Possibile!
Ciao a tutti bellee rutti :maLOL: