HighTechTalks DotNet Forums  

Re: Controls accessing outside tags

ASP.net ASP.net discussions (microsoft.public.dotnet.framework.aspnet)


Discuss Re: Controls accessing outside tags in the ASP.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
tshad
 
Posts: n/a

Default Re: Controls accessing outside tags - 07-26-2007 , 11:59 AM







"Göran Andersson" <guffa (AT) guffa (DOT) com> wrote

Quote:
tshad wrote:
I tried looped through the Form elements and found that the name of the
textbox is actually - LoginID:txtUserName.

That's odd. That name is not very usable. I would expect the name to be
LoginID$txtUserName and the id to be LoginID_txtUserName. That's how
controls are usually named.

What does the generated html code for the form look like?
Here is the line with the input tag:

<input name="LoginID:txtUserName" type="text" size="25"
id="LoginID_txtUserName" />
<span id="LoginID__ctl0" controltovalidate="LoginID_txtUserName"
evaluationfunction="RequiredFieldValidatorEvaluate IsValid" initialvalue=""
style="color:Red;visibility:hidden;">User Name Required</span>

What is interesting is that the javascript uses the LoginID:txtUserName and
the ID uses the underscore. The trace shows the ":" which is the Name not
the ID.

__PAGE ASP.test_aspx
_ctl0 System.Web.UI.LiteralControl
_ctl1 System.Web.UI.ResourceBasedLiteralControl
myBody System.Web.UI.HtmlControls.HtmlGenericControl
_ctl2 System.Web.UI.LiteralControl
addForm System.Web.UI.HtmlControls.HtmlForm
_ctl3 System.Web.UI.LiteralControl
LoginID ASP.test_ascx
LoginID:_ctl1 System.Web.UI.LiteralControl
LoginID:txtUserName System.Web.UI.WebControls.TextBox
LoginID:_ctl2 System.Web.UI.LiteralControl
LoginID:_ctl0
System.Web.UI.WebControls.RequiredFieldValidator
LoginID:_ctl3 System.Web.UI.LiteralControl
_ctl4 System.Web.UI.LiteralControl
_ctl5 System.Web.UI.LiteralControl
_ctl6 System.Web.UI.LiteralControl

The code that works uses the ":" in the function just not in the inline code
as shown here:

function GetFocus()
{
if (document.getElementById("LoginID:txtUserName") != null)
{
document.getElementById("LoginID:txtUserName").foc us();
}
}

Thanks,

Tom

Quote:
I change the attribute lines to:

Dim a as htmlControl
a = CType(Page.FindControl("myBody"),htmlControl)

a.Attributes.Add("onLoad","onload=document.addForm .LoginID:txtUserName.focus();")

An identifier in Javascript can not contain a colon. If the name really
contains a colon, you would need to use a string to reference it:

onload=document.addForm.elements('LoginID:txtUserN ame').focus();

I am not getting there error now, but I am also not getting focus.

The browser doesn't display Javscript errors by default. In Internet
Explorer they show up as a notice in the status bar. In Firefox you open
the Error Console to see them.

--
Göran Andersson
_____
http://www.guffa.com



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.