Web Forms :: Execute Server-side Code From JavaScript?

Jun 11, 2010

Executing Server side code using Javascript. Here is the solution.In the Asp.net forums, I often see the question asked, "Can I call server-side code from the client/JavaScript?" Almost invariably, the responses given are "No, the client cannot access the server," or "You can only use WebMethods or PageMethods." The first response is not entirely correct, and unfortunately, WebMethods and PageMethods are static methods and therefore have no way to directly access the page.This is why I present to you the following "hack". I call it a hack because there really should be some way built into the ASP.NET AJAX Extensions that allow this approach directly. Instead, it relies on using controls in a manner that they aren't necessarily intended in order to obtain the desired result. But this "hack" does have a redeeming quality—it's incredibly easy.The Code:

<%@ 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">

[code]...

View 1 Replies


Similar Messages:

Web Forms :: Can Execute Server Side Button Event After Executing Javascript Code

Mar 10, 2010

I have buttion on web page and client side java script ConfirmResetPassword() for confirmation message which return true or false

[Code]....
if (confirm("Are you sure you want to reset password of this user?")) {
return true;
}
return false;
}
}with Telerik AjaxSetting[Code]....
<input type="button" name="ctl00$ContentPlaceHolder1$btnResetPassword" value="Reset Password" onclick="javascript:return ConfirmResetPassword();__doPostBack('ctl00$ContentPlaceHolder1$btnResetPassword','')" id="ctl00_ContentPlaceHolder1_btnResetPassword"
/> ?

View 5 Replies

How To Execute Server Side Code From This Button

Mar 22, 2010

I have a button where I use an Animation Extender. When I click the button I have to set OnClientClick="return false;" otherwise the Animation Extender closes.
So that causes my problem. How do I execute server side code from this button?
I have tried this code in my code behind, but there is an error:

Code:
Dim strScript As String
strScript = "<script>"
strScript = strScript & "return false;"
strScript = strScript & "</script>"
ScriptManager.RegisterStartupScript(Me, GetType(Page), "MyScript", strScript, False)
This is my code for the Animation Extender:
Open data"></asp:Button>

View 3 Replies

Execute Client & Server Side Code With One Click?

May 18, 2010

i am not sure if my design have flaw but would like to know what others have to say, i am in a situation where i am trying to acheive two things in one click.

using : asp.net web form

i have a web form with few textbox and a gridview control and a button.

if i click on the button i am executing two things

1) asynchronously get data from server to client (working great) and able to display the data in the textboxes.

2) same click i want to bind the gridview.

[Code]....

recap:

1) jquery script execute asynchronously to get data from server to client and display in the textboxes
2) server side code to bind the gridview.

PROBLEM:

if i have onClientClick="return LoadDataById(); then it executes ONLY ajax code and does not execute server side but if have onClientClick="LoadDataById(); then it executes client and server but textbox value wipeout. (the textbox value popuplate through ajax)

View 2 Replies

C# - Execute Server Side Code Without Full Postback

Jun 8, 2010

When a user clicks a button I need to create a .bmp file on the server. After the .bmp file is created I will load it into the html page. Would Ajax be the best way to accomplish this?

View 6 Replies

C# - How To Execute Server Side Code Just Before The Session Variable Expires

Oct 7, 2010

In my asp.net website I am creating a session upon user login and I would like to perform some operations in the database just before this session will expire.I am having problem in determining where should I write code and how will I know the session is going to expire.

I am not sure if 'session_end' event of 'Global.asax' suits my requirements as the session I want to check is created manually(not a browser instance).

View 1 Replies

Call Javascript Function From Code Behind After Server Side Code Executes

May 25, 2010

I have an asp.net button, that when clicked calls a code behind function. The function does some evaluation, and then I want to call javascript from within this asp.net function.

View 2 Replies

How To Execute Serverside Code In Parallel With Client Side Code

Aug 2, 2010

I have a web app that needs to do two things at the same time. After a user clicks a button on the site, a javascript function needs to execute and while thats working I need the server side code for the button click to execute without waiting on the client side to finish.

To be more specific, the client side function takes about 23 seconds to complete, and while that is running the server side code promts the user for printing a document. So I need the javascript to run "in the background".

View 3 Replies

AJAX :: Can Send An Object From Client-side JavaScript To Server-side Code Via AJAX

Mar 16, 2011

I know that I can receive an javascript object from the server via ASP.NET AJAX using Json. But I am not sure how can I send an javascript object from my client-side javascript to my server-side code. And if I can, how can I extract this object in my server-side code and access its members?

View 1 Replies

Cannot Refresh The Page After Calling Server Side Code Using Javascript

Apr 4, 2011

I am using Ajax's EnablePageMethods way to call server side code using javascript. The problem is that in IE8 the page automatically refreshes after the ajax call has been completed i.e. the server side function has been executed successfully. I want the same to happen with Chrome and Firefox but it doesnt refresh the page once the server side function has been executed.

I am using this way to call server side code from Javascript -- [URL]

this is the javascript function:

[code]...

this is where i am calling the javascript event:

<a href='myPageName.aspx' onclick='javascript:editNode(1);return false;'>Delete</a>

View 1 Replies

Jquery - Click On Table Row To Fire Both JavaScript And C# Server Side Code

Feb 16, 2011

I have a pop-up div contains a table.

I need to make table rows clickable and can be catched by both js and .net server side .

how can I use Request.form to solve this issue? since I've created functions for js part .

The reason why I want to fire sever side event, because I use JS to add option (item) to an asp:ddl in an updatepanel, it will cause error or lose the new option by doing a postback fired by other buttons.

View 1 Replies

Javascript - Get Client - Side Script To Execute On Postback (from An UpdatePanel)?

Jul 15, 2010

Basically I want to get some javascript to be sent back to the client and executed from a postback inside an UpdatePanel. Furthermore this is inside of a reusable WebControl. I've tried

this.Page.ClientScript.RegisterStartupScript and this.Page.ClientScript.RegisterClientScriptBlock but Firebug shows that those scripts aren't sent back in the postback's response.

I also tried straight up writing a <script> tag inside the control's main div in the Render method, which does get sent back but isn't executed. I got a hacky solution working, but ideally looking for a cleaner solution. The hack is to add a 1x1 pixel img with width/height set to 0 and use that for an onload event to execute the script and that works, but it seems like there has to be a cleaner way to do this.

View 1 Replies

Forms Data Controls :: How To Execute Jquery Function With Gidview Button Or From Server Side

Jan 19, 2011

How can I trigger a jQuery function with the Gridview Select button? I want that the select button trigger the jquery function that has the row details (it's already working with a asp:buttonfield ), and select the row so i can get the values and send it trough e-mail with another button. I don't know if this is possible. or, Can I trigger the jQuery function from code behind with the select button Sub? How?

[Code]....

This function capture the gridview cell values that are hidden and show them in a div outside the gridview (it works as row details). I have no problem with this.

[Code]....

All i need is a button that select the row index and/or values and trigger the jquery function . Or I can execute the jQuery function from server side. I don't know if it's posible.

View 1 Replies

Execute Javascript In Code Behind?

Jan 20, 2010

Execute javascript in code behind? can i call javascript like this

For i
As
Integer = 0
To 10
'call javascript code
Next

View 10 Replies

Web Forms :: How Do You Write To A Client-side Control (text Box) With Server-side Code

Jan 6, 2010

If I have a standard HTML textbox

[Code]....

but got a readonly error.

View 10 Replies

AJAX :: Execute JavaScript In C# Code?

Mar 10, 2011

Basically i have two asp.net buttons on my asp.net page as follow:

[Code]....

and this is the code behand fo btnSave onclick event:

[Code]....

and this is the code behand of btnPreviwe onclick event:

[Code]....

as you can see, when the btnSave is clicked, it is programmatically clikced the btnPrevew first, and btnPreview registers and fires the required JavaScript. But actually once the btnSave clicked, it does go to the btnPreview_OnClick event, but for some unknow reasons, the javascript in btnPreview_OnClick doesnt work, however, when i just put cstext2.Append("alert('hi')" instead of cstext2.Append("'SaveSignature()'", the javascript does executed, and also if i modifed the asp.net code for btnPreview to this, it works too.

[Code]....

View 5 Replies

AJAX :: If(confirm) Javascript Execute In Code C#?

Jan 22, 2010

i'm a beginner with c# 2.0 and ajax

i have two radio button and i want to execute a javascript if user selected the second radio button

i want execute a javascript if confirm(message)

but i wonder if it possible to GET the value of the if (confirm) if user has click ok or cancel !?

View 5 Replies

JQuery :: Execute Code Behind Function In Javascript?

Sep 29, 2010

I had a custom confirm box Using Jquery....In that It crates two buttons Yes and No. I need to execute my code in Yes click.....how?

View 6 Replies

JQuery :: How To Execute Code Using JavaScript Function

Jun 11, 2010

I have downloaded a jquery tool which creates overlay windows so here is the code which I want to trigger by calling a javascript function instead of a button or link.

The CSS

[Code]....

The HTML note the overlay is executing when i click the button i want this to be triggered on javascript function)

[Code]....

[Code]....

All i want to do is call a function lets say "ShowOverlay()" from my code behind using ClientRegisterScript() and it should do the same as it is doing on button.

View 3 Replies

How To Execute Code Behind Function Using JavaScript Keypress

Jul 22, 2011

how to execute the code behind function using JavaScript keypress ?

The reason is that the keypress that I'm referring to will be used in searching record so I want that every keypress a result will be shown in the gridview immediately.

View 15 Replies

Javascript - Execute Some Custom Code Before AJAX Request Is Sent

May 10, 2010

I have a drop down in an ASP.NET page. Whenever the value of the drop down changes an ASP.NET AJAX request is made to the server. I also attached a jQuery "change" event handler to that list to execute some code when the value is changed. So, probably two different event handlers are being attached to the same drop down, and it's causing some problems, i.e., sometimes wrong drop down values are sent to the server. I don't know why is this happening but I think attaching two different event handlers to a same drop down may be the reason.

Can anyone tell me what is the problem here? If what I guessed is true, then is there any other way to execute some custom javascript code before asp.net AJAX request is sent ?

View 1 Replies

Visual Studio :: Replace Text And Execute Server Side?

Mar 18, 2011

The text and style runs properly but the server side code is ignored. How would I write this so that it's not ignored? Do I have any options?

Text = Text.Replace("Blank Div", "<div class=""New""><% If Session(""User"") Is Nothing Then%><asp:LinkButton ID=""lbtnSignup"" runat=""server"">Sign up</asp:LinkButton><% End If%></div>")

View 2 Replies

Execute JavaScript From Code - Behind After UpdatePanel Has Finished Loading Its DOM Elements?

Jul 7, 2010

I have an UpdatePanel with a repeater in it that is re-bound after a user adds an item to it via a modal popup. When they click the button to add a new row to the repeater the code-behind looks something like this:

protected void lbtnAddOption_Click(object sender, EventArgs e)
{
SelectedOption = new Option()
{
Account = txtAddOptionAccountNumber.Text,
Margin = chkAddOptionMargin.Checked,
Symbol = txtAddOptionSymbol.Text,
Usymbol = txtAddOptionUsymbol.Text,
};
Presenter.OnAddOption(); // Insert the new item
RefreshOptions(); // Pull down and re-bind all the items
mpeAddOptionDialog.Hide(); // Hide the modal
// ... Make call to jQuery scrollTo() method here?
}

This works fine and the new row will show up quickly via the UpdatePanel. However, there are often hundreds of rows and where the new one is added is based on the current sorting column used. So, I wanted to take this as a chance to use the sweet jQuery ScrollTo plugin. I know that if I give it the ID of my overflowed container div and the ID of an element within it, it will smoothly scroll straight to the users newly added row. However, there are two problems:

I need to find the appropriate row so I can snag the ClientID for it. I need to execute the jQuery snippet from my code-behind that will cause my newly updated repeater to scroll to the right row. I've solved #1. I have a reliable method that will produce the newly added row's ClientID. However, problem #2 is proving to be tricky. I know I can just call ScriptManager.RegisterStartupScript() form my code-behind and it will execute the JavaScript on my page.

The problem I'm having is that it seems that it is executing that piece of JavaScript before (I'm guessing) the newly refreshed DOM elements have fully loaded. So, even though I am passing in the appropriate jQuery line to scroll to the element I want, it is erroring out for me because it can't find that element yet. Here is the line I'm using at the end of the method I posted above:

string clientID = getClientIdOfNewRow();
ScriptManager.RegisterStartupScript(this, typeof(Page), "ScrollScript", String.Format("$("#optionContainer").scrollTo("{0}", 800);", clientID), true);

What do I need to do so I can ensure that this line of JavaScript isn't called until the page with the UpdatePanel is truly ready?

View 2 Replies

Write And Execute Textchange Event Handler In Javascript And Code Behind?

Dec 22, 2010

in my asp.net website, i have textbox control inside datagrid control. I would like to add textchange event in javascript where i need to sum the values inside textboxes in datagrid and show that addition in lable outside grid. I would also like to do same addition in codebehind(*.cs) But codebehind only execute when browser not support javascript. It means when browser support javascript only client side javascript should execute not server side code

View 1 Replies

How To Execute Web Services Asynchronously In Server Side When Called By JQuery's .ajax

Mar 22, 2011

I have an ASP.NET (3.5) web page which calls a few web methods (SOAP based) using jQuery's .ajax method. The web methods implement 'ScriptMethod' attribute and return JSON data. The web service file (asmx) is local to the same project.

I noticed these web methods execute synchronously on the server which means they run sequentially and affect performance negatively, some methods are waiting, when some of them are slow.

I read this article and I am not sure if I understand that WebMethods which implement Scriptmethod can run synchronously only (they implement IHttpHandler not IHttpAsyncHandler).

If this is true, I might have to change the design. I am looking for other designs, maybe like using WCF, where the browser can call webmethods using JavaScript and the web methods run asynchronously on the server.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved