473,287 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Functions executing on Page Load?

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.

May 12 '06 #1
2 1273
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

<ci******@hotmail.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.com...
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.
May 13 '06 #2
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.

May 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Bryant Huang | last post by:
Hello! I would like to read in files, during run-time, which contain plain Python function definitions, and then call those functions by their string name. In other words, I'd like to read in...
4
by: chris.dunigan | last post by:
I'm looking for an example of how to execute an existing DTS­ package from an ASP (VB)script and would appreciate any and all response. ­I don't even know if it's possible Thanks - Chuck...
2
by: mart | last post by:
I am experiencing a weird problem with some buttons on my webpage. The page_load is executing twice when a button is clicked. If I replace the button for a Linkbutton the page_load only loads...
7
by: Jibey | last post by:
Hello: I'm facing a very strange problem. When I run my Web application in Visual Studio.NET the Page_Load event is not executing. Other events like a Button_Click are executing. It doesn't...
3
by: Mike | last post by:
Hi, I am trying to resize a HTML table through Javascript. When the user control loads the first time, the table is resized, but then it doesn't anymore. I am using the following code in the...
12
by: darrel | last post by:
I have a asp:dropdownlist set to autopostback. However, my handler doesn't seem to execute (even though there is a postback). Here's the DDL: <asp:dropdownlist id=ddl_districtSelect...
7
by: tshad | last post by:
I thought I understood how the SaveViewState is working and was trying to use this (as per some code I found) to detect refreshes. It seemed to be working but I found that the SaveViewState was...
2
by: rico.fabrini | last post by:
Hello Everyone, I've suddenly started running into the error "error executing child request for Page.aspx" when doing a Server.Transfer("Page.aspx"); That's on a Win2003 Server machine. ...
7
by: jphaycock | last post by:
Hi all I am calling a method in a Page_Load event that makes use of a value from a text box. Unfortunately the textbox value is only set after a javascript runs and the page is rendered....
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.