• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 476
  • Last Modified:

execute server side code via javascript in asp.net using C#.net

hello,

kindly tell me how to execute server side code via javascript using C#.net in my web application

but not the static method .. or open.window because i don't want to open the windows because to many data on the server side and impossible to send on the anotherpage for process via cache or session ... and static method is not because my application is dynamic and if i use static method then its useless..

please help me.. !! fastly
0
AVARICESOFT
Asked:
AVARICESOFT
  • 6
  • 5
  • 2
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
Explanation:

What I am doing here is adding a server-side button control (<asp:Button runat=server &>). I then make the button invisible by adding style=display:none;. In the buttons server-side Click event, I do whatever it is I want to do on the server.

In this example, I am clicking a standard client-side button (<input type=button &>) to fire off a server-side redirect, but this could just as easily be called by selecting an item in a DropDownList, typing text into a textbox, etc. Clicking the client button calls the JavaScript .click() event of the server-side button control.

if I need to pass arguments from the client-side script to the server-side script
it is done done by putting server-side HiddenField controls on the page.
Use the JavaScript to set their values (document.getElementById(myHiddenField).value = Hello World;) and then use C# or VB.NET to retrieve them on the server (Dim myVar as String = myHiddenField.Value).
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>         

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
  <title>My Page</title>
  <script type="text/javascript">
    function myClientButton_onclick() {
    document.getElementById('myServerButton').click();
  }
  </script>
  <script runat="server">
    Protected Sub myServerButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles myServerButton.Click
      Response.Redirect("http://www.asp.net/")
    End Sub
  </script>
</head>
<body>
  <form id="form1" runat="server">
    <input id="myClientButton" type="button" value="Press Me" onclick="return myClientButton_onclick()" />
    <asp:Button ID="myServerButton" runat="server" style="display:none;" />
  </form>
</body>
</html>

Open in new window

0
 
Meir RivkinFull stack Software EngineerCommented:
u can also use this post from codeproject:
http://www.codeproject.com/KB/ajax/Ajax_Call_using_AjaxNet.aspx
0
 
AVARICESOFTAuthor Commented:
please give me this example on c#.net i explicitly mention in my code not vb

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
Meir RivkinFull stack Software EngineerCommented:
replace VB code in <script runat="server"> with the follownig:
protected void myServerButton_Click(object sender, System.EventArgs e)
{
    Response.Redirect("http://www.asp.net/");
}
0
 
AVARICESOFTAuthor Commented:
not working :(
0
 
Meir RivkinFull stack Software EngineerCommented:
can u post your aspx code?
0
 
AVARICESOFTAuthor Commented:
attached the file which u have made.. !!
0
 
Meir RivkinFull stack Software EngineerCommented:
my answer should be treated as guideline not a copy/paste.
did u follow the explanation above?
did u go through the link i've posted from codeproject to understand the solution?
0
 
Saber37886661Commented:
If you are using Telerik controls just use the Ajax control.
Then it in if your RadAjaxManager is called RadAjaxManager1 it is:
RadAjaxManager1.ResponseScripts.Add("Javascript function name");
0
 
AVARICESOFTAuthor Commented:
and i want to call this Javascript function when new node is entered ..

and only call the function and its gooes to the javascript then go to the server side call my serverside function then i achieve my objective

only call server side function via javascript

thanks.

0
 
Saber37886661Commented:
as a matter of intrest, if you have 2 open questions in here pertaining to the same problem (well the two issues must mesh) why are they seperate, and why complicate it all by using a javascript layer in here? I dont understand why you are not just using ajax. That way your form doesnt change and you then have access to Teleriks rich server side controls.
0
 
AVARICESOFTAuthor Commented:
i only want to call the server side function in the javascript thats all .. only tell me how .. nothing meshing the question ..

and no button or click event occur .. or no static page method or webmethod...


i only want a code in javascript which calls serverside function


0
 
AVARICESOFTAuthor Commented:
thanks i get the solution
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 6
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now