473,403 Members | 2,071 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,403 software developers and data experts.

Firing JavaScript methods from code behind

Jim
Group,

How would I go about firing a JavaScript method from a C# method in the aspx code behind file? It seems as though this could not be done since JavaScript is executed from within the Web browser and C# is executed on the server.

Thanks for your consideration,
Jim
Nov 18 '05 #1
6 4488
You are correct. But, you can add some conditions to your code-behind that
will output the correct JavaScript calls so that when the page renders, it
can run your code.

"Jim" <Ji*@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
Group,

How would I go about firing a JavaScript method from a C# method in the aspx code behind file? It seems as though this could not be done since
JavaScript is executed from within the Web browser and C# is executed on the
server.
Thanks for your consideration,
Jim

Nov 18 '05 #2
One solution is to add an JavaScript onLoad event to the BodyTag of the Page. This gets messy quickly as you have to get rid of the onLoad as the page posts-back or it will keep firing repeatedly.

Best practice is try to not mix the two contexts. Coordinating the form submit, client side JavaScript, .NET's own JavaScript that it renders with certain controls, and server side page processing is dicey at best. Try to keep it simple and use multiple pages or something unless the boss demands that it "pop-up" just so...

Andyz MCSD.NET
"Peter Rilling" wrote:
You are correct. But, you can add some conditions to your code-behind that
will output the correct JavaScript calls so that when the page renders, it
can run your code.

"Jim" <Ji*@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
Group,

How would I go about firing a JavaScript method from a C# method in the

aspx code behind file? It seems as though this could not be done since
JavaScript is executed from within the Web browser and C# is executed on the
server.

Thanks for your consideration,
Jim


Nov 18 '05 #3
Strongly disagree with the last paragraph. It's impossible to make a fast
ASP.NET application without good deal of client scripting and client-server
coordination.

Eliyahu

"Andy Z Smith" <An********@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.com...
One solution is to add an JavaScript onLoad event to the BodyTag of the Page. This gets messy quickly as you have to get rid of the onLoad as the
page posts-back or it will keep firing repeatedly.
Best practice is try to not mix the two contexts. Coordinating the form submit, client side JavaScript, .NET's own JavaScript that it renders with
certain controls, and server side page processing is dicey at best. Try to
keep it simple and use multiple pages or something unless the boss demands
that it "pop-up" just so...
Andyz MCSD.NET
"Peter Rilling" wrote:
You are correct. But, you can add some conditions to your code-behind that will output the correct JavaScript calls so that when the page renders, it can run your code.

"Jim" <Ji*@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
Group,

How would I go about firing a JavaScript method from a C# method in
the aspx code behind file? It seems as though this could not be done since
JavaScript is executed from within the Web browser and C# is executed on the server.

Thanks for your consideration,
Jim


Nov 18 '05 #4
I agree with you, but I beg to differ. Take a quick look at a public domain solution to the pop-up calendar problem.

REF: http://www.csharphelp.com/archives3/archive563.html
This author has made a pretty good use of the coordination between contexts. But, as you notice, and not horrendously, but he is already using the __doPostBack functions. I urge you to find the Microsoft documentation that references this function publicly. I think that going deep into those .NET internal functions is just asking for trouble as the framework is enhanced and changed and your code breaks due to "__DoPostBack" being deprecated.

I agree the "power" apps are going to push the limits and use all kinds of techniques to achieve the desired effect. I think the compromise must be made between development time, functionality and future compatibility/maintainability.

My bet is on using what Microsoft has provided (namely CodeBehind) which allows for an Object Oriented view of an inherently 'chatty' client-server browser based application.

Andrew
"Eliyahu Goldin" wrote:
Strongly disagree with the last paragraph. It's impossible to make a fast
ASP.NET application without good deal of client scripting and client-server
coordination.

Eliyahu

"Andy Z Smith" <An********@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.com...
One solution is to add an JavaScript onLoad event to the BodyTag of the

Page. This gets messy quickly as you have to get rid of the onLoad as the
page posts-back or it will keep firing repeatedly.

Best practice is try to not mix the two contexts. Coordinating the form

submit, client side JavaScript, .NET's own JavaScript that it renders with
certain controls, and server side page processing is dicey at best. Try to
keep it simple and use multiple pages or something unless the boss demands
that it "pop-up" just so...

Andyz MCSD.NET
"Peter Rilling" wrote:
You are correct. But, you can add some conditions to your code-behind that will output the correct JavaScript calls so that when the page renders, it can run your code.

"Jim" <Ji*@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
> Group,
>
> How would I go about firing a JavaScript method from a C# method in the aspx code behind file? It seems as though this could not be done since
JavaScript is executed from within the Web browser and C# is executed on the server.
>
> Thanks for your consideration,
> Jim


Nov 18 '05 #5
Notice that changes in the framework are making these kinds of tricks unnecessary and true to form, the __DoPostBack was changed in 1.1 causing some kind of problem...
http://weblogs.asp.net/vga/archive/2...InWhidbey.aspx

http://devhawk.net/art_submitfirefixup.aspx

Andrew S.
"Andy Z Smith" wrote:
I agree with you, but I beg to differ. Take a quick look at a public domain solution to the pop-up calendar problem.

REF: http://www.csharphelp.com/archives3/archive563.html
This author has made a pretty good use of the coordination between contexts. But, as you notice, and not horrendously, but he is already using the __doPostBack functions. I urge you to find the Microsoft documentation that references this function publicly. I think that going deep into those .NET internal functions is just asking for trouble as the framework is enhanced and changed and your code breaks due to "__DoPostBack" being deprecated.

I agree the "power" apps are going to push the limits and use all kinds of techniques to achieve the desired effect. I think the compromise must be made between development time, functionality and future compatibility/maintainability.

My bet is on using what Microsoft has provided (namely CodeBehind) which allows for an Object Oriented view of an inherently 'chatty' client-server browser based application.

Andrew
"Eliyahu Goldin" wrote:
Strongly disagree with the last paragraph. It's impossible to make a fast
ASP.NET application without good deal of client scripting and client-server
coordination.

Eliyahu

"Andy Z Smith" <An********@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.com...
One solution is to add an JavaScript onLoad event to the BodyTag of the

Page. This gets messy quickly as you have to get rid of the onLoad as the
page posts-back or it will keep firing repeatedly.

Best practice is try to not mix the two contexts. Coordinating the form

submit, client side JavaScript, .NET's own JavaScript that it renders with
certain controls, and server side page processing is dicey at best. Try to
keep it simple and use multiple pages or something unless the boss demands
that it "pop-up" just so...

Andyz MCSD.NET
"Peter Rilling" wrote:

> You are correct. But, you can add some conditions to your code-behind

that
> will output the correct JavaScript calls so that when the page renders,

it
> can run your code.
>
> "Jim" <Ji*@discussions.microsoft.com> wrote in message
> news:46**********************************@microsof t.com...
> > Group,
> >
> > How would I go about firing a JavaScript method from a C# method in

the
> aspx code behind file? It seems as though this could not be done since
> JavaScript is executed from within the Web browser and C# is executed on

the
> server.
> >
> > Thanks for your consideration,
> > Jim
>
>
>


Nov 18 '05 #6
Andrew,

I agree with you, one should avoid hacker-style programming. I actually
never use __doPostBack. My ASP.NET experience started from writing a few
heavily server- and code behind-oriented applications. They were slow and
GUI was bad. That was due to lack of experience with client side and clear
understanding client-server coordination. Now I tend to load the client-side
with more and more tasks. My client-side is evolving from just a set of
separate scripts to a design layer with its own infrastructure. The improve
is dramatic. My web apps are comparable to window forms ones in speed and
more attractive in GUI. The development indeed takes longer, but I am sure
the development tools for client side will improve.

Happy programming,

Eliyahu
"Andy Z Smith" <An********@discussions.microsoft.com> wrote in message
news:B4**********************************@microsof t.com...
I agree with you, but I beg to differ. Take a quick look at a public domain solution to the pop-up calendar problem.
REF: http://www.csharphelp.com/archives3/archive563.html
This author has made a pretty good use of the coordination between contexts. But, as you notice, and not horrendously, but he is already using
the __doPostBack functions. I urge you to find the Microsoft documentation
that references this function publicly. I think that going deep into those
..NET internal functions is just asking for trouble as the framework is
enhanced and changed and your code breaks due to "__DoPostBack" being
deprecated.
I agree the "power" apps are going to push the limits and use all kinds of techniques to achieve the desired effect. I think the compromise must be
made between development time, functionality and future
compatibility/maintainability.
My bet is on using what Microsoft has provided (namely CodeBehind) which allows for an Object Oriented view of an inherently 'chatty' client-server
browser based application.
Andrew
"Eliyahu Goldin" wrote:
Strongly disagree with the last paragraph. It's impossible to make a fast ASP.NET application without good deal of client scripting and client-server coordination.

Eliyahu

"Andy Z Smith" <An********@discussions.microsoft.com> wrote in message
news:8E**********************************@microsof t.com...
One solution is to add an JavaScript onLoad event to the BodyTag of the
Page. This gets messy quickly as you have to get rid of the onLoad as the page posts-back or it will keep firing repeatedly.

Best practice is try to not mix the two contexts. Coordinating the
form submit, client side JavaScript, .NET's own JavaScript that it renders with certain controls, and server side page processing is dicey at best. Try to keep it simple and use multiple pages or something unless the boss demands that it "pop-up" just so...

Andyz MCSD.NET
"Peter Rilling" wrote:

> You are correct. But, you can add some conditions to your
code-behind that
> will output the correct JavaScript calls so that when the page
renders, it
> can run your code.
>
> "Jim" <Ji*@discussions.microsoft.com> wrote in message
> news:46**********************************@microsof t.com...
> > Group,
> >
> > How would I go about firing a JavaScript method from a C# method
in the
> aspx code behind file? It seems as though this could not be done
since > JavaScript is executed from within the Web browser and C# is

executed on the
> server.
> >
> > Thanks for your consideration,
> > Jim
>
>
>


Nov 18 '05 #7

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

Similar topics

6
by: Rod Snyder | last post by:
I'm trying to set up a page with an asp.net link button that would send a user to a certain page and on page load execute a specific stored procedure tied to the button on the previous page. The...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
13
by: Chris | last post by:
I can create Javascript confirm message boxes during page creation, etc adding them to the button attributes (many good posts on this!). But how can I add this event after the button is pressed? I...
1
by: Paul L | last post by:
Hi, I have an issue with the OnSelectedIndexChanged event not firing for a DropDownList control which is in the ItemTemplate of a DataList. I have made an exact copy of the DropDownList control,...
8
by: Frank | last post by:
Hi, I am working with VS.NET 2005 Ultimately, I wish to call a JavaScript function from a .js file
3
by: Jay | last post by:
I am on the 2.0 framework and have run the c:\windows\microsoft.net \framework\v1.1.4322\aspnet_regiis.exe -c and had no success. About half of the buttons on my webforms are firing and the other...
2
by: NvrBst | last post by:
Hello. I posted this problem in the microsoft.public.dotnet.languages.csharp origionally but moving it here since I think it probably belongs here now. I have a blank ASP.NET/C# page with a...
6
Frinavale
by: Frinavale | last post by:
Apparently I have a lot of questions today regarding JavaScript security. I've implemented a JavaScript Object that intercepts page submits (postbacks) and then displays a UI prompting the user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.