ASP:HyperLink control and client-side scripting

B

Brian W

Hi All,

I know this is a dumb question, but I'll ask it anyway...

How do you do client-side scripting with an ASP control?

For example I have:

<asp:hyperlink id="Hyperlink1" runat="server" NavigateUrl="~/"
onclick="return false;">Home</asp:hyperlink>

When I run this it works as expected, except the IDE sees it as and error.

I know I can add the attribute in the codebehind, but is this possible in
the HTML designer side?

TIA
Brian W
 
B

bruce barker

not with the webcontrol controls, as asp.net assumes these are postback
events

-- bruce (sqlwork.com)
 
S

Steven Cheng[MSFT]

Hi Brain,


Thanks for posting in the community!
As for your question that "whether possible to add client side attributes
in the ASP.NET server control's html source(aspx page)", I agree with bruce
that we can only specify the Server control's specified attributes in its
tag such as
<asp:Button...> <asp:Label ...> ..
In fact, when the asp.net runtime parsing the aspx page, it'll parse the
asp.net server controls( not html server controls) according to its class
in framework, and these classes has their buildin attributes which are
quite different from html element's attributes( only for serverside code's
controling). The runtime construct a server control's instance via the
attribuets and finally render it out to client via some certain mapping
(from these attributes to the proper html element attributes). So we can't
add clientside used attributes in ASP.NET server control's source template
in aspx page(html view). One way to do this is via their' "Attributes"
collection in code behind as you've mentioned. If you do want to add
clientside attributes in aspx file(html view), I think you can try using
the HtmlServerControls instead, because they're directly mapping to html
element. Do you think so?

In addition, here are some tech ariticles on the ASP.NET servercontrols and
html server controls:

#ASP.NET Server Controls Recommendations
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbconchoosingwebformscontrols.asp

#ASP.NET Server Controls and Browser Capabilities
http://msdn.microsoft.com/library/en-us/vbcon/html/vbconWebFormsControlsBrow
serCapabilities.asp?frame=true

#HTML Server Controls
http://msdn.microsoft.com/library/en-us/cpgenref/html/cpconASPSyntaxForHTMLC
ontrols.asp?frame=true

#The Forgotten Controls: HTML Server Controls
http://msdn.microsoft.com/library/en-us/dnaspp/html/ASPNet-ForgottenControls
.asp?frame=true

Hope these also helpful.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top