Categories: Snippets, Community.NET, German Posted by AlexanderZeitler on 4/13/2006 5:34 AM | Comments (0)

CodeKeep.NET ist ein Repository für CodeSnippets für etliche Sprachen wie C#, VB.NET, ASP.NET, HTML, CSS, Javascript usw.

Aktuell sind über 6.000 Snippets verfügbar - da sollte sicher die eine oder andere Problemlösung dabei sein ;-)

Currently rated 1.3 by 13 people

  • Currently 1.307692/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories: Code, Snippets, Training, Slides Posted by AlexanderZeitler on 8/16/2005 7:19 AM | Comments (0)

Christoph Wille has uploaded the Slides and Demos (both in english language) for the past NCC 2005A Security.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories: Snippets, CSharp, Framework.NET Posted by AlexanderZeitler on 11/12/2004 9:30 AM | Comments (3)

Nachdem ich mich nun zum x-ten Mal über das umständliche Handling der Split-Methode geärgert habe, habe ich sie mir in eine kleine Klasse verpackt:

using System;

namespace MyPersonal.Utils
{
    /// <summary>
    /// Zusammenfassung für StringHelper.
    /// </summary>
    public class StringHelper
    {
        public static string [] Split(string Words, string Delimiter) {
            char [] delimiter = Delimiter.ToCharArray();
            string [] split = null;
            split = Words.Split(delimiter);
            return split;
        }
    }
}

Aufruf:

string [] words = StringHelper.Split("Eins,Zwei,Drei",",");

Auflösung siehe Kommentare - stellt sich die Frage, was ich heute morgen gedacht habe ;-)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories: ASP.NET, Basics, Code, Snippets Posted by AlexanderZeitler on 9/20/2004 6:31 PM | Comments (0)

Bedingt durch ein Posting in der ASP.NET-Mailingliste habe ich ein wenig mit der ASP.NET DataList gespielt - Resultat ist die Möglichkeit, Inhalt in DataListItems per Mausklick ein- und auszublenden.

Zur Verdeutlichung rechts einige Screenshots. Dargestellt sind die Kunden aus der bekannten Northwind-Datenbank.

Der Code der .aspx-Datei:

<%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="false" Inherits="BlogSamples.DataListItemInvisible._default" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>default1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="GridLayout">
    
<form id="Form1" method="post" runat="server">
    <asp:datalist id="DataList1" runat="server">
        <headertemplate><h1>Kunden</h1>    </headertemplate>
        <itemstyle backcolor="#ffffff" />
        <itemtemplate>
            <asp:linkbutton runat="server" id="lbtShowHide" commandname="show">
            <%# DataBinder.Eval(Container, "DataItem.CompanyName") %>
            </asp:linkbutton>
            <br/>
            <asp:label id="lblAddress" runat="server" visible="False">
            <%# DataBinder.Eval(Container, "DataItem.Address") %>
            </asp:label>
            <asp:label id="lblCountry" runat="server" visible="False">
            <%# DataBinder.Eval(Container, "DataItem.Country") %>
            </asp:label>
            <hr/>
        </itemtemplate>
    </asp:datalist>
</form>
</body>
</html>

Der Code der .aspx.cs-Datei:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace BlogSamples.DataListItemInvisible
{
    /// <summary>
    /// Zusammenfassung fr default.
    /// </summary>
    public class _default : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.DataList DataList1;
    
        private void Page_Load(object sender, System.EventArgs e) {
        if(!Page.IsPostBack)
        {
            // Datenbindung
            DataList1.DataSource = this.ReadDataFromDB();
            DataList1.DataKeyField = "CustomerID";
            DataList1.DataBind();
            }
        }

        // Daten aus der Northwind-DB lesen
        private DataSet ReadDataFromDB() {
            OleDbConnection MyNWConn =
                new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../data/Nwind.mdb"));
            DataSet MyDataSet = new DataSet();
            OleDbDataAdapter oCommand = new OleDbDataAdapter();
            OleDbCommand oledbcmd = new OleDbCommand();
            oledbcmd.CommandType = CommandType.StoredProcedure;
            oledbcmd.CommandText = "[SelectCustomers]";
            oledbcmd.Connection = MyNWConn;
            oCommand.SelectCommand = oledbcmd;
            oCommand.Fill(MyDataSet,"Orders");
            MyNWConn.Close();
            return MyDataSet;
        }


        #region Vom Web Form-Designer generierter Code
        override protected void OnInit(EventArgs e) {
            //
            // CODEGEN: Dieser Aufruf ist fr den ASP.NET Web Form-Designer erforderlich.
            //
            InitializeComponent();
            base.OnInit(e);
        }
        
        /// <summary>
        /// Erforderliche Methode fr die Designeruntersttzung.
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor gendert werden.
        /// </summary>
        private void InitializeComponent() {
            this.Load += new System.EventHandler(this.Page_Load);
            this.DataList1.ItemCommand += new DataListCommandEventHandler(DataList1_ItemCommand);
        }
        #endregion

        //Auswertung des geklickten LinkButtons
        private void DataList1_ItemCommand(object source, DataListCommandEventArgs e) {
            if(e.CommandName == "show") {
                ((Label)e.Item.FindControl("lblAddress")).Visible = true;
                ((Label)e.Item.FindControl("lblCountry")).Visible = true;
                ((LinkButton)e.Item.Controls[1]).CommandName = "hide";

            }
            if(e.CommandName == "hide") {
                ((Label)e.Item.FindControl("lblAddress")).Visible = false;
                ((Label)e.Item.FindControl("lblCountry")).Visible = false;
                ((LinkButton)e.Item.FindControl("lbtShowHide")).CommandName = "show";
            }
        }
    }
}

Zunächst die Liste vor dem Klick auf den Namen des Kunden:

Nach dem Klick auf den Namen des Kunden erscheinen die übrigen Daten:

Ein weiterer Klick auf den Namen lässt die erweiterten Informationen wieder verschwinden:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories: Code, Components, Snippets, Community.NET Posted by AlexanderZeitler on 8/27/2004 5:24 PM | Comments (0)

Scott Mitchell betreibt bereits seit längerem die Seite "The .NET Toolbox". Dort listet er freie .NET-Tools und -Komponenten sowie Bewertungen und Reviews derselben.

Currently rated 1.1 by 7 people

  • Currently 1.142857/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories: Code, Components, Snippets Posted by AlexanderZeitler on 7/8/2004 10:16 AM | Comments (0)

In der ASP.NET-Mailingliste kam die Frage auf, wie man mehrere .config-Files, wie es z.B. dasBlog tut, verwenden kann. Die Lösung liefert Daniel Fisher's custom configuration file AppSettings reader Klasse.

Die Klasse lässt sich problemlos mit dem von mir vorgestellten ApplicationSettings Wrapper verwenden - ein Beispiel für die Verwendung mit zwei .config-Files (web.config und DataAccess.config) könnte z.B. so aussehen:

using System;
using System.Configuration;
using System.Web;
using System.Web.UI;
using StaticDust.Configuration;

namespace MyApplication.Configuration
{
    /// <summary>
    /// Zusammenfassung für Configuration.
    /// </summary>
    internal class Web
    {
        public static string BaseURL
        {
            get
            {
                return LoadConfigValue("BaseURL");
            }
        }


        /// <summary>
        /// Liefert den angefordeten Keyvalue aus der
        /// web.config zurück und cached diesen, falls
        /// noch nicht gecached.
        /// </summary>
        /// <param name="nameInWebConfig">Der angefordete Keyname
        /// in der web.config</param>
        /// <returns>Der Keyvalue aus der web.config.</returns>
        private static string LoadConfigValue(string nameInWebConfig)
        {
            string nameInApplication = "ConfigWeb" + nameInWebConfig;
            HttpApplicationState app = HttpContext.Current.Application;
            if( app[nameInApplication] == null )
            {
                app[nameInApplication] =
                    ConfigurationSettings.AppSettings[nameInWebConfig];
            }
            return
                app[nameInApplication].ToString();
        }
    }

    internal class DataAccess
    {
        /// <summary>
        /// Liefert den in der web.config gespeicherten
        /// Connectionstring zurück.
        /// </summary>
        public static string ConnectionString
        {
            get
            {
                return LoadConfigValue("ConnectionString");
            }
        }

        /// <summary>
        /// Liefert den angefordeten Keyvalue aus der
        /// web.config zurück und cached diesen, falls
        /// noch nicht gecached.
        /// </summary>
        /// <param name="nameInWebConfig">Der angefordete Keyname
        /// in der web.config</param>
        /// <returns>Der Keyvalue aus der web.config.</returns>
        private static string LoadConfigValue(string nameInWebConfig)
        {
            string nameInApplication = "ConfigDataAccess" + nameInWebConfig;
            HttpApplicationState app = HttpContext.Current.Application;
            if( app[nameInApplication] == null )
            {
                app[nameInApplication] =
                    CustomConfigurationSettings.AppSettings(
                    HttpContext.Current.Server.MapPath("DataAccess.config"))[nameInWebConfig];

            }
            return
                app[nameInApplication].ToString();
        }
    }
}

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories: Allgemein, Blog, Code, Snippets Posted by AlexanderZeitler on 9/24/2003 8:52 AM | Comments (0)

Ab sofort können Sie den SourceCode zu den hier vorgestellten Beispiel herunterladen.

Den Download finden Sie hier

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories: ASP.NET, Controls, FAQ, Code, Snippets Posted by AlexanderZeitler on 9/17/2003 5:00 PM | Comments (0)

Möchte man WebControls z.B. in Abhängigkeit von der Auswahl in einer DropDownList zur Laufzeit erzeugen, gibt es eine einfache Möglichkeit: man verwendet einen sog. PlaceHolder. Dieser fungiert als Platzhalter an der Stelle, an der später das entsprechende Control dynamisch erzeugt werden soll.

Zur Verdeutlichung des Ziels finden Sie hier ein Beispiel: Beispiel zur dynamischen Erzeugung von WebControls

Der Code der aspx-Datei sieht wie folgt aus:

 

 
1:   <%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="false" Inherits="BlogSamples.DynamicControls._default" %>
2:   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
3:   <HTML>
4:       <HEAD>
5:           <title>default</title>
6:           <meta name="vs_snapToGrid" content="False">
7:           <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
8:           <meta name="CODE_LANGUAGE" Content="C#">
9:           <meta name="vs_defaultClientScript" content="JavaScript">
10:           <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
11:       </HEAD>
12:       <body MS_POSITIONING="GridLayout">
13:           <form id="Form1" method="post" runat="server">
14:               <asp:DropDownList     id="DropDownList1"#
15:                                   style="Z-INDEX: 101; LEFT: 24px; POSITION: absolute; TOP: 120px"
16:                                   runat="server">
17:               </asp:DropDownList>
18:               <asp:Label            id="Label1"
19:                                   style="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 32px" 
20:                                   runat="server"
21:                                   Width="376px" 
22:                                   Font-Bold="True">Beispiel zur dynamischen Erzeugung von WebControls
23:               </asp:Label>
24:               <asp:Label             id="Label2" 
25:                                   style="Z-INDEX: 103; LEFT: 24px; POSITION: absolute; TOP: 72px" 
26:                                   runat="server"
27:                                   Width="579px"
28:                                   Height="24px">Bitte wählen Sie ein WebControl in der DropDownList aus und klicken Sie auf den Button.
29:               </asp:Label>
30:               <asp:Button         id="Button1" 
31:                                   style="Z-INDEX: 104; LEFT: 200px; POSITION: absolute; TOP: 120px" 
32:                                   runat="server"
33:                                   Width="48px" 
34:                                   Height="24px" 
35:                                   Text="Button">
36:               </asp:Button>
37:               <table                 style="Z-INDEX: 104; LEFT: 24px; POSITION: absolute; TOP: 150px" 
38:                                   cellpadding="0"
39:                                   cellspacing="0">
40:                   <tr>
41:                       <td>
42:                           <asp:PlaceHolder     id="PlaceHolder1" 
43:                                               runat="server">
44:                           </asp:PlaceHolder>
45:                       </td>
46:                   </tr>
47:               </table>
48:           </form>
49:       </body>
50:   </HTML>

Der Code der zugehörigen CodeBehind-Datei:

 
1:   public class _default : System.Web.UI.Page
2:   {
3:       protected System.Web.UI.WebControls.DropDownList DropDownList1;
4:       protected System.Web.UI.WebControls.Label Label1;
5:       protected System.Web.UI.WebControls.Label Label2;
6:       protected System.Web.UI.WebControls.Button Button1;
7:       protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1;
8:       ICollection CreateDataSource() 
9:       {
10:           DataTable dt new DataTable();
11:           DataRow dr1;
12:           DataRow dr2;
13:           DataRow dr3;
14:  
15:           dt.Columns.Add(new DataColumn("IntegerValue"typeof(Int32)));
16:           dt.Columns.Add(new DataColumn("ControlType"typeof(string)));
17:  
18:           dr1 dt.NewRow();
19:           dr1[0] = 1;
20:           dr1[1] = "DropDownList";
21:  
22:           dr2 dt.NewRow();
23:           dr2[0] = 2;
24:           dr2[1] = "Label";
25:  
26:           dt.Rows.Add(dr1);
27:           dt.Rows.Add(dr2);
28:  
29:           DataView dv new DataView(dt);
30:           return dv;
31:       }
32:  
33:       private void Page_Load(object senderSystem.EventArgs e)
34:       {
35:           if(!IsPostBack)
36:           {
37:               DropDownList1.DataSource CreateDataSource();
38:               DropDownList1.DataTextField "ControlType";
39:               DropDownList1.DataValueField "IntegerValue";
40:               DropDownList1.DataBind();
41:               }
42:           }
43:  
44:       private void Button1_Click(object senderSystem.EventArgs e)
45:       {
46:           switch(int.Parse(DropDownList1.Items[DropDownList1.SelectedIndex].Value.ToString()))
47:           {
48:               case 1:
49:                   PlaceHolder1.Controls.Clear();
50:                   DropDownList DDLDynamic new DropDownList();
51:                   DDLDynamic.DataSource CreateDataSource();
52:                   DDLDynamic.DataTextField "ControlType";
53:                   DDLDynamic.DataValueField "IntegerValue";
54:                   DDLDynamic.DataBind();
55:                   PlaceHolder1.Controls.Add(DDLDynamic);
56:                   break;
57:               case 2:
58:                   PlaceHolder1.Controls.Clear();
59:                   Label LBLDynamic new Label();
60:                   LBLDynamic.Text "Hello World! - dynamisch erzeugt";
61:                   PlaceHolder1.Controls.Add(LBLDynamic);
62:                   break;
63:           }
64:       }
65:   }

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories: ASP.NET, Basics, FAQ, Code, Snippets Posted by AlexanderZeitler on 9/16/2003 6:52 PM | Comments (0)

Manchmal muß man auf die Eingabe in einer TextBox bereits bei der Eingabe reagieren. Für dieses Zweck stellt das .NET-Framework den Eventhandler .TextChanged zur Verfügung. Allerdings funktioniert der Eventhandler nicht "as is". Für die zu überwachende TextBox muß zusätzlich AutoPostBack aktiviert werden. Außerdem muß die TextBox nach der Eingabe verlassen werden (z.B. durch Drücken der TAB-Taste). Eine zeitnahe Reaktion auf die Eingabe ist also nicht möglich.

Ein Beispiel hierfür finden Sie hier: TextChanged Beispiel mit .NET-Bordmitteln

Der SourceCode sieht wie folgt aus:

dotnet.aspx:

 
1:   <%@ Page language="c#" Codebehind="dotnet.aspx.cs" AutoEventWireup="false" Inherits="BlogSamples.onTextChange.dotnet" %>
2:   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
3:   <HTML>
4:       <HEAD>
5:           <meta name="vs_snapToGrid" content="True">
6:           <title>default</title>
7:           <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
8:           <meta name="CODE_LANGUAGE" Content="C#">
9:           <meta name="vs_defaultClientScript" content="JavaScript">
10:           <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
11:       </HEAD>
12:       <body MS_POSITIONING="GridLayout">
13:           <form id="Form1" method="post" runat="server">
14:               <asp:TextBox    id="TextBox1"
15:                               style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 88px" 
16:                               runat="server"
17:                               AutoPostBack="True">
18:               </asp:TextBox>
19:               <asp:Label     id="Label1" 
20:                           style="Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 64px"
21:                           runat="server"
22:                           Width="512px">
23:                           Bitte geben Sie einen Text ein und drücken Sie nach Ihrer Eingabe die TAB-Taste
24:               </asp:Label>
25:               <asp:Label     id="Label2" 
26:                           style="Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 120px"
27:                           runat="server"
28:                           Width="146px">
29:                           Ihre Eingabe bisher:
30:               </asp:Label>
31:               <asp:Label     id="Label3" 
32:                           style="Z-INDEX: 104; LEFT: 32px; POSITION: absolute; TOP: 144px" 
33:                           runat="server"
34:                           Width="197px" 
35:                           ForeColor="Blue">
36:               </asp:Label>
37:               <asp:Label     id="Label4" 
38:                           style="Z-INDEX: 105; LEFT: 32px; POSITION: absolute; TOP: 24px" 
39:                           runat="server"
40:                           Width="344px" 
41:                           Font-Bold="True">
42:                           TextChanged Beispiel  mit .NET-Bordmitteln
43:               </asp:Label>
44:               <asp:Label     id="Label5" 
45:                           style="Z-INDEX: 106; LEFT: 32px; POSITION: absolute; TOP: 184px" 
46:                           runat="server">PostBack ausgelöst:
47:               </asp:Label>
48:               <asp:Label     id="Label6" 
49:                           style="Z-INDEX: 107; LEFT: 168px; POSITION: absolute; TOP: 184px" 
50:                           runat="server"
51:                           Width="56px" 
52:                           Font-Bold="True" 
53:                           ForeColor="DarkRed">
54:               </asp:Label>
55:           </form>
56:       </body>
57:

  </HTML>

 

dotnet.aspx.cs:

 
1:   public class dotnet : System.Web.UI.Page
2:   {
3:       protected System.Web.UI.WebControls.TextBox TextBox1;
4:       protected System.Web.UI.WebControls.Label Label1;
5:       protected System.Web.UI.WebControls.Label Label2;
6:       protected System.Web.UI.WebControls.Label Label4;
7:       protected System.Web.UI.WebControls.Label Label5;
8:       protected System.Web.UI.WebControls.Label Label6;
9:       protected System.Web.UI.WebControls.Label Label3;
10:  
11:       private void Page_Load(object senderSystem.EventArgs e)
12:       {
13:           if(!IsPostBack)
14:           {
15:               Label6.Text="nein";
16:           }
17:           else
18:           {
19:               Label6.Text="ja";
20:           }
21:       }
22:  
23:       private void TextBox1_TextChanged(object senderSystem.EventArgs e)
24:       {
25:       Label3.Text=TextBox1.Text;
26:       }
27:   }

Abhilfe schafft hier die Verwendung von Javascript. Dieses lässt sich leicht mittels WebControls.Attributes.Add(key, valuestring) injizieren. Damit kann bei jedem erfassten oder gelöschten Zeichen in der TextBox ohne PostBack sofort auf die Eingabe reagiert wrden.

Das Beispiel findet sich hier: TextChanged Beispiel mit JavaScript

Der Code der aspx-Datei ist bis auf die Aktivierung von AutoPostBack identisch mit dem vorangegangenen Beispiel, der Code der javascript.cs sieht wie folgt aus:

 
1:   public class _default : System.Web.UI.Page
2:   {
3:       protected System.Web.UI.WebControls.TextBox TextBox1;
4:       protected System.Web.UI.WebControls.Label Label1;
5:       protected System.Web.UI.WebControls.Label Label2;
6:       protected System.Web.UI.WebControls.Label Label4;
7:       protected System.Web.UI.WebControls.Label Label5;
8:       protected System.Web.UI.WebControls.Label Label6;
9:       protected System.Web.UI.WebControls.Label Label3;
10:  
11:       private void Page_Load(object senderSystem.EventArgs e)
12:       {
13:           TextBox1.Attributes.Add("onKeydown","Label3.innerText=TextBox1.value");
14:           if(!IsPostBack)
15:           {
16:               Label6.Text="nein";
17:           }
18:           else
19:           {
20:               Label6.Text="ja";
21:           }
22:       }
23:   }

Currently rated 1.1 by 7 people

  • Currently 1.142857/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories: ASP.NET, Basics, FAQ, Code, Snippets Posted by AlexanderZeitler on 9/15/2003 4:14 PM | Comments (0)

Aus Zeitmangel gibts heute nur einen einfachen Quicky zum Thema ASP.NET:

Das Problem: Der Focus, sprich Cursor soll beim Laden der Seite und nach dem Klick auf einen Button, auf ein bestimmtes Element der Seite springen.

Zur Verdeutlichung gibt's auch heute wieder ein Sample.

Der Code ähnelt sehr stark dem normalen HTML/Javascript:

 
1:   <%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="false" Inherits="BlogSamples.FocusSample._default" %>
2:   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
3:   <HTML>
4:       <HEAD>
5:           <title>Focus Sample</title>
6:           <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
7:           <meta name="CODE_LANGUAGE" Content="C#">
8:           <meta name="vs_defaultClientScript" content="JavaScript">
9:           <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
10:       </HEAD>
11:       <script language=javascript>
12:                   function Nothing_Clicked()
13:                   {    document.all('txtInput1').focus();
14:                       return false;
15:                   }
16:                   function cmdButton1_Clicked()
17:                   {    document.all('txtInput2').focus();
18:                       return false;
19:                   }
20:                   
21:                   function cmdButton2_Clicked()
22:                   {    document.all('txtInput3').focus();
23:                       return false;
24:       }
25:       </script>
26:       <body MS_POSITIONING="GridLayout" onload="return Nothing_Clicked()">
27:           <form id="Form1" method="post" runat="server">
28:               TextBox 1:
29:               <asp:TextBox ID="txtInput1" Runat="server" Width="50" /> (Focus beim Laden der Seite)
30:               <br>
31:               TextBox 2:
32:               <asp:TextBox ID="txtInput2" Runat="server" Width="50" />
33:               <br>
34:               TextBox 3:
35:               <asp:TextBox ID="txtInput3" Runat="server" Width="50" />
36:               <br>
37:               <br>
38:               Klicken Sie bitte auf einen der Buttonsum den Focus auf TextBox oder zu setzen:<br>
39:               <input ID="cmdButton1" type="button" value="Focus auf TextBox 2" OnClick="return cmdButton1_Clicked()">
40:               <input ID="cmdButton2" type="button" value="Focus auf TextBox 3" OnClick="return cmdButton2_Clicked()">
41:           </form>
42:       </body>
43:   </HTML>
Wichtig: Arbeiten Sie mit CodeBehind, muß das Projekt dennoch compiliert werden, damit der Code funktioniert!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5