Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Raise Postbacks from Hyperlink

Status
Not open for further replies.

henna

Technical User
Dec 18, 2002
23
0
0
NZ
Hi,

I have a web page which dynamically creates some hyperlinks using the Response.Write("<a href='thispage.aspx?passData=12345'>some link</a>");.

How can I add event handlers to these links which does postbacks after they have been rendered to the page.

Please help.
 
Use a linkbutton for that.
<ASP:LinkButton Onclick="Link_OnClick" >Click Here</ASP:LinkButton>


If you add them dynamically you will have to add them on page_load or page_init each time the page is requested
for the event to fire.
It is better to create one during design time and just turn it's visible to false when you are not using it.
 
AS RTomes pointed out, you should always use controls if you want to write out to the page (Response.Write should only be used when testing).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
>>Response.Write should only be used when testing.

but isnt it faster writing a string rather than building a control (i use response.write to build simple links, not LiteralControls)...

Known is handfull, Unknown is worldfull
 
It's maybe faster but it's bad programming!


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
why???

Known is handfull, Unknown is worldfull
 
The ASP.NET rendering process takes place after the Response.Write would, you have no control over where the data is written to on the page
 
when u dont want to place it inbetween controls? e.g.:
response.write("<script></script>")
not the inbuilt .net method, but as such there is no restricition as to where a script tag can appear...

Known is handfull, Unknown is worldfull
 
but as such there is no restricition as to where a script tag can appear...
The script tags will write out before the <html> tags. Even though your browser will recognise the script tags it is not in the correct place according to HTML standards and is therefore bad programming practice.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
The time difference if any can't be a few milliseconds. This negligible in broad scheme of things. Focus on structure and maintainability. There is no sense in using .net if are doing things that way. Controls do not post back in .Net if are just writing them as literals to the page.
 
thanks for the info. i thought literal controls participate in view state...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top