Click to See Complete Forum and Search --> : Calling functions on "onclick"
caodocil
03-29-2007, 06:40 PM
On my site, i show content (links and pics) from a sql server. And i need to, when a user clicks, open a pop-up and add a new row to the db containing the clicked link and info about who clicked it.
Function clickonlink(ByVal link As String) As String
'does the insert
I m using to open the popup:
dim htmlstrlinkimg as new stringbuilder
(...)
htmlStrlinkimg.Append("<td>")
htmlStrlinkimg.Append("<a href=""")
htmlStrlinkimg.Append(reader.GetString(2))
htmlStrlinkimg.Append(""" onclick="" newWin(this.href,855,400,'yes','no','no','no','no','250','250'); return false; "">")
My question is:
How do i call both functions on onclick ?
If i put the pop up on a function the "this.href" dont work....
lmf232s
03-30-2007, 08:44 AM
caodocil,
Are you using that code to open the new window from the code behind?
Or are you creating the string with that code and then displaying it on the page for the user to click on?
You might want to use an <asp:Linkbutton> tag for what your doing. This way you can call both a client side function and a code behind function.
This is in theory and i have not tested it but i see it going like this.
<asp:Linkbutton id="lnkPopup" runat="server" onclick="clickonlink('link')" onclientclick="newWin('your info')"/>
Depending on your situation you could also pass in a value through the query string and then on the page load of the new window call your clickonlink function and request the raw url and do the insert there as well.
caodocil
04-01-2007, 11:34 AM
It's Working! Thank you very much ! :)
caodocil
04-02-2007, 06:58 PM
Sorry, but with
<asp:Linkbutton id="lnkPopup" runat="server" onclick="clickonlink('link')" onclientclick="newWin('your info')"/>
only onclientclick code is executed.
it's there some way around this ?
Cstick
04-02-2007, 10:03 PM
I don't know if this is way off track, but maybe it'll give you some ideas.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
/*<!--*/
window.onload = function() {
var links = document.getElementsByTagName("a");
for (var idx = 0; idx < links.length; idx++) {
if (links[idx].className == "link") {
var old = (links[idx].onclick) ? links[idx].onclick : function () {};
links[idx].onclick = function () {old(); setHid(this);};
}
}
}
function setHid(o) {
document.getElementById("hid").value = o.href;
document.forms[0].hid.submit();
}
//-->
</script>
<script runat="server">
private sub page_load(sender as object, e as eventargs) handles mybase.load
If Me.IsPostBack Then
response.write(hid.value)
response.write(request.browser.browser)
End If
end sub
</script>
</head>
<body>
<form runat="server">
<input type="hidden" id="hid" runat="server" />
<a href="http://www.webdeveloper.com" class="link" target="_blank" onclick="alert('blah');">webdeveloper.com</a>
</form>
</body>
</html>