2 onlick events?

D

DC Gringo

I have a clickable image that I would like to convert into a server control
imagebutton accessing a server-side onClick event and a client-side
javascript onclick event as well. Is this possible? How can I invoke both
the client side javascript event and the server side VB?

Here's what I started with:

<A
ONMOUSEOVER="nbGroup('over','TabB','TabB_f2.gif','TabB_f3.gif',1);"
ONCLICK="nbGroup('down','navbar1','TabB','TabB_f3.gif',1);"
ONMOUSEOUT="nbGroup('out');"
HREF="default.aspx?pageID=shas">

<IMG
SRC="TabB.gif" WIDTH="217"
BORDER="0" NAME="TabB">

</A>

Here's what I'm stuck on for an equivalent imagebutton server control...also
notice that VS.NET doesn't like the onMouseOver and onMouseClick attributes.

<ASP:IMAGEBUTTON
ID="ImageButton1"
RUNAT="server"
ONMOUSEOVER="nbGroup('over','TabB','TabB_f2.gif','TabB_f3.gif',1);"
ONCLICK="nbGroup('down','navbar1','TabB','TabB_f3.gif',1);"
ONMOUSEOUT="nbGroup('out');"
IMAGEURL="TabB.gifdefault.aspx?pageID=shas">
</ASP:IMAGEBUTTON>
 
S

SevDer

DC said:
I have a clickable image that I would like to convert into a server control
imagebutton accessing a server-side onClick event and a client-side
javascript onclick event as well. Is this possible? How can I invoke both
the client side javascript event and the server side VB?

Here's what I started with:

<A
ONMOUSEOVER="nbGroup('over','TabB','TabB_f2.gif','TabB_f3.gif',1);"
ONCLICK="nbGroup('down','navbar1','TabB','TabB_f3.gif',1);"
ONMOUSEOUT="nbGroup('out');"
HREF="default.aspx?pageID=shas">

<IMG
SRC="TabB.gif" WIDTH="217"
BORDER="0" NAME="TabB">

</A>

Here's what I'm stuck on for an equivalent imagebutton server control...also
notice that VS.NET doesn't like the onMouseOver and onMouseClick attributes.

<ASP:IMAGEBUTTON
ID="ImageButton1"
RUNAT="server"
ONMOUSEOVER="nbGroup('over','TabB','TabB_f2.gif','TabB_f3.gif',1);"
ONCLICK="nbGroup('down','navbar1','TabB','TabB_f3.gif',1);"
ONMOUSEOUT="nbGroup('out');"
IMAGEURL="TabB.gifdefault.aspx?pageID=shas">
</ASP:IMAGEBUTTON>
As far as I know, this is not possible.
However you can write you script code so that, you will invoke
_doPostBack method yourself.

But I don't see the point where you will need to do that.
If you explain your point then I can help more.
 
D

DC Gringo

Ok, what I'm trying to do is maintain a rollover effect but also invoke a
servers-side Sub btn_onClick(). First problem is that VS.NET doesn't like
onMouseOver or onMouseOut as it doesn't find those attributes. Upon running
the app, the first error thrown is comilation error: 'MM_nbGroup' is not a
member of 'ASP.communities_ascx'. (my MM_nbGroup function is in a .js file
which is at the bottom for your reference:


This works (but without my server-side Sub:

<A ONCLICK="MM_nbGroup('down','navbar1','TabB','TabB_f3.gif',1);"
HREF="default.aspx?pageID=shas"><IMG HEIGHT="31" SRC="TabB.gif" WIDTH="217"
BORDER="0" NAME="TabB"></A>


Now I"m trying to move to this but getting the error mentioned above.

<ASP:IMAGEBUTTON ID="imgShasTab" NAME="TabB" RUNAT="server"
ONMOUSEOVER="MM_nbGroup('over','TabB','TabB_f2.gif','TabB_f3.gif',1);"
ONMOUSEOUT="MM_nbGroup('out');"
ONCLICK="MM_nbGroup('down','navbar1','TabB','TabB_f3.gif',1);"
IMAGEURL="TabB.gif" WIDTH="217" BORDERWIDTH="0"></ASP:IMAGEBUTTON>

Which should invoke:

Private Sub imgShasTab_Click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles imgShasTab.Click
Response.Redirect("~/advanced/default.aspx?pageID=shas")

End Sub


Here's the javascript function MM_nbGroup

function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
if (event == "init" && args.length > 2) {
if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new
Array();
nbArr[nbArr.length] = img;
for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args)) != null)
{
if (!img.MM_up) img.MM_up = img.src;
img.src = img.MM_dn = args[i+1];
nbArr[nbArr.length] = img;
} }
} else if (event == "over") {
document.MM_nbOver = nbArr = new Array();
for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args)) != null)
{
if (!img.MM_up) img.MM_up = img.src;
img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] :
img.MM_up);
nbArr[nbArr.length] = img;
}
} else if (event == "out" ) {
for (i=0; i < document.MM_nbOver.length; i++) {
img = document.MM_nbOver; img.src = (img.MM_dn) ? img.MM_dn :
img.MM_up; }
} else if (event == "down") {
nbArr = document[grpName];
if (nbArr)
for (i=0; i < nbArr.length; i++) { img=nbArr; img.src = img.MM_up;
img.MM_dn = 0; }
document[grpName] = nbArr = new Array();
for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args)) != null)
{
if (!img.MM_up) img.MM_up = img.src;
img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
nbArr[nbArr.length] = img;
} }
}
 
G

Guest

try this:

<ASP:IMAGEBUTTON ID="imgShasTab" NAME="TabB" RUNAT="server"
IMAGEURL="TabB.gif" WIDTH="217" BORDERWIDTH="0"></ASP:IMAGEBUTTON>


on the page load :
imgShasTab.attributes.add("OnMouseOver", "MM_nbGroup('whatever');")
imgShasTab.attributes.add("OnMouseOut", "MM_nbGroup('whatever');")

hope this helps..



DC Gringo said:
Ok, what I'm trying to do is maintain a rollover effect but also invoke a
servers-side Sub btn_onClick(). First problem is that VS.NET doesn't like
onMouseOver or onMouseOut as it doesn't find those attributes. Upon running
the app, the first error thrown is comilation error: 'MM_nbGroup' is not a
member of 'ASP.communities_ascx'. (my MM_nbGroup function is in a .js file
which is at the bottom for your reference:


This works (but without my server-side Sub:

<A ONCLICK="MM_nbGroup('down','navbar1','TabB','TabB_f3.gif',1);"
HREF="default.aspx?pageID=shas"><IMG HEIGHT="31" SRC="TabB.gif" WIDTH="217"
BORDER="0" NAME="TabB"></A>


Now I"m trying to move to this but getting the error mentioned above.

<ASP:IMAGEBUTTON ID="imgShasTab" NAME="TabB" RUNAT="server"
ONMOUSEOVER="MM_nbGroup('over','TabB','TabB_f2.gif','TabB_f3.gif',1);"
ONMOUSEOUT="MM_nbGroup('out');"
ONCLICK="MM_nbGroup('down','navbar1','TabB','TabB_f3.gif',1);"
IMAGEURL="TabB.gif" WIDTH="217" BORDERWIDTH="0"></ASP:IMAGEBUTTON>

Which should invoke:

Private Sub imgShasTab_Click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles imgShasTab.Click
Response.Redirect("~/advanced/default.aspx?pageID=shas")

End Sub


Here's the javascript function MM_nbGroup

function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
if (event == "init" && args.length > 2) {
if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new
Array();
nbArr[nbArr.length] = img;
for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args)) != null)
{
if (!img.MM_up) img.MM_up = img.src;
img.src = img.MM_dn = args[i+1];
nbArr[nbArr.length] = img;
} }
} else if (event == "over") {
document.MM_nbOver = nbArr = new Array();
for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args)) != null)
{
if (!img.MM_up) img.MM_up = img.src;
img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] :
img.MM_up);
nbArr[nbArr.length] = img;
}
} else if (event == "out" ) {
for (i=0; i < document.MM_nbOver.length; i++) {
img = document.MM_nbOver; img.src = (img.MM_dn) ? img.MM_dn :
img.MM_up; }
} else if (event == "down") {
nbArr = document[grpName];
if (nbArr)
for (i=0; i < nbArr.length; i++) { img=nbArr; img.src = img.MM_up;
img.MM_dn = 0; }
document[grpName] = nbArr = new Array();
for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args)) != null)
{
if (!img.MM_up) img.MM_up = img.src;
img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
nbArr[nbArr.length] = img;
} }
}
 
G

gh0st54

in the page load try

this.imgShasTab.attibutes.add("onmouseover","javascript:MM_nbGroup('over','T
abB','TabB_f2.gif','TabB_f3.gif',1);")
repeat for your other client side events

for the on click you will need to call the server side script from your
javascript
at the end of your javascript you will need to add something like

getelementbyid['__EventTarget'].value= imgShasTab
document.form.submit

what this does is it tells the page post back that the event that triggered
the post back was a click on the control imgShasTab

the thing is asp.net controls don't like "sensitive" feature that react on
the client , it's server based after all.

hope this helps



DC Gringo said:
Ok, what I'm trying to do is maintain a rollover effect but also invoke a
servers-side Sub btn_onClick(). First problem is that VS.NET doesn't like
onMouseOver or onMouseOut as it doesn't find those attributes. Upon running
the app, the first error thrown is comilation error: 'MM_nbGroup' is not a
member of 'ASP.communities_ascx'. (my MM_nbGroup function is in a .js file
which is at the bottom for your reference:


This works (but without my server-side Sub:

<A ONCLICK="MM_nbGroup('down','navbar1','TabB','TabB_f3.gif',1);"
HREF="default.aspx?pageID=shas"><IMG HEIGHT="31" SRC="TabB.gif" WIDTH="217"
BORDER="0" NAME="TabB"></A>


Now I"m trying to move to this but getting the error mentioned above.

<ASP:IMAGEBUTTON ID="imgShasTab" NAME="TabB" RUNAT="server"
ONMOUSEOVER="MM_nbGroup('over','TabB','TabB_f2.gif','TabB_f3.gif',1);"
ONMOUSEOUT="MM_nbGroup('out');"
ONCLICK="MM_nbGroup('down','navbar1','TabB','TabB_f3.gif',1);"
IMAGEURL="TabB.gif" WIDTH="217" BORDERWIDTH="0"></ASP:IMAGEBUTTON>

Which should invoke:

Private Sub imgShasTab_Click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles imgShasTab.Click
Response.Redirect("~/advanced/default.aspx?pageID=shas")

End Sub


Here's the javascript function MM_nbGroup

function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
if (event == "init" && args.length > 2) {
if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new
Array();
nbArr[nbArr.length] = img;
for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args)) != null)
{
if (!img.MM_up) img.MM_up = img.src;
img.src = img.MM_dn = args[i+1];
nbArr[nbArr.length] = img;
} }
} else if (event == "over") {
document.MM_nbOver = nbArr = new Array();
for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args)) != null)
{
if (!img.MM_up) img.MM_up = img.src;
img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] :
img.MM_up);
nbArr[nbArr.length] = img;
}
} else if (event == "out" ) {
for (i=0; i < document.MM_nbOver.length; i++) {
img = document.MM_nbOver; img.src = (img.MM_dn) ? img.MM_dn :
img.MM_up; }
} else if (event == "down") {
nbArr = document[grpName];
if (nbArr)
for (i=0; i < nbArr.length; i++) { img=nbArr; img.src = img.MM_up;
img.MM_dn = 0; }
document[grpName] = nbArr = new Array();
for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args)) != null)
{
if (!img.MM_up) img.MM_up = img.src;
img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
nbArr[nbArr.length] = img;
} }
}
 

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,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top