Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Javascript not firing on a link button - even though it is there.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tshad - 04 Mar 2008 01:30 GMT
Using VS 2005, I have the following linkbutton:

<asp:LinkButton ID="lnkSendEmail" runat="server" Text="Send Email"
CssClass="cssbutton"
                Width="165px" OnClick="lnkSendEmail_Click"
CausesValidation="False" />

I want to add a Javascript to it so I do the following in my Page_Load
(!IsPostBack) event:

                   lnkSendEmail.OnClientClick = "Email(this);";

Here is the code that is rendered:

<a onclick="Email(this);" id="ctl00_mContentPlaceHolder_lnkSendEmail"
   class="cssbutton"
href="javascript:__doPostBack('ctl00$mContentPlaceHolder$lnkSendEmail','')"
   style="display:inline-block;width:165px;">Send Email</a>

So the onclick is there, but it never gets done - I assume because of the
postback, but not sure.

How would I fix this to do this javascript?

Thanks,

Tom
Mark Rae [MVP] - 04 Mar 2008 10:01 GMT
> So the onclick is there, but it never gets done - I assume because of the
> postback, but not sure.
>
> How would I fix this to do this javascript?

Firstly, are you absolutely sure that the script "never gets done"...? If
you put a breakpoint (or use the debugger; method) in the JavaScript
function, does execution pause as expected...?

If not, are you absolutely sure that the Email method is available to the
page once it's been rendered to the browser, i.e. can the hyperlink "see"
the Email method...? An easy way to check is to do this:
lnkSendEmail.OnClientClick = "alert('Hello');"; If that works, then you have
almost certainly put the JavaScript method / file in the wrong location...

Finally, might you have accidentally turned JavaScript off...?

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Michael Nemtsev [MVP] - 04 Mar 2008 10:02 GMT
Hello tshad,

And where is your JS code?
Seems that you miss your implementation. Because if u put the following code
on the page the "Hi" message box is shown when u click the linkButton

<script type="text/javascript">
   function Email()
   {
       alert('hi');
   }
</script>

---
WBR,
Michael  Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour 

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

t> Using VS 2005, I have the following linkbutton:
t>
t> <asp:LinkButton ID="lnkSendEmail" runat="server" Text="Send Email"
t> CssClass="cssbutton"
t> Width="165px" OnClick="lnkSendEmail_Click"
t> CausesValidation="False" />
t> I want to add a Javascript to it so I do the following in my
t> Page_Load (!IsPostBack) event:
t>
t> lnkSendEmail.OnClientClick = "Email(this);";
t>
t> Here is the code that is rendered:
t>
t> <a onclick="Email(this);" id="ctl00_mContentPlaceHolder_lnkSendEmail"
t> class="cssbutton"
t> href="javascript:__doPostBack('ctl00$mContentPlaceHolder$lnkSendEmail
t> ','')"
t> style="display:inline-block;width:165px;">Send Email</a>
t> So the onclick is there, but it never gets done - I assume because of
t> the postback, but not sure.
t>
t> How would I fix this to do this javascript?
t>
t> Thanks,
t>
t> Tom
t>
tshad - 04 Mar 2008 19:02 GMT
> Hello tshad,
>
> And where is your JS code?

Duhhh.

That was the problem.

The <style> line accidently got deleted when I was doing some undos.

Thanks,

Tom
> Seems that you miss your implementation. Because if u put the following
> code on the page the "Hi" message box is shown when u click the linkButton
[quoted text clipped - 33 lines]
> t> t> Tom
> t>

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.