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

How to call server side function for client side JavaScript?

I want to call a server-side function, like a button's click event, from a
client-side JavaScript function. How do I do that? Thanks.
Nov 19 '05 #1
3 15491
JV
In order to call server-side code you have to post back to the web server.
If you examine the HTML that is generated on a simple web page with a
button, you will get a pretty good idea how to do that. It's just calling a
javascript that ASP.NET automatically generates in your web page.
"lanem" <la***@discussions.microsoft.com> wrote
I want to call a server-side function, like a button's click event, from a
client-side JavaScript function. How do I do that? Thanks.

Nov 19 '05 #2
Do you mean you want to fire a server-side event?

Eliyahu

"lanem" <la***@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
I want to call a server-side function, like a button's click event, from a
client-side JavaScript function. How do I do that? Thanks.

Nov 19 '05 #3
Lanem:
Your question is a little vague..if you just want to dynamically trigger a
postback, you can use the __doPostback function:

<asp:button id="x" runat="server" />
<a href="javascript:__doPostBack('x', '');">hahah I'm sooo clever!</a>

If you only have Buttons and no LinkButtons or other controls which require
__doPostBack, you'll have to trick the page into generating the Javascript
for you (button's don't need javascript)...you can use
Page.GetPostBackClientEvent(x, ""); where x is the id of the button
control.

the above <a tag will cause x's click event to fire in codebehind.

If you want to fire server-side code without generating a postback, you'll
need to look at XmlHTTP, here's a good link dump:
http://www.quirksmode.org/blog/archi...p_linkdum.html
Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"lanem" <la***@discussions.microsoft.com> wrote in message
news:A2**********************************@microsof t.com...
I want to call a server-side function, like a button's click event, from a
client-side JavaScript function. How do I do that? Thanks.

Nov 19 '05 #4

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

Similar topics

12
by: HarveyB | last post by:
I would like to generate non-modal popup windows from ASP.Net code-behind. I have tried using Client Side scripting like "function Test(){ window.open('test.htm',_blank,...
1
by: cheezebeetle | last post by:
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when...
1
by: Mike Moore | last post by:
Can an asp.net button that is a server side control call a client side java function when the button is clicked? If so, please provide example.....thanks.,
3
by: David Shorthouse | last post by:
Hey folks, Not an off-topic posting.....since I was shot-down in an earlier post...this one's legit. How do I go about calling a server-side vbscript within a client-side javascript function?...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
1
by: prince -=nore=- | last post by:
I'm trying to open a new window when a button is clicked. I'm using the following code in my page_load to do so. Dim myScript As String = "<script language=javascript> function loadWin()...
4
by: abcd | last post by:
I am novice asp.net programmer. I have xyz.js file which has resuable functions. I have asp.net form abcd.aspx and the code behind file abcd.aspx.cs, I want to put a 'Help' button when clicked...
19
by: thisis | last post by:
Hi All, i have this.asp page: <script type="text/vbscript"> Function myFunc(val1ok, val2ok) ' do something ok myFunc = " return something ok" End Function </script>
0
AnuSumesh
by: AnuSumesh | last post by:
Hi All, I am trying to call RDP on click of link. 'n' I am using following code to do this: <script language="javascript"> function setip(ip) { var wshell;
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.