How to call server side function from client side JavaScript?

I want to call a server-side function, like a button's click event or just another private or
public function , from a client-side JavaScript function.
How do I do that?

thanX
Anz

If this post was useful to you, please mark it as answer.

ClientSideAsp.Net | Blog
0
anzer
5/18/2005 6:13:36 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

4 Replies
2888 Views

Similar Articles

[PageSpeed] 30

Maybe alittle more that you need, but.......

1) Put a button on the page. Lets say its id is Button1. Make sure that its has causesValidation=false
2) Write the code for the button.
3) Write the following in the PAge_Load event

Button1.Attributes.Add("onClick", "myJSFunction(); return false")

4) Copy this javascript onto your page.

function
myJSFunction()
{

        //Fix to get the button to validate the page
       
if (typeof(Page_ClientValidate) == 'function')

       
{
               
Page_ClientValidate();

       
}

       
if (Page_IsValid)

       
{
               
var answer = confirm('Do you wish to continue?');

                
if (answer)

               
{
                      //This calls the Button1's server side code
                     
__doPostBack('btnButton1','');
                }
         
}

}


Intelligence is a burden.
Jagdip Singh Ajimal
Manchester (and yes, I am a Manchester United fan)
0
jagdipa
5/18/2005 8:13:12 AM
Hi jagdipa 
i didnt understand
Page_ClientValidate and Page_IsValid means. Is it a Javascript function defined by me or its an inbuilt capability like serverside Page.IsValid.
Thanks alot. and if there is any method to call a server side function instead of an event.
Anz

Gazing through the window at the world outside
Wondering if mother earth will survive
Hoping that mankind will stop abusing her, sometime






If this post was useful to you, please mark it as answer.

ClientSideAsp.Net | Blog
1
anzer
5/18/2005 9:07:11 AM
If you have validators on the page,
then ASP.NET automatically puts javascript on the page to handle client
side validation. That is where the Page_ClientValidate and Page_IsValid are coming from.
You may have problems with this if you are using anything other that IE (I havent tested this outside of IE). But, you could simply modify it to:

function
myJSFunction()
{

        //This calls the Button1's server side code
       
__doPostBack('btnButton1','');
}

The reason I included this is because people often want client side validation, and a confirmation box before running the buttons serverside code. That is what this javascript function was originally designed for.

As far as I know, there is no way to call a serverside function instead of an event. But, one way round this could be to just make Button1 invisible in the Page_Load event (Button1.visible = false). That way, there is no button on the page, but the code for the button click event is still there.

Intelligence is a burden.
Jagdip Singh Ajimal
Manchester (and yes, I am a Manchester United fan)
0
jagdipa
5/18/2005 11:05:20 AM
I tested your solution ya it works good. Thanks.
ASP.net's inbuilt validators are not working in Mozilla and all so we are using Javascript.






If this post was useful to you, please mark it as answer.

ClientSideAsp.Net | Blog
0
anzer
5/18/2005 12:47:39 PM
Reply:

Similar Artilces:

How to call server side(C#) function from Client side(Javascript) function?
Hi i have used below functions,  function HandleOnClose() {// this function will be called after clicking browsers close button in Internet explorer if (event.clientY < 0) { event.returnValue = 'Are you sure you want to leave the page?'; } // if he clicks ok then i need to call one server side function in this instance.. else not. } <body onbeforeunload="HandleOnClose()" leftmargin="0" rightmargin="0">other controls in page..</div>  How to achieve this? Thanks MS AJAX Extensions would be the option of choice here. Combined with webservices you can...

how to call server side function from client side javascript?
Hi all, I have a image button in the update panel. I would like to call a method from server side (not from webservice) to get the variable when Onclick on the image button is invoked. Is there any way that I can able to access this function from the client script? In using the UpdatePanel, in essence, you're already doing this because there will not be a full postback.  You can make an asynchronous call to your Click method of your ImageButton.  So, what do you want to do with this "variable"?Christopher Reed"The oxen are slow, but the earth is patient."...

Call server side function from client side javascript
I have a javascript where I either need to call an onclick even of a server link button or I need to be able to call a server side function.   The only thing is I cant use AJAX.  Is there any way I can do this or am I spinning my wheels. Thanks!-------------Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue. I have a similar problem.  In my case, I would like to set a server-side session object from JavaScript.  Any suggestions?  Thanks.  Dan Sure, y...

Can you call a c# on the server side from javascript functions on client side
Hello guys This is something intresting I have come across during development. I have a javascript written in a .JS file , to my knowledge the .js files are executed on the server side. But security concerns with java script that these .js files can be access by connecting to port 80 of the server . So an ultimate alternative reminas to call c# code from a java script function. Can anyone Help me on this matter Regards Nihar Hi Nihar, Usually .js files executed on client side. Please explain your configuration.Leon LangleybenMCSD, ASP.NET MVPBlog...

Calling a client side function from the server side
Is it possible to call a client side function from the server side. I dont want to invoke that function through button click. I just want to call that to do some operations.  Regards, Aish Use the below code ASP.NET 2.0 Page.ClientScript.RegisterStartUpScript(this.GetType(),"callfunction","<script language=javascript>Test();</script>"); ASP.NET 1.X Page.RegisterStartUpScript("callfunction","<script language=javascript>Test();</script>"); Where Test() is the javascript function. HCHaissam Abdul MalakMCAD.NET| Blog | No, it is not possible.  The cl...

How to call server side function on client side
Hi,   How to call server side function on client side? here i want to call change() function on textbox onchange event.   <script language="javascript">    function serverfunction()    {    }    </script><input id="Text1" onchange="javascript:serverfunction();"  type="text" /> code behind:  public void change()    {        Response.Write("hello");    } <script type=&quo...

Is it possible to call client side function from server side code without initial client request?
Atlas is great. I'm using timer to periodically check database changes on server to populate client side controls with new data. Is it possible to do it without a lot of client requests to server which takes a huge useless network traffic? Server should call client side function on all connected clients when, for example, 'database updated' event occurs on server. Thanks. Hi~ Just for your interest, I think you could have a look at Comet, many web IM like Gmail's embeded Gtalk and meebo.com are built on this architecture你好! Just FYI o_O...

Call client side function from server side code
My problem is that in some point of the VB.Net code I need to call a function defined in vbScript, for example: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click   'There's some code here....   ' ...   If (SomeCondition) Then   'HERE'S WHERE I NEED TO CALL THE JAVASCRIPT FUNCTION... SO HOW CAN I DO THAT?   Else     '...   End If   ' ... End Sub The asp.net code runs to generate the html and when it is done the html is rendered in your browser. So you can't access cli...

calling server side function from client side script
i have a web form that includes a function named "koko()" in its server side class i want to write a script code in in its HTML script that will be run at the client side, and this client side script will call the function "koko()" from the server side. in brief : i want to call a server side function from a client side script... can you help me in this You can't call server-side code directly from client-side code. You can, however, trigger a postback that your server-side code watches for and triggers the server-side code appropriately. You can do some ...

Client side script calling Server side functions
Hi, I'm currently developing an ajax.net enabled aspx page that contains a usercontrol (which is based on the listbox but extends it to include icons to represent invalid data). http://www.djcharlie.co.uk/WeeeCareResolutionCentre.jpg I want the onClick event of the selected TR to call an asp.net server function which then populates the controls to the right hand side in the page. Obviously because the row is just rendered HTML overriden from the base class I can only assign a javascript function to the onClick event. So I need a way of calling a server side function that will populate th...

Calling a server-side procedure from a client-side function
I have a server side function that executes a database stored procedure, and I need to be able to call it from a javascript function.  Is this possible (without using an iFrame)?  Post back the page or use Ajax. Eric Pascarello.com | Twitter epascarello | LinkedIn...

Calling server side function from client side alert
Hi, I am developing an ASP.Net application in which I am giving client side alert to the user with OK and Cancel buttons. Can I call a server side function from the click of this button? For e.g. I have to give user alert "Do you want to save record" with Yes/No button. On Yes button click it should go to the server and save the record. Can I call some server side function from the Yes button click? Any help in this regard will be highly appreciated. Thanks in advance. Ashish I would create a button control, say Button1. set Button1.visible=False then, ...

How to Call server side and client side function on same LinkButton
hello,         i have one linkbutton when i click on linkbutton i insert record in DB using onclick=Linkbutton_click. if successfully insert then returnvalue is 1. after return 1 i want to call javascript function. how i can do this? Reply ASAP. Is It Possible? e.g. <asp:LinkButton ID="Operation_Link" runat="server" OnClick="Operation_Link_Click"></asp:LinkButton>protected void Operation_Link_Click(object sender, EventArgs e) {if (Operation_Link.Text == "SUBMIT") {ReturnValue = company.InsertCompany...

Calling a server side function from client side using the toolkit
Ok, I'm sure this is a really stupid question, but I'm willing to ask it anyway.  Let's say that I created a new extender called "My", so I now have three files files, MyExtender.cs, MyBehaviour.js, and MyDesigner.cs.  I want my control to be able to take some data on the client side and use it to retrieve some data on the server side, which AJAX is all about right? :) So for the sake of argument, let's say I want to enter an email address in a textbox, and then consult a database to return the user's password. So in my MyExtender.cs file, I create ...

Calling a client side control event from a server side function
I would like to know how to raise an event on a client side only control from a server side function.   For example, I have Button1 whose onclick is handled at the server. The logic behind the function will do 1 of 2 things, change the text of a label to indicate a problem or navigate to a new page.  I cannot use redirect because i need the new page to appear inside 2 of 3 existing frames.  I can manage this using an anchor on the client.  All I need to do is automatically click the anchor after I post back from the Button1.click event.I tried the following line of c...

Client-side call from server-side form... anyone, anyone, Bueller?
I'm hoping someone can help me here, I am about at my wits end.   I am a part of a team building a rather rich web app that requires multiple possibilities as to the form layout.   Right now, we are using javascript to dynamically build the form according to the needs of the "search" that is being created.   i.e., one person with one house, two people with one house, three people two houses, all dynamically created by the user as they are creating the search.   Obviously depending on how the search form has been created there would be any...

Call server-side page function from client-side button click
I have an existing ASP application that I am migrating to ASP.net. In the ASP app I was using the Microsoft.XMLHTTP on a the client-side of a ASP page to retrieve data from another asp page using the Microsoft.XMLDOM object. The client page passes 3 tags columns, table and Criteria. The receiving page builds the SQL statement executes the query and returns the row with all the column data. I am trying to convert it over to ASP.NET and I am getting errors on the xmlDOM.Load(Request.InputStream) on DLookup.aspx, the code is listed below. Someone suggested to use System.Net HTTP classes su...

Problem accessing a server side declared array from the client side javascript function.
I have an array that store the values of a resultset row under the server side coding.How do i retrieve them under my client side javascript function.I wrote the following coding under my client side function and it got an error.BSCStr is an array storing data from a resultset row which i did under the server side coding. From client side javascript function: addr=addr + "&C" + i + "=" + <%=BSCStr[i]%>; Hi wingshya, Did you still need help with this thread? Jason ConwayMCP, MCTS, Certified SCRUM Masterasp.net blog...

Problem accessing server side array values from javascript client side function
i faced the following problem ..i have an array that store the values of a resultset row under the server side coding.How do i retrieve them under my client side javascript function.I wrote the following coding under my client side function and it got an error.BSCStr is an array storing data from a resultset row which i did under the server side coding. From client side function: addr=addr + "&C" + i + "=" + <%=BSCStr[i]%>; First of all, you can't mix server-side and client-side code. The reason is that the protocol that is used to communicate betwee...

Accessing server-side control in client-side javascript function; on Content page
I am trying to set an asp:textbox value in the Client side javascript function. It works fine on the standalone page. But when i try to do this the Content page, it’s giving the follwoing error message. document.getElementByID[...] is null of not an object  Any idea? Thanks, Riz   Hi, are you using ClientID property of that server control, to get its ID (which is rendered at the client and can be used with document.getElementById )?Thanks,Teemu KeiskiFinland, EU Thank you my problem is solved....

Problem accessing server side array values from client side javascript function
i faced the following problem ..i have an array that store the values of a resultset row under the server side coding.How do i retrieve them under my client side javascript function.I wrote the following coding under my client side function and it got an error.BSCStr is an array storing data from a resultset row which i did under the server side coding. From client side function: addr=addr + "&C" + i + "=" + <%=BSCStr[i]%>;...

How do I call server side function in client side script without using __doPostBack
Hello, My page has a server side panel that is hidden when the page loaded, checkboxes inside of the datagrid, and buttons.  If at least one checkbox is not clicked and the user click on the button, I show the panel.  When the user click on one of the checkbox, I want to hide the panel.  Onclick on the checkbox I already have a cleint function to change the row color.  I don't want to use __doPostBack.  Don't want to do postback. My question are: How do I either have checkbox onclick called both client and server side functions.  Or have the client side func...

Having WebControl recognize javascript client side function instead of looking for a server side funtion.
I have the following HTML field definition in an ASP.NET web form page: <asp:DropDownList id="techevalasset_maintbyoper" style="Z-INDEX: 114; LEFT: 280px; POSITION: absolute; TOP: 40px" runat="server" ForeColor="Black" Font-Names="Tahoma" Font-Size="X-Small" Height="24px" BackColor="White" OnSelectedIndexChanged="acMaintChanged(this)"></asp:DropDownList> I added this field to the web form as a Web Form Drop Down List control. When this field is changed I want to enable/disable anoth...

How to call server side function by javascript using Ajax.Net
Sir, I want to call the server side function by javascript function. Is it possible using Ajax.Net (System.Web.Extensions.dll or AjaxControlToolkit.dll)? If yes then please give me the code or URL. I found some article using Ajax.dll but I want to use System.Web.Extensions.dll or AjaxControlToolkit.dll. Please help me. Thanks in advance Paresh        Hi, Ajax.NET and ASP.NET AJAX, what you want, are completely different implementations so please be sure to use the correct terminology in the future as there are already 100+ AJAX frameworks aroun...

Web resources about - How to call server side function from client side JavaScript? - asp.net.web-forms

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

JavaScript - Wikipedia, the free encyclopedia
programming styles. JavaScript was formalized in the ECMAScript language standard and is primarily used in the form of client-side JavaScript ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
... editor - report abuse/spam - help the entire directory only in Tools/Obfuscators Description Top : Computers : Programming : Languages : JavaScript ...

Facebook File-Transfer App Pipe Relaunches, Now Works Via JavaScript, WebRTC
... allowed Facebook users to send and receive files up to 1 gigabit in size. A new version of Pipe debuted Monday, and the app now works via JavaScript ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

JavaScript
The Facebook SDK for JavaScript provides a rich set of client-side functionality for adding Social Plugins, making API calls and implementing ...

Senior Front-End Developer (Javascript and AJAX)
Company: Sometrics Category: Software Development Location: Los Angeles, CA How to Apply: jobs@sometrics.com Description: We are looking for ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken . blog.mozilla.org/research/2014/… ...

Resources last updated: 2/17/2016 4:11:38 AM