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

cancelbubble in asp code

Status
Not open for further replies.

nivini

Programmer
Mar 24, 2004
64
Hi all
I have this code, It has rows of textboxex and a button in each row, The button is to delete the row (the record).
And 3 buttons to add differrent kind of rows (records).
Now, no matter what button i press all events happens.
I tryed to add the
window.event.cancellbubble=true
to all buttons but it didnt help.
please take a look at the code, and find out what i cant find out
Thank you all expert in advance

here it is:
Code:
<%@ Language=VBScript %>
<%



conStr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ="
DSNName=conStr & server.MapPath("/db/news.mdb")
strSql="select * FROM tblnews"
set rs=server.CreateObject("adodb.recordset")
set con =server.CreateObject ("adodb.connection")
con.Open DSNName

function addArticle()

strSql="INSERT INTO tblNews (code,articleHeader,articlePath) VALUES(3,'tryTOAddArticle','2.doc')"
con.Execute strsql
end function

function AddProtocol()
end function

function AddEvent()
end function

function DEL(num)
strSql="DELETE FROM tblNews WHERE id="&num
con.Execute strSql
end function
%>
<html>

<body>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255" dir="rtl">
	<title></title>
	
</HEAD>

<div align="center">

<b><font size="5">MANAGMENT</font></b><br>

<div align=center>

<form method="Post"  id=form1 name=form1 onclick=window.event.cancelbubble=true  >

<%
rs.Open strSql,con,3,3
dim i
i=0
if not rs.EOF then
	while not rs.EOF 
		i=i+1
		Response.Write "<input type='text' value='"&rs("articleHeader")&"'  name='Header"&i&"'  id='Header"&i&"' >"
		Response.Write "<input type='text' value='"&rs("articlePath")&"'  name='Path"&i&"'  id='Path"&i&"' >"
		response.Write "<input type='button' value='ERASE' name='"&rs("id")&"  id='"&rs("id")&"' onclick='"&DEL(rs("id"))&"; window.event.cancelbubble=true;' language='javascript'>"
		rs.MoveNext 
		Response.Write "<br>"
		Response.Write "<br>"
	wend
end if

		Response.Write "<input type='button' value='ADD PROTOKOL' name='Protocol'  id='Protocol' onclick='"&AddProtocol()&" ;window.event.cancelbubble=true;' language='javascript'>"

		Response.Write "<input type='button' value='ADD EVENT' name='event'  id='event'  onclick='"&addEvent()&" ;window.event.cancelbubble=true;' language='javascript'>"

		Response.Write "<input type='button' value='ADD ARTICLE' name='article'  id='article' onclick='"&addArticle()&";window.event.cancelbubble=true;' language='javascript'>"

%>


</form>
</div>
</body>
</html>
 
> no matter what button i press all events happens.
The problem is not event being bubbling up, it is the confusion of assigning client-side function to server-side functionality. In fact, even before (any of) the buttons clicked, the server-side functions are already executed "once" before the page is rendered. Look at renderment of the page (on the client browser) by view-source. You won't see any trace of any of the functions, addArticle() or AddProtocol() or..., any of them.
 
Thank you tsuji for inlightining the inlighted to all, but me.
 
What he is saying is that the asp part of it (the server side) happens before the rest. so the client (the web browser) never sees the bits in <%%> So the javascript has notning to interact with.
To delete or add to the database you need to submit the form and process it on the server as asp.

Not sure that explains it very well.

The javascript never sees the ASP that is the bit about rendering. The server creates a static html page based on the asp.

}...the bane of my life!
 
Take for instance:
>[tt]response.Write "<input type='button' value='ERASE' name='"&rs("id")&" id='"&rs("id")&"' onclick='"&DEL(rs("id"))&"; window.event.cancelbubble=true;' language='javascript'>"[/tt]

Del(rs("id")) is already executed on the server in order to response.write. It is no string literal, it is the return value (which may be none). But, the "side-effect" is that it's done something on the recordset. Hence, (self-quoting);
>the server-side functions are already executed "once"
And it is this execution that you have observed and think it is due to the button-click.

I may excuse myself in case I'm mistaken because I only reason based on the script I see and some general principles of how things work. So, if you're not convinced, feel free to experiment further looking in this direction and prove me wrong.
 
Aye. If you're ever in doubt of what's happening on the Javascript side, view the source of the page in your browser: that's all the browser's Javascript interpreter has to work with. If you weren't able to get ASP to send it to the browser, then the browser can't act on it.

Remember, everything you ask the server to do, the stuff in <% %> tags, is performed in its entirety on the server first. Then the browser takes over and does everything in <script> </script> tags (and onclick's and such).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top