473,760 Members | 9,717 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to call apsx.cs mthod(C#) from javascript?

17 New Member
Any body has any idea on How to call apsx.cs mthod(C#) from javascript?

Thanks
Abdun Nabi Sk
Apr 16 '08 #1
8 5732
Mr Gray
47 New Member
Depends what you are trying to achieve?
Apr 16 '08 #2
abdunnabisk
17 New Member
can u show me some examples?

thanks..
Abdun Nabi Sk
Apr 16 '08 #3
Mr Gray
47 New Member
This is the standard bit of JScript that is in an aspx page but generally you do not send javascript to interact with methods in the cs file:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3. var theForm = document.forms['aspnetForm'];
  4. if (!theForm) {
  5.     theForm = document.aspnetForm;
  6. }
  7. function __doPostBack(eventTarget, eventArgument) {
  8.     if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
  9.         theForm.__EVENTTARGET.value = eventTarget;
  10.         theForm.__EVENTARGUMENT.value = eventArgument;
  11.         theForm.submit();
  12.     }
  13. }
  14. // -->
  15. </script>
  16.  
Apr 16 '08 #4
abdunnabisk
17 New Member
actually I am having a method name
Expand|Select|Wrap|Line Numbers
  1. public void Check(int n)
  2. {
  3. }
  4.  
in aspx.cs file.

in javascript
Expand|Select|Wrap|Line Numbers
  1. function Test(n)
  2. {
  3.   <%Check(n)%>;
  4. }
  5.  
its not calling Check() method....
There are errors like syntax

and if I dont want to send argument then no error but
every time i have to refresh the page...

can u help me

Thanks
Abdun Nabi SK
Apr 16 '08 #5
Mr Gray
47 New Member
In your case you should probably have a submit button that runs that code. In order to run cs code you need to post to the server to run that code.

So in the aspx page you should add an:

Expand|Select|Wrap|Line Numbers
  1. <asp:button id="btnSubmit" runat="server" Text="Submit" />
  2. <asp:TextBox id="txtCheck" runat="server" />
  3.  
In the cs file in the Initialise() method you can add the eventhandler for the button like so:

Expand|Select|Wrap|Line Numbers
  1. btnSubmit.Click += new EventHandler(Check);
  2.  
Then in the Check() method you created you can access the text field like so:

Expand|Select|Wrap|Line Numbers
  1. public void Check(object s, EventArgs e)
  2. {
  3.     string strCheck = txtCheck.Text;
  4.  
  5.     // operate on strCheck here
  6. }
  7.  
Hope this example will help get you started.
Apr 16 '08 #6
abdunnabisk
17 New Member
I have button that is calling
javascrip:paren t.Test(2)

method.....
anyway I have to call c# method from
javascript method Test().

please help me
thanks

Abdun Nabi Sk
Apr 16 '08 #7
Frinavale
9,735 Recognized Expert Moderator Expert
I have button that is calling
javascrip:paren t.Test(2)

method.....
anyway I have to call c# method from
javascript method Test().

please help me
thanks

Abdun Nabi Sk
You can't really use JavaScript for this.
You're going to have to use Ajax to call server side code.

Are you using Ajax in your web project currently?
If you use Ajax, the page is "partially" posted back to the server, your request is processed and that section of the page is updated.

You can use pure Ajax to do this if you want to, but .NET now has an Ajax framework that simplifies things.


Instead of putting in Ajax calls to do validation, you should consider using the client side Validator objects available to you (eg RequiredFieldVa lidator, RegularExpressi onValidator ...etc).

You should still validate on the server....I would place a call to your Check() method in your button click event and if it return's true, would allow further processing to take place.

-Frinny
Apr 16 '08 #8
antonmaju
7 New Member
I'm agree with what Frinavale said.
But if you really want to do validation via js then you may use PageMethods with ASP.NET Ajax.
Apr 18 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

15
4214
by: chirs | last post by:
I am trying to understand a piece of code. In a javascrpit file, there is a function: function ItemStyle(){ var names=; addProps(this,arguments,names,true); }; In the html file, it calls the function as:
4
361
by: Eric | last post by:
Problem: I want a table row appear to flash. How might i do this? I tried a do loop with a delay, but of course it is running on the server and the page does not get refreshed. Is there a way to do this without having to go back to the server In the exe world i would just have a thread that sleeps 500 ms, then based on the current backcolor it woud change it, this would create a flashing type view. Any ideas Thanks Eric.
4
4220
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where the server generates the HTML based on a passed in parameter. In our case, CustomerID. Every Customer ges a branded website with there logos and webpage etc.. To Avoid having 1 ASP.Net application running for each client I am attempting a more...
1
3950
by: Hong Hao | last post by:
Recently, I was trying to modify an existing aspx page when client-side validation on that page stopped working. I searched this group and the web in general and found that other people have had the same issue. However, none of the suggested fixes solved my particular problem. I tracked down the cause of the problem, which is related to aspx page parser's handling of controls inside html comments. The problem may be quite common and well...
6
1273
by: Brett | last post by:
How to I call a method within a DLL every 1 minute? The DLL (written in VB.NET) will download messages from a mail server and enter them into a database. This application is a mixture of CFMX and VB.NET. Here are two methods: 1. Allow the CFMX task scheduler to call a CF template, which then calls the DLL as an object and references some method (s) within it. 2. Create a VB.NET EXE that references the DLL and use Windows Task...
3
2044
by: Kevin Richards | last post by:
I have a .NET web service that needs to be called from any platform. I need to make the Login method of the web service secure. It doesnt matter about the remaining methods, just the password parameter of the Login call needs to be encrypted. Trying to do this platform independently seems to be difficult. I feel certificates is a bit over the top for what I am trying to acheive. Does anyone know of a way to make a single mthod of a...
3
3683
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of html is: <a class="searchsavechanges btn btn3d tbbtn" href="javascript:" style="position:static"> <div id="TBsearchsavechanges">Search</div> </a>
1
1763
by: coolsidsin | last post by:
I have a apsx form (Form A), which on submiting does a time consuming task. So i want to open a new aspx window (Form B) in which I want do do that time consuming task and show progress to the user and while that task is being completed I want Form A to redirect to Form C. I opened form B in a new javascript window and updated the progress through ajax but Form A doesn't let me redirect to Form C unless Form B's processing is Completed. ...
0
9521
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10107
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9945
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9900
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8768
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7324
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3442
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.