Onclientclick firing twice?

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

<script language=javascript>
function selectFile(fileUrl)
{
if(navigator.appName.indexOf('Microsoft')!=-1)
window.returnValue=fileUrl;
else
window.opener.setAssetValue(fileUrl);
self.close();
}
</script>


<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server"
OnClientClick="selectFile('blabla')" Text="Button" />

When I run this code for some reason, it seems to do it twice. Also,
the first time I press the button the window is still open, but the
second time I press the button it correctly closes the window.

Any idea what is going on?

Also do you know the syntax of how I can pass the parameter of the text
in textbox1 instead of the 'blabla' to the javascript function?
 
Generally when an event fires twices it's because an event handler is
registered twice. Maybe you have it registered both in the code behind and
the html?
 
Use an HTML button, not an asp.net ?

Rick said:
Generally when an event fires twices it's because an event handler is
registered twice. Maybe you have it registered both in the code behind and
the html?
 
Since you are using C# I would double check where the designer hooks the
events.
I have seen it subscribe twice to an event due to manual deletion and
recreation of buttons.
I had the same problem a year or so ago.

HTH

SA
 
Back
Top