473,383 Members | 1,870 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,383 software developers and data experts.

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

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

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

thanks..
Abdun Nabi Sk
Apr 16 '08 #3
Mr Gray
47
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
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
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
I have button that is calling
javascrip:parent.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 Expert Mod 8TB
I have button that is calling
javascrip:parent.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 RequiredFieldValidator, RegularExpressionValidator ...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
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
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...
4
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...
4
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...
1
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...
6
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...
3
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...
3
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...
1
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.