Web Forms :: How To Do Asynchronous Postbacks From Generated Controls
Apr 28, 2010
I am generating an html flow into Update Panels in a content ASPX page (VB.Net 2008 Professional w/ SP1). These include EDIT anchor tags that call a javascript function which calls __doPostBack(target, args); so I can interact with the code behind. This all works fine except on some of the postbacks the connection with the browser just seems to get closed prematurely and suddenly the webpage displays a directory listing. When debugging it, it only happens sometimes, at different places for the E and D options below but not for the V or AddPost or AddArticle. I am just stepping through E or D and suddenly the web page show a directory listing. (What is that? Is the connection crashing? Is the page suddenly redirecting to the base directory because it crashed?)
I am trying to integrate ASP .Net AJAX into an existing application, but so far I am striking out.After significant digging, I found that for some reason, the ScriptManager was set so that SupportsPartialRendering is false, overriding EnablePartialRendering. From looking at the MSDN documentation, it seems to me that this should not be the case.The rules for determiningrSupportsPartialRendering are (from MSDN):The W3CDomVersion property value must be greater than or equal to 1.0.The EcmaScriptVersion property value must be greater than or equal to 1.0.The SupportsCallback property value must be set totrue.Using Firefox 3.6 and IE7+, these tests should have passed. W3CDomVersion = 1.0, EcmaScriptVersion=1.4, and SupportsCallback=true.n an effort to see if I could get around it by setting the value myself, I overrode the OnInit function in the code behind to explicitly set SupportsPartialRendering to true.his appeared to attempt to start an async postback, but failed with the javascript error "this._postBackSettings.async' is null or not an object" from within the ASP.Net AJAX scripts.
Also, I created a sample application outside of my existing project and got it working exactly as I wanted. When I copied and pasted all the code from the sample project and put it into the existing solution (aspx and code behind) it experienced the same issue. I know that it has something to do with the existing solution, but I am at the end of my rope as to what it could be.Other relevant information:he solution I am trying to integrate this into was at one time upgraded from ASP .Net 2.0 to 3.5.The controls which trigger the async postback are in a repeater and are being registered with ScriptManager.RegisterAsyncPostBackControl during prerender by looping over the bound items in the repeater. This occurs after the Repeater is databound. At the same time, triggers are dynamically added to the UpdatePanel. Code snippet (taken from OnPreRender):
[Code]....
I think the "_postBackSettings.async is null" error is something of a red-herring and is an indication that I am headed down a wormhole, so I am not considering heading down the path of forcing SupportsPartialRendering to true for now. Does anyone know what else could be turning it off in the first place? Or what else could be preventing partial rendering from functioning as expected?
I have 3 user controls that I have to load at the same time. They each contain a gridview that pulls data from the database. They are doing a "delay" load of the data so there is a progress bar template that shows that the data is loading however the first gridview fires and loads, then the second, then the third and I need them to all fire at the same time.
I have a C# web application that dynamically adds user controls to the default page for whatever "mode" the application is in. The problem is that it is not persisting these across postbacks. How do I persist these across postbacks and keep the content of the controls that are in the user control?
For instance, say I have a user control that creates a new tour record. The user clicks on the Tour item from the menu on the default page, it dynamically loads the tours user control. The user then fills out the form in the tours user control and clicks save. This is where the problem happens. When the postback occurs, the web application has no idea that the new tours user control was ever loaded. So, no save takes place because the Save button's click event never even gets fired.
I have a scenario where I have two data grids (both dynamic) to be loaded onto a page. However, the data that needs to be shown on one of the grids has no dependence on the data of the other grid. So, when fetching the data, I want to fetch it in an asynchronous manner and bind that data to each of the grids individually. Currently we have a code like
GetData(ForGridOne) ; GetData(ForGridTwo);
I want to make these calls asynchronously so that in order to load the page, the time taken would be lesser. What should be the ideal way to go forward with this ? One more thing, we would be hosting the application in a portlet which doesn't support AJAX.
I am having a gridview in which there are many columns. The Last column is button column with command name as Select.
In row command event, I am creating a webreqest instance and passing the url of the required page in my application, and based on the response status code, updating the column value for that particular row.
This is working.
What I want is this should be asynchronous. Means, if I click the first row Select button, then it should fire and process request. Meanwhile I should be able to click other row's Select button, even if the previous button's click event is still in process.
Means the communication should be asynchronous. Even if
I have a gridview with scroll enabled. Means i have a gridview like this-
[Code]....
I want during postbacks scroll position of my gridview will not change. I have tried many articles on the web, but in some scrolling is retained only in IE, in some others scrolling position changes on clicking edit link of gridview. I want a good solution for IE, FF, Chrome
In the Page_Load() event handler for one of my pages I use the new statement about 100 times equating to memory allocation for about 100 objects. As follows:
using System.Web.UI.WebControls; Table mytable1 = new Table(); TableRow [] myrows = new TableRow[5]; TableCell [] mycells = new TableCell[100]; int i; for(i=0; i<5; i++) myrows[i] = new TableRow(); for(i=0; i<100; i++) mycells[i] = new TableCell();
My question is, should all of these new statements be enclosed like so:
if(IsPostBack==false) { // Initialize all controls for page just once during the session }
Or should the Controls be freshly allocated, initialized, and added to the page each time the Page_Load event handler is called? I personally don't think its efficient to create mytable from scratch every Page_Load since all I really ever change is the contents of the table and not the table itself.
On a dashboard page I'm loading several controls dynamically; the controls always need to be loaded so there is no if (!Page.IsPostBack) code. The problem though is in that in the code-behind, we are using Request.Form.GetValues and a particular dropdown field's value is always null (presumably because the controls are being cleared and reloaded on a postback) and this is triggering an error later on in the page that expectes a value from this dropdown. I have to use Request.Form.GetValues because the page enables dynamically adding rows (each row containing 5+ HTML inputs) via Javascript.
If I check for postback, then the button event of the control does not fire at all but instead the dashboard page is reloaded, and no controls are loaded at all (i.e. the page is blank).
How do I get around this issue? I need to dynamically load the controls at all times, but I also need to retrieve the values via Request.Form.GetValues.
(Server-side, in ibtnGetQuote_Click - this is actually a loop since user can append multiple rows; "i" is appended to the word "Class" to find the exact row)
IList<string> classes = this.GetFormValues("Class1"); // This will return null all the time... private IList<string> GetFormValues(string clientID) { String[] values; values = Request.Form.GetValues(clientID); if (values == null) { Control ctl = FindControl(clientID); // uses built-in FindControl method values = Request.Form.GetValues(ctl.ClientID);......
The original code was hardcoding the "ctl00$xx$xx" stuff, but the control may or may not be loaded so we cannot guarantee the name the control will get. In fact, I'm not even sure if this will work for all scenarios since only the FIRST control is a server control, the rest are just standard HTML controls so wouldn't have a "ClientID".
Can I dynamically create controls in Silverlight without a postback to the server (even an asynchronous one). Does silverlight drag-n-drop requires postback?
I'm asking this because I've an asp.net application where I dynamically create/delete lots of controls. So after the postback I'm getting error with view state stating that the control tree doesn't match the view state tree.
I need to do a database persistence asynchronously. So am using BeginExecuteNonQuery and EndExecuteNonQuery methods.
IAsyncResult Async = cmd.BeginExecuteNonQuery(null, cmd); --code--- int number= cmdE.EndExecuteNonQuery(result);
Now this will work if i want to update or insert. Now what i want to do is, i need to insert values in a table and i need to retreive the identity column value for the values which are being inserted. So once the values are inserted, how do i retreive the identity column value corresponding to those inserted values. Here am passing null value in BeginExecuteNonQuery method. So what change should i do to retreive the last identity value.
I got a requirement where i need to persist 1,000,000 records/min into database Asynchronously...i Binged some wat on this topic...and i got an idea like.. do the persistence in a method which will be called like "Fire and Forget"...In that method have a queue which will takes all the record....and persist the record one by one from the queue.. I dont know whether Im right or Wrong...
I want some more inputs and references to read more about the Asynchronous DB persistence or retrieval..
I'm displaying a table based on query results, and each record has a dynamically generated dropdownlist and submit button (and other controls, but this is simplified). That part works fine, but how do I reference the controls in a function? Here is the code I've tried. Create the controls:
[Code]....
Reference the control values (hopefully):
[Code]....
The function SubmitAction_Click fires when I click the Post button, so that part works. I just can't figure out how to reference the selected value of the dropdownlist. You can see that I'm explicitly giving the DDL a unique ID (DS_RecordID). I'm guessing I have to use FindControl to reference it, but I don't know how to format the code.
I use ASP.NET C# with AJAX Professional (http://www.ajaxpro.info)1) I have a div container with Panel control, Panel control should hold DropDownList that will be generated in codebehind function:
[Code]....
2) I have a JS script function "getDDL" that sends data to codebehind function and then it receives response with generated Panel and DropDownList controls:[Code].... 3) Codebehind function "GetDDL" must return generated DropDownList inside the Panel control:
[Code]....
So the problem is when I try to get the generated Panel and DropDownList through the JS response I receive only the text "System.Web.UI.Design.Panel" or something like that, tried to generate only DropDownList - similar text shows up "System.Web.UI.Design.DropDownList".But when I call a codebehind function to get these two controls I see them without any problems. Why I can't get them through JS? I do everything fine, debugged million times and didn't see any problems, I can't figure out what's wrong with JavaScript?
The server produce an error that says that I must establish the property ID to itemPlaceHolder in a control of the ListView.... but I have done this !!!
Just to be sure.. ive added a GridView and i was wondering if it was normal that it is generated as a floating element? Because, i had to use a clear: both after in order to write on the next line.. cause the text was displayed at the right of the GridView even with a <br>.
I have following code and Javascript in my aspx page and my aspx page has a master page:-
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <script language = "javascript" type = "text/javascript"> function GenerateNew() { var tblRow = document.getElementById("ctl00_ContentPlaceHolder1_tblRow"); var tr = document.createElement("tr"); var td = document.createElement("td"); var txt = document.createElement("input"); var theValue = document.getElementById("theValue"); theValue.value = parseInt(theValue.value) + 1; i = theValue.value; tr.setAttribute("id", "tr" + i); td.appendChild(txt); tr.appendChild(td); tblRow.appendChild(tr); } function RemoveRow() { var tblRow = document.getElementById("ctl00_ContentPlaceHolder1_tblRow"); var Val = document.getElementById("theValue"); for (var i = 1; i <= Val.value; i++) { var RowToBeDeleted = document.getElementById('tr' + i); if (RowToBeDeleted != null) { tblRow.removeChild(RowToBeDeleted); } } } </script> <asp:Table ID="tblRow" runat="server"> <asp:TableRow> <asp:TableCell> </asp:TableCell> </asp:TableRow> </asp:Table> <input type = "hidden" id = "theValue" value = "0" /> <input id="Button2" type="button" value="Insert Record From JS" onclick = "GenerateNew()" /> <input id="Button3" type="button" value="Remove From JS" onclick = "RemoveRow()" /> </asp:Content>
This JS code generates a dynamic textbox and adds it to the existing table <asp:Table>. It works perfectly when I run it locally, however it doesn't work when I put it on the server.
This issue is only with IE, other browsers like Firefox and Chrome works perfectly fine locally and at server but IE works only locally not at the server. I am using IE 8 (OR 8.0.6001.18702 to be precise) and IIS 5.1.
Two questions. First, is HeaderStyle-Width a preferred/best way to manage column width in a grid view? And second, how do I suppress the genration of the the additional code?
Tried several different ways to do this but am just not seeing it. Proably a quick solution for someone more skilled than me.
I have a gridview generated from a datatable. One of the columns is "client name" whose data is generated from a class.
I added a link button for the column header that fires a sub that should sort the datagrid, but is not.
Here is the code I have so far that creates the gridview which works fine:
Private Sub PopulateCaseListGrid() 'Kill the existing DataSource, in case of a page reload gvCaseList.DataSource = Nothing 'Create a datatable with whatever column you want to use
I would like to save some data for use after a page postback. Here is an example of what I'd like to do:
Partial Class TestPage Inherits System.Web.UI.Page Private _CategoryID As String = "" Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then _CategoryID = "ABC" Me.ViewState("CategoryID") = _CategoryID Else _CategoryID = CType(Me.ViewState("CategoryID"), String) End If End Sub End Class
I've tried both session variables and view state. The page loads fine initially, but on postback I get the following error:
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
What am I doing wrong? How can I save this data for use after postback?
I am having a problem with postbacks on my live server.I have added a button to my page with postbackurl="google.com when I press the button it is doing nothing but If I put response.redirect("google.. in the code behind button click event it will work?Is there an simply reason that the postbackurl is not doing anything?