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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capature JavaScript function Call

Status
Not open for further replies.

Caradog

Programmer
Jun 28, 2000
73
GB
I have some code written to a litteral sometihng like this:

strHTML.Append("<a href=""JavaScript:catchClick(1);"">LINK</a>")

Is there a way I can programmatically catch that JavaScript call to a function in the .vb page and do some stuff with it?
 
You could redirect the user (in the javascript function) and add a querystring variable to indicate that the page has been loaded because of the call to the javascript function (you just check for the querstring on your Page_Load). e.g. something like:

Code:
self.parent.location= "MyCall.asp?FromJavascript=T"

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Yeah, I think that'll work, thanks!

Is there anyway progmarically I can do this in vb.net? Such as populating the litteral with a vb click event which triggers a set procedure in the code behind? Basically I mean just someway to capture an event (besides using JS).
 
If you are just looking to create something that lets you click it why are you using a literal control?

You could simply create a button or a linkbutton etc...

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
I usualy use a datalist populted by my sproc and then use the CommandName and CommandValue options to pass the info I need into the datalist_itemcommand procedure in the code behind, but in this case I have a recursive call to create the data I want to display, basically a list of categories like this:

cat1
------>cat1.1
------------>cat1.1.1
------------>cat1.1.2
cat2
------>cat2.1
...and so on.

I've not found a way to bind that kind of view to a datalist or datagrid (at least not in a formatted way). I want each cat name to be a link which is captured by VB, in the datalist case that would be in the _ItemCommand procedure.

So, for now I am using a literal populated by HTML generated by my recursive procdure to display the categories in teh format above. I dont mind having to refresh the page (by passing a var in the QS as suggested), but I'm trying not to lose state as I have previous panels on the page which have data in a form I want to retain...
 
There is no click event associated with a literal control so the only way to do it would be add another control next to your literal control (or only have a Button or LinkButton).

I would suggest using a LinkButton instead of your literal control as you can set the text property to be whatever you want (i.e. you can include your HTML formatted text so it appears in the format you stated above) and it has an click event associated with it.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top