Web Forms :: Use Some Javascript Code To Make AJAX Calls To Different Handlers?
May 12, 2010
I am currently building an asp.net webforms application in ASP.NET C# using Visual studio 2008 and the Framework .NET 3.5.In my application main page, I use some javascript code to make AJAX calls to different handlers (.ashx files) in order to get some information.In this handlers définition (in the CodeBehind), I use the Oracle provider for .NET (Oracle.DataAccess.Client) to get the requested information from an Oracle database.The thing is, when I make a first call to one of these handlers, everything works just fine, but when the main page try to repeat the call in order to update the information requested, I encounter a problem.In fact, it appears that the different Oracle SQL request results that were made during the first call are still in memory and that the requests are not repeated correctly in order to obtain the updated information from the database. The application keeps the first results and this is these results that are sent back to the main page once again.I don't know how to force the handler to obtain new results and work with it instead of working with the previous results.In the handlers définition, the IsReusable methods are all set to false.I have called the Dispose() méthods of every Oracle object at the hand of the handlers définition and then the System.GC.Collect() méthod to force Garbage Collection. But this does not seem to be sufficient to be sure that nothing is kept in memory.
I'm working with the MicrosoftAjax.js libraries to make my webservice calls via javascript, right now all my services are returning basic types, like string, int, bool. can i also have my services return things like DataSets, DataTables, or custom Classes that I have built to my javascript side?
How do I go about making true ajax requests to an asp.net page? (Not update panels). I read this tutorial but couldn't get it working. Is there a better approach? Or should this work?
I am trying to make 2 separate AJAX calls using buttons. What I want to happen is: when Button1 is clicked ProductsTable shows data from the webservice; when Button2 is clicked OthersTable shows its own data from the webservice. But right now, when either button is clicked, nothing shows up. I know the code works if there's only one of them and it's not wrapped around a .click function.
No error messages. ASP.NET 4.0, JQuery 1.4.4. Not using ScriptManager. Not using UpdatePanels.
I am trying to use LinkButtons with the DefaultButton property of the ASP.NET Panel in an UpdatePanel. I have read and used the various other answers that are around describing the wiring up of the click event so that a full postback is not done instead of a partial postback. When the page loads, I wire up the .click function of the LinkButton so that the DefaultButton property of the ASP.NET panel will work.
This all works fine, until you bring an UpdatePanel into the mix. With an UpdatePanel, if there is a partial postback, the script to wire up the .click function is not called in the partial postback, and hitting enter reverts to causing a full submit of the form rather than triggering the LinkButton.
How can I cause javascript to be executed after a partial postback to re-wire up the .click function of the LinkButton? I have produced a sample page which shows the problem. There are two alerts showing 1) When the code to hook up the .click function is being called, and 2) When the .click function has been called (this only happens when you hit enter in the textbox after the event has been wired up). To test this code, type something in the textbox and hit Enter. The text will be copied to the label control, but "Wiring up Event Click" alert will not be shown. Add another letter, hit enter again, and you'll get a full postback without the text being copied to the label control (as the LinkButton wasn't called). Because that was a full postback, the Wiring Up Event Click event will be called again, and the form will work properly the next time again.
I have a WCF service returning JSON to jQuery ajax calls and presenting the results on an ASPX page. When the page is NOT under SSL, the ajax calls work perfectly. When the page IS under SSL, the calls fail. I understand that this behavior must be due to the Same Origin Policy (SOP).
So, how do I setup my WCF service to accept calls from an SSL-secured page? Does the WCF service also need to be secured? If so, how do I do this?
I'm building this small control. It should detect client resolution and set height and width values within two separated HtmlInputHidden controls. But tester property is not getting values froms this control.
[ToolboxData("<{0}:UIControlResolution runat=server></{0}:UIControlResolution>")] public class UIControlResolution : Control { HtmlInputHidden _txtwidth = new HtmlInputHidden(); HtmlInputHidden _txtheight = new HtmlInputHidden();
Old school coders are used to having every server control create events in the .cs files.. for example.. Getting the Initial load of data, Saving Data, Deleting data... and then binding datasources to the server control..
New school coders want to do it in Jquery + AJAX calls to .svc files... That gives automatic no post backs so that is a advantage... and I think its a different way of thinking.. All of a sudden the UI related events are all being done in Jquery..
What is the most modern and efficient way to go ? How can I convince the old school coders to let us you this new paradigm ? (assuming it is the better way)
I know how to call a simple old fashion asmx webservice webthod that returns a single value as a function return result. But what if I want to return multiple output params? My current approach is to separate the params by a dividing character and parse them on teh client. Is there a better way.
Here's how I return a single function result. How do I return multiple output values?
For performance reasons, I would like to put some code in javascript but am concerned that a user may pick up some proprietary formulas. Is it even possible to hide it or scramble it to the user?
However I'm not seeing center aligned text. What am I doing wrong? Also, will I need to make whatever changes to the JQuery .css files as well? Basically what I'm aiming for here is a single master page that I can use to hold all .css and javascript code so I don't have to reference it everywhere else.
I'm trying to make API calls to a service provider. I've never tackled JSON requests before but I want to give it a go - as they seem less verbose than XML. Could someone be kind enough to give me a simple example here?
My confusion stems from some libraries I've come across. Do I need to add any libraries to my project? Or is it just a matter of creating a string that complies with JSON syntax and send it via a WebRequest?
I need to gather information (via GET) from several other websites (not under my control), do some processing (specific to each source) on the data returned, and then print all the info out to the user.
Right now I'm making the GET request to website A, waiting for it to return, processing it, then calling website B, and so on... Obviously this is too damn slow. I'd like to make async requests to A, B, and C, then process each response as it comes back, and once I have all the responses, print it all out to the user.
I'm allowed to use classic asp or vb.net. I'm more familiar with classic asp but I'm willing to learn...
This code works fine if i use this inside ssercontrol > panel and i have a checkboxes in table when no checkbox is checked its works fine .... but if i disabled and checked any of the textbox then this doesn't work .... in usercontrol why ? i didnt understand ..
<script type="text/javascript" language="javascript"> function checkboxChecked(){ var allInputs = document.getElementsByTagName("input"); for(var i=0; i<allInputs.length; i++) { var chk = allInputs[i]; if(chk.type == "checkbox" && !chk.disabled && chk.checked) {
return true; } } alert("OOps! You haven't selected all available checkboxes"); return false; } </script>
I was wondering if anyone had an easy way to wire up javascript event handlers to events happening on the server-side. I have a long running process that includes a lot of steps, and would like the client to be continually updated with new information as the steps transition. Will this involve some sort of polling mechanism?
I have a page that contains a user control. Can i make an ajax request directly to the control? I know I can make an ajax request to .aspx or .ashx; however, is it possible to go direct to the .ascx?
I am trying to add validation on my form. I am using AJAX controls in my form fields. When I remove the Update panel and AJAX control, my validation starts working, but when keeping both the things together, my validation is not working. How could I make them work together?
<script type="text/javascript"> function Validate() { var QuestionTextArea = document.getElementById("ctl00_ctl00_cphBody_midbox_fvInsert_txtQuestion"); varError = ""; if (!IsTextBoxEmpty(QuestionTextArea, " Question Text Area not be Empty.")) { alert(varError); document.getElementById("ctl00_ctl00_cphBody_midbox_fvInsert_txtQuestion").focus(); return false; } return true; } </script> <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <asp:TextBox ID="txtQuestion" runat="server" MaxLength="1000" Columns="50" Rows="5" Style="width: 380px; float: none" Text='<%# Bind("Description") %>' TextMode="MultiLine" /> <AjaxControl:TextBoxWatermarkExtender runat="server" TargetControlID="txtQuestion" WatermarkCssClass="water" WatermarkText="Type your Question Here."> </AjaxControl:TextBoxWatermarkExtender> </ContentTemplate> </asp:UpdatePanel>
When I removes ajax extender and Update Panel. My textbox gets validated and when using UpdatePanel. No javascript function created by me is called.
I have an ASP.NET page with two instances of the same Web User Control (a simple WYSIWYG editor). On submit, the WUCs do a little JavaScript magic and then proceed with a normal postback.
The first instance seems to be working, but the second fails to post changes back to the server (it reverts to the original, and posts that). I believe the problem is that the JS only fires for the first WUC. I've traced that to the following code, from the generated client-side source:
function WebForm_OnSubmit() { prepHtml('AddEditPopup1_ctlEditorQuestion_txtEdit','AddEditPopup1_ctlEditorQuestion_divEdit', 'AddEditPopup1_ctlEditorQuestion_divHT' ); //snip... }
The problem seems to be that there should be two calls to prepHtml: one for the ctlEditorQuestion instance of the WUC, and one for the ctlEditorAnswer instance.
Instead, there's only the one for ctlEditorQuestion. Both controls are registering the OnSubmit event, but one of them overwrites the other.The prepHtml call is registered from the WUCs' C# code at runtime:
I should point out that I didn't write this control myself, and I've never seen this kind of runtime registration of OnSubmit JS code before. Page.ClientScript.RegisterOnSubmitStatement is totally new to me. I need to register both prepHtml calls so they run sequentially. Is this possible? I'm open to alternatives to Page.ClientScript.RegisterOnSubmitStatement, so long as the code still gets fired on submit.
i'm just getting started with asp.net and ajax. My question is : is it possible to make an ajax request and simulate the server response in the code behind. in other words can the request be sent to the code behind of the same page? if it's possible haw can i perform this ?
Is there any specific order in which the external CSS or Scripts should be called in a aspx page which could help a bit in decreasing the page load time?
i.e
script type="text/javascript" src="../Includes/JavaScript/jquery.ui.tabs.js" link href="../Includes/css/ui.all.css" rel="Stylesheet" type="text/css"
or
link href="../Includes/css/ui.all.css" rel="Stylesheet" type="text/css" script type="text/javascript" src="../Includes/JavaScript/jquery.ui.tabs.js"