Functions executing on Page Load?

C

cider123

Here's a quick snapshot of the top few lines of the aspx page:

<%@ Page Language="C#" MasterPageFile="~/Master1.master"
AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="TestPage"
Title="Test Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cpMain"
Runat="Server">
<script type="text/javascript">
function fnOpen(){
<%
DoSomething();
%>
}
</script>
<table style="width: 100%">
....



I have the function calling a code behind routine, and that works just
fine when I want it to (button click on form).

I was puzzled at first, thinking the button was getting triggered on
page load.. but I removed all references, searched the project and no
other references to "fnOpen()" exist except this snapshot you see
above.

Ideally it should never fire because nothing is calling it. However,
it fires every time the page is loaded.

How do you make it so the function is only executed when you click the
button?

I'm working with ASP.NET 2.0 in Visual Studio 2005.


The only place it exists is in this one Web Form I have in the project.
 
S

Shawn

Why do you want to trigger a javascript that triggers a code behind method
when clicking on a button? Can't you just set the code behind method you
wish to call in the button's onClick event, like this:
<asp:button id="testButton" runat="server" onClick="DoSomething" />

Then in your code behind you declare the method like this:
Protected Sub DoSomething(ByVal sender As Object, ByVal e As
System.EventArgs)
...
End Sub


Shawn

Here's a quick snapshot of the top few lines of the aspx page:

<%@ Page Language="C#" MasterPageFile="~/Master1.master"
AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="TestPage"
Title="Test Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cpMain"
Runat="Server">
<script type="text/javascript">
function fnOpen(){
<%
DoSomething();
%>
}
</script>
<table style="width: 100%">
....



I have the function calling a code behind routine, and that works just
fine when I want it to (button click on form).

I was puzzled at first, thinking the button was getting triggered on
page load.. but I removed all references, searched the project and no
other references to "fnOpen()" exist except this snapshot you see
above.

Ideally it should never fire because nothing is calling it. However,
it fires every time the page is loaded.

How do you make it so the function is only executed when you click the
button?

I'm working with ASP.NET 2.0 in Visual Studio 2005.


The only place it exists is in this one Web Form I have in the project.
 
C

cider123

What I was attempting to do was pop a window based on results in
Profile values and so forth. In the code behind I was executing some
stored procedures and getting values, based on what returned I was
going to pop any number of different types of windows. The only way I
discovered (at the time) to do this was through a javascript openwindow
call.

I eventually decided to just roll the results to a new page instead of
popping a window, by using the Response.Redirect. Works just as well I
suppose.
 

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,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top