Visual Studio .NET - calling C# method from javascript
Asked By mostafa hamdy
29-Nov-06 05:49 AM
Hi all
please I want to call C# method from javascript code in my web page please how can I do som thing like that please if any body can help me send me
regards
Mostafa
K Pravin Kumar Reddy replied to mostafa hamdy
Not directly, no. http://www.daniweb.com/techtalkforums/thread31065.html# functions live server-side, client-side functions live on the client.
In fact, the only way to get ANY server-side code to run, is to submit the form. ASP.NET unrolls the HTTP headers, unpackages the hidden ViewState variable, re-instantiates objects, and then decides what events to raise based on all of the above.
What you can do is have your JavaScript function set a hidden form variable, then do a form.submit().
Then, in your Page_Load handler on the server, use the Request object to check for the presence and/or value of this variable, and call the appropriate server-side method.
There are several ways to do this
besides "submitting the form".
1) You can use XmlHttp or the built in ClientCallback infrastructure to actually make a GET call to the page and a method call based on parameters on the QueryString, and marshal the results back into the client-side DOM via the ResponseText property.
2) You can use an infrastructure that is specifically designed to do this - such as Anthem.Net, MagicAjax, or Microsoft ASP.NET AJAX (formerly "ATLAS").
Of the 3 mentioned, right now I'd recommand Anthem.Net as it is easy to learn, lightweight, and highly extensible.
Toolbar user control
Hi all
I have tool bar user control which contains 4 buttons ,and I add for each property to enable and disable this button, when I use it in web page it works good but when I try to use the enable/disable property of the user control in some method or event of the web page it doesn't work at all but it works only in the page_load event and no method else
please if any body have face some problem like this with user contol or know solution for this problem please send me
best regards
Mostafa
pls try this
in javascript lets say you have a method called "hi" which expects a parameter.
<script>
function hi(var someVar)
{
document.write("hi " + someVar);
}
</script>
in .NET on a method you wish to call the javascript method from:
string whatever = "blahblah";
Page.RegisterStartupScript("myScript", "<script language=JavaScript>hi('" + whatever + "');</script>");
I hope that is what you are looking for and hope it helps!

Interview Questions for .NET Framework This article is specially for the users those are in development or want to be a .net developer • To test a Web Service you must create a windows application or web application to consume this service? It is True / False? FALSE How many classes can a single.NET DLL contain? Answer1: As many Answer2: One or more What are good ADO.NET object(s) to replace the ADO Recordset object? The differences includes In ADO, the in memory representation of data is the recordset. In ADO.net, it is the dataset A recordset looks like a single table in ADO In contrast, a dataset is a collection of one or more tables in ADO.net ADO is designed primarily for connected access ADO net the disconnected access to the database is used In ADO you communicate with the database by making calls to an OLE DB provider. In ADO.NET you communicate with the database through a data adapter (an OleDbDataAdapter, SqlDataAdapter, OdbcDataAdapter, or OracleDataAdapter
faqs on masterpages Hi all, can anybody tell me the FAQs on Masterpages in asp.net. Thanks alot var Hi What are Master Pages in ASP.NET? or What is a Master Page? ASP.NET master pages allow you to create a consistent layout for the pages in your application A single master page defines the look and feel and standard behavior that you want for all of the
across this article. See if it can be of any use regarding debugging javascript from .net: Your pages need JavaScript, both for logic and UI. But debugging JavaScript code can be a pain, unless you know a few tricks. ASP.NET has many advantages over classic ASP in the area of debugging. You can now easily debug your server-side code using the full power of a modern debugger such as Visual Studio .NET. This, along with the introduction of server controls and a postback architecture, has simplified Web and postbacks have reduced the need for Web developers to interact with JavaScript in an ASP.NET application, many developers are learning that they cannot forget about client-side scripting altogether. Developers
is the code. . .but please tell me why slide show is not running. . . . . . ?? on ASPX Page: protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["Id"] ! = null) { uint Id = Convert.ToUInt16(Request.QueryString["Id"].ToString()); FillControls(Id); GetImages(Id); GetImage(Id); } ScriptManager.RegisterStartupScript(this, this.GetType(), "myScript1", "slideshow_automatic();", true); } public void GetImage(uint id) { Test ts = new Test WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] / / To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class Test : System.Web WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] / / To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class Test : System.Web GetFiles(" *.*"); foreach (FileInfo file in DI.GetFiles()) { ar.Add(file.FullName); } return ar; } } ON ASMX Page [WebMethod] public AjaxControlToolkit.Slide[] GetSlides( uint id) { ArrayList ar = GetAllFile(id); AjaxControlToolkit.Slide[] fileCollection = new GetFiles(" *.* "); foreach (FileInfo file in DI.GetFiles()) { ar.Add(file.FullName); } return ar; } ON ASPX PAGE: <asp:Label runat = " Server " ID = " imageTitle " CssClass = " slideTitle " / > <br / > <asp:Image ID = " ImagePlayer " runat = " server
Build an Anthem.NET [AJAX] Autosuggest Textbox Build an Anthem.NET [AJAX] Autosuggest Textbox by Peter A. Bromberg, Ph.D. Peter Bromberg Remote Scripting (which is an Autosuggest feature built in, but in this article I will focus on the Anthem.NET framework, reworking some very nice code that was originally submitted to the Anthem.NET Sourceforge repository as a suggested patch by J.C. Murphy. I've changed around the and related properties directly into the control. The sample control is presented here in both ASP.NET 1.1 and ASP.NET 2.0 versions, along with the entire source tree so that interested users can look