Salve Ragazzi,
Ho un problema in una webfom con Master Page.
Non riesco a fare il focus su una textbox nella Page_Load della webform.
Ho trovato 100 suggerimenti ma nessuno fuziona: dal javascript al Focus()...nulla, non va.
Questa e' la Master Page:
<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Site1.master.vb" Inherits="Logbook.Site1" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajaxToolkit" %>
<!DOCTYPE html>
<html>
<head runat="server">
<link href="~/Style/StyleSheet.css" rel="stylesheet" type="text/css" id="css1"/>
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div class="div">
<asp:Label ID="Label1" runat="server" Text="Production Logbook" CssClass="label_page_Title"></asp:Label>
</div>
<br />
<div class="div">
<asp:Image ID="Logo" runat="server" ImageUrl="~/Img/Logo_White_small.png" Height="16px" Width="77px"/>
<asp:Image ID="Image1" runat="server" ImageUrl="~/Img/login.png" />
<asp:Label ID="L_Username" runat="server" CssClass="label_login" />
</div>
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
e questa e' la webform:
<%@ Page Title="" Language="vb" AutoEventWireup="true" MasterPageFile="~/Site1.Master" CodeBehind="Default.aspx.vb" Inherits="Logbook._Default" MaintainScrollPositionOnPostback="true" %>
<%@ Register assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI.DataVisualization.Charting" tagprefix="asp" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajaxToolkit" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="div_body">
<br />
<br />
<div class ="div">
<table class="table">
<tr>
<td>
<asp:TextBox ID="TB_Barcode" runat="server" CssClass="textbox" AutoPostBack="True"></asp:TextBox>
<ajaxToolkit:TextBoxWatermarkExtender ID="TextBox1_TBWE" runat="server" BehaviorID="TextBox1_TBWE" TargetControlID="TB_Barcode" WatermarkCssClass="Watermark" WatermarkText="Scan the barcode" />
</td>
<td>
<asp:Image ID="I_Reset" runat="server" ImageUrl="~/Img/RESET.png"/>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Come dicevo, i vari:
o
Page.Form.DefaultFocus = TB_Barcode.ClientID
o
<script type=text/javascript>
<!--
function windowOnLoad()
{
document.getElementById('<%= (WebUserControl1.FindControl("TB_Barcode")).ClientID %>').focus();
}
window.onload = windowOnLoad;
// -->
</script>
o
Public Sub SetFocus(ByVal control As Control)
Dim sb As StringBuilder = New StringBuilder()
Dim body As HtmlGenericControl
Dim p As Control = control.Parent
While Not ((TypeOf (p) Is System.Web.UI.HtmlControls.HtmlForm))
p = p.Parent
End While
p = p.Parent
body = CType(p, HtmlGenericControl)
If Not (p Is Nothing) Then
body.Attributes.Add("onload", body.Attributes("onload").ToString & "document.getElementById('" & control.ClientID & "').focus();")
End If
End Sub
non funzionano.
Avete qualche altra dritta da suggerirmi?
Grazie
Marco