I'm passing Me.Page in a function call. The function is receiving Me.Page as a Control. I need to add attributes to the control so that I can use onfocus, but I get an error message saying "Attributes is not a member of System.Web.UI.Control. How can
I do this?
Thanks - is there a way to handle this so that I can pass the Page as a WebControl or change the pass value to a web control after it's been received by the function?
Have you tried using page.findcontrol() to find the control in question and cast it for the control type? You can then set attributes. That should work I think.
Tried it as HookOnFocus(Me.Page.FindControl()). But it didn't like the statement. I doing it inside Page Load when in a Non Pageback event after Refresh. I can use Attributes.Add for each element in the Page Load to get the Element for setting focus.
But was trying to use a function that wasn't specific to a particular field.
No I mean inside the hookonfocus function use currentcontrol.findcontrol("textbox1") and cast that to textbox. Now you can do stuff on it. Something like that.
Problem is - I don't know what the control is. I was basically trying to pass the page as a control to the function that would then based on the type of control do the following:
sarndt
Member
72 Points
33 Posts
Add Attribitutes
Feb 17, 2012 04:47 PM|LINK
I'm passing Me.Page in a function call. The function is receiving Me.Page as a Control. I need to add attributes to the control so that I can use onfocus, but I get an error message saying "Attributes is not a member of System.Web.UI.Control. How can I do this?
Code is
HookOnFocus(Me.Page)
Private HookOnFocus(CurrentControl As Control)
CurrentControl.Attributes.Add("on focus",........................................)
I'm using Microsoft Visual Studio 2010 VB
Thanks
rossisdead2
Participant
1313 Points
300 Posts
Re: Add Attribitutes
Feb 17, 2012 04:50 PM|LINK
The Control class itself doesn't implement IAttributeAccessor, which is what gives web controls the Attributes property.
sarndt
Member
72 Points
33 Posts
Re: Add Attribitutes
Feb 17, 2012 04:53 PM|LINK
Thanks - is there a way to handle this so that I can pass the Page as a WebControl or change the pass value to a web control after it's been received by the function?
MetalAsp.Net
All-Star
112032 Points
18231 Posts
Moderator
Re: Add Attribitutes
Feb 17, 2012 04:59 PM|LINK
sarndt
Member
72 Points
33 Posts
Re: Add Attribitutes
Feb 17, 2012 05:04 PM|LINK
Tried it as HookOnFocus(Me.Page.FindControl()). But it didn't like the statement. I doing it inside Page Load when in a Non Pageback event after Refresh. I can use Attributes.Add for each element in the Page Load to get the Element for setting focus. But was trying to use a function that wasn't specific to a particular field.
MetalAsp.Net
All-Star
112032 Points
18231 Posts
Moderator
Re: Add Attribitutes
Feb 17, 2012 05:12 PM|LINK
No I mean inside the hookonfocus function use currentcontrol.findcontrol("textbox1") and cast that to textbox. Now you can do stuff on it. Something like that.
sarndt
Member
72 Points
33 Posts
Re: Add Attribitutes
Feb 17, 2012 05:27 PM|LINK
Problem is - I don't know what the control is. I was basically trying to pass the page as a control to the function that would then based on the type of control do the following:
CurrentControl.Attributes.Add("onfocus", "try{document.getElementById('__LASTFOCUS').value=this.id} catch(e) {}")
And then recursively go thru the children to see if I need to setfocus on one of the children...
But I can't get pass the attributes.add statement do the the Currentcontrol being a control - not a webcontrol.
srinanthuram
Contributor
6800 Points
1549 Posts
Re: Add Attribitutes
Feb 17, 2012 05:57 PM|LINK
hi
pls see this url
http://stackoverflow.com/questions/7794563/add-to-onfocus-codebehind-without-deleting-current-onfocus
thank u
Hua-Jun Li -...
All-Star
75950 Points
5608 Posts
Re: Add Attribitutes
Feb 20, 2012 03:52 AM|LINK
Hi,
The "attributes" property come from the webcontrol, other asp.net server conrol inherit the webcontrol to gain the property.
You can check the current type is compatiable with the webcontrol, if so, you can use the "attribtes.add" method for the current type.
if(Currentcontrol.GetType() is webcontrol)
{
}
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
rossisdead2
Participant
1313 Points
300 Posts
Re: Add Attribitutes
Feb 21, 2012 08:47 PM|LINK
"Currentcontrol.GetType() is webcontrol)" would never be true, since a Type instance is not an instance of WebControl.