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

Object.Click?

Status
Not open for further replies.

ThatRickGuy

Programmer
Oct 12, 2001
3,841
US
Hey Guys, I'm having a problem with an ASP.Net page, but it sounds like the issue is in the JavaScript.

Here is a super stripped down sample:

In the code behind page:
Code:
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
  'I'm running this local on my dev box, so I see this
  'messagebox when I click on the image button directly
  MsgBox("Button Clicked, backend")
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  Me.Button1.Attributes.Add("onclick", "alert('button1 clicked'); document.getElementById('ImageButton1').click;")
End Sub

HTML:
Code:
<form id="Form1" runat="server" >
  <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="Images/btn_Upload.PNG" />
  <asp:Button ID="Button1" runat="server" Text="Button" />     
</form>

It appears that the JavaScript object.Click() method is not actually causing a PostBack, it is just calling what ever JavaScript is associated with the client side click event.

Anyone know how to get around that?

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Hey rick, can you post some of the client-side code? You're not speaking our language with all of the postback stuff, that's more in the ASP.Net realm, of which I know 0% about....

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
Ahh nevermind, I'm being dumb.

I was using:
Code:
document.getElementById('bsibPlay').click();

But I forgot that ASP.Net name mangles controls when you have multiple objects with the same name loaded, so I had to change it to:

Code:
document.getElementById('WucAudio1$bsibPlay').click();

So it's back to the drawing board for now.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Glad I could help [thumbsup2]

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
Each control has a ClientID property you can use to find what the mangled version will be.
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  Me.Button1.Attributes.Add("onclick", "alert('button1 clicked'); document.getElementById('[b]" & Me.ImageButton1.ClientID & "[/b]').click[red]()[/red];")
End Sub

Adam
 
Yup, that's what I wound up doing. Finally got the whole thing to work this morning! All my sound functionality wrapped up in one nice little user control that I just have to set the sound source for!

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top