Fordelaktig.no
Webutvikler kurs ASP.NET, C#, CSS mm.

WebRessurs.no - Webprogrammering og ressurs innen ASP, ASP.NET, PHP, SQL, HTML, CSS, Javascript, XML, C#, VB, Flash  mm.

Brukernavn: 
Passord:

Registrèr deg Glemt passord?
Logg deg inn




  ASP.net (199)
  ASP 3.0 (111)
  PHP (30)
  HTML (66)
  SQL (89)
  CSS (46)
  XML (7)
  JavaScript (78)
  Diverse kode (13)


  Programmering (22)
  System og drift (15)
  Trafikk og inntekt (11)
  Guider og tips (22)
  Nyttig lesestoff (23)
  Web forum (592)
  Link galleri (566)


  ASP.NET kurs(5)
  CSS kurs (2)
  JQuery kurs (2)


  Øk trafikken (8)
  Facebook App. (4)
  Microsoft CEO (6)


  Server & web
  Internett & epost
  Systemverktøy
  Sikkerhet
  Fildeling
  Lyd & media
  Diverse software


  Domenesalg
  Metagenerator
  Websikre farger
  Gratis epost
  WebMail


  Bli medlem!
  Siste innlegg
  Gjestebok
  Tips en venn
  Kontakt oss
  Forsiden




Kode Artikler
Linker


Mål internetthastigheten din.


Property: Vise en User Control avhengig av input fra brukeren.

av Øyvind A. Isaksen
 
Denne artikkelen tar for seg bruken av Property og Viewstate, og viser en User Contol avhengig av om en bruker har tastet inn et korrekt passord eller ikke. For å kommunisere mellom en ASP.NET side og en User Control lager vi en property som vi benytter til dette.

Eksempelet består av 2 filer; register.aspx og ucRegister.ascx (User Control).

-----------------------------------------
register.aspx
-----------------------------------------

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="register.aspx.vb" Inherits="crm.register"%>
<%@ Register TagPrefix="uc1" TagName="ucRegister" Src="usercontrols/user/ucRegister.ascx" %>

<form id="Form1" method="post" runat="server">
<asp:textbox id="txtVerify" Runat="server" Columns="10"></asp:textbox>
<asp:button id="btnVerify" Runat="server" Text="Send"></asp:button>
<uc1:ucRegister id="UcRegister1" runat="server" visible="false"></uc1:ucRegister>
</form>

-----------------------------------------
register.aspx.vb (Code Behind fila)
-----------------------------------------

Imports System.Data.SqlClient

Public Class register
Inherits System.Web.UI.Page
Protected WithEvents txtVerify As System.Web.UI.WebControls.TextBox
Protected WithEvents btnVerify As System.Web.UI.WebControls.Button
Protected WithEvents ucRegister1 As ucRegister

Private Sub btnVerify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVerify.Click
Dim SQL As String = "select custID from tblCustomer where password=@password and active = '1'"
Dim conn As New SqlConnection(variables.ConnString)
Dim cmd As New SqlCommand(SQL, conn)
Dim parameter1 As New SqlParameter("@password", Me.txtVerify.Text)
cmd.Parameters.Add(parameter1)

conn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
While dr.Read
ucRegister1.customerID = dr.Item("custID")
ucRegister1.Visible = True
End While

conn.Close()
conn.Dispose()
cmd.Dispose()
End Sub
End Class


-----------------------------------------
register.ascx (User Control)
-----------------------------------------

<%@ Control Language="vb" AutoEventWireup="false" Codebehind="ucRegister.ascx.vb" Inherits="crm.ucRegister" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>

<asp:TextBox id="txtFname" runat="server"></asp:TextBox>
<asp:TextBox id="txtLname" runat="server"></asp:TextBox>
<asp:Button id="btnRegister" runat="server" Text="Button"></asp:Button>

-----------------------------------------
register.ascx (User Control - Code Behind)
-----------------------------------------

Imports System.Data.SqlClient

Public MustInherit Class ucRegister
Inherits System.Web.UI.UserControl
Protected WithEvents txtFname As System.Web.UI.WebControls.TextBox
Protected WithEvents txtLname As System.Web.UI.WebControls.TextBox
Protected WithEvents btnRegister As System.Web.UI.WebControls.Button


Public Property customerID() As Integer
Get
Return viewstate("customerID")
End Get
Set(ByVal Value As Integer)
viewstate("customerID") = Value
End Set
End Property


Private Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
Dim SQL As String = "insert into tblEmployee (fname,lname,custID) values (@fname,@lname,@custID)"
Dim conn As New SqlConnection(variables.ConnString)
Dim cmd As New SqlCommand(SQL, conn)
Dim parameter1 As New SqlParameter("@fname", Me.txtFname.Text)
Dim parameter2 As New SqlParameter("@lname", Me.txtLname.Text)
Dim parameter3 As New SqlParameter("@custID", customerID)
cmd.Parameters.Add(parameter1)
cmd.Parameters.Add(parameter2)
cmd.Connection.Open()
Response.Write(customerID)
'cmd.ExecuteNonQuery()
cmd.Connection.Close()
cmd.Dispose()
conn.Dispose()
End Sub
End Class

WebRessurs.no anbefaler:    StackOverflow.com | Experts-Exchange.com | W3schools | ASP.NET | Codeproject | 4Guys
WebRessurs.no er utviklet og drives av SoftMaker LTD
Sett som startside: [ ]. Bokmerk denne siden: [ klikk ]. Sitemap. http://twitter.com/webressurs_no/. Antall brukersesjoner: 9013848.
Copyright WebRessurs.no © 2003 - 2015
Turvenn.no