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 Buttons, um den Focus auf TextBox 2 oder 3 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!