Transfer DataTable Between RadParentWindow And Child Window - asp.net

I have a RadWindow, in that rad window there is a button that will popup another radwindow. (Inside the parent window,and it is a different page). I should be able to send my datatable to Parent radwindow after closing the child radwindow. Any suggestions?

This greatly depends on your setup and the data you need to pass. Here is a brief overview:
you have a server object and you cannot pass the data through JavaScript: Devise a way to store the data on the server (e.g., in the Cache or Session) so you can access it later in the parent page.
You can pass the data via JavaScript: In this case you can simply handle the RadWIndow's OnClientClose event to get the data and pass it to its close() method from the content page, as shown here: http://www.telerik.com/help/aspnet-ajax/window-client-side-events-onclientclose.html.
In either case, you should use the OnCLientClose event to either work with your data on the client (see this demo http://demos.telerik.com/aspnet-ajax/window/examples/dialogreturnvalue/defaultcs.aspx), or to initiate a postback on the first dialog that will work with the data on the server.
This demo will show you a slightly different way of going through the server and then performing an AJAX request to update the first page: http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandwindow/defaultcs.aspx?product=window.

Related

Getting table control programmatically

I have a table that I am creating programmatically and then adding some rows and data to it in the CreateChildControls() method.It has 2 columns with dropdownlist controls in it.Now on the client side based on selection in the dropdown I am adding more rows by copying the contents of the last row.There is a save button which when clicked invokes the below overriden function of the webpart to get the table object back..The issue is the rows that I am adding on the client side are not being retrieved..Only the rows that were created on the server side initially are being retrieved.Can someone please tell me what I am doing wrong here.
So doing this Table tab = FindControl("Main1") as Table;
tab.rows only give 3 which were initially generated on the server and does not include the 2 new that were created client side
Public Override Control FindControl(string id)
{
return base.FindControl(id);
}
Any rows added client side will not be passed to the server - that is the way in which the technology works. A better way to do this would be for the save button to generate a PostBack and add the new rows on the server.
If the new rows absolutely have to be added client side then you will need to write an ajax call to add the new rows to the viewstate server side after they have been added client side - seems like a lot of work when a PostBack should be perfectly adequate.
I believe the controls added server-side are stored in ViewState, and client-side DOM changes don't affect that. It would probably be easiest for you and the best user experience to add an UpdatePanel around your table and dropdowns, and add the rows server-side.

Avoid hidden field in the web forms

I have a web page and a modal dialog page. On clicking the save button in the show modal dialog. closes the window and returns a value. Now when the
control reaches the JavaScript function of the parent window . I wnt to perform some database operation on the basis of this returned ID.
I am using the following approach to utilize this returned value.
Keeping it in the hidden field and populating the returned value in hidden control.
keeping a hidden button in the parent window, performing the click event when control comes back to JavaScript function of the parent page. Thus in the server side button handler get the value from hidden field and perform database operation on the basis of returned value.
Is this approach fine. Or I can get rid of hidden field
That's not terribly bad provided the ID returned is not sensitive information that someone can use to modify a record that doesn't belong to him. One can perfectly manipulate this ID on the client side for any other ID and have your logic update a different record from what you intended.
If all you are doing is calling a server side method passing this ID; why don't you do the whole update from the pop-window itself (at that point you already know the ID)?
If the parent window (page) is meant to be updated; you can just perform a normal refresh of the page (ie. use window.location to redirect the user to the same page so he can see the update or use Response.Redirect to the same page.)
What you're probably looking for is called AJAX. With AJAX you can communicate with your web server from within your JavaScript code directly. No HTML form posts are required then. You might want to look at frameworks like JQuery. These have easy implementations (cross browser wrappers) to send HTTP requests via AJAX.
Note: I just noticed, you are using ASP.NET. Take a look at ASP.Net AJAX Page Methods.

close jquery UI dialog when file download begins

I am using an ASP.Net MVC site that has a link to an ASP.Net WebForms page that performs the actual download. I would like my jquery ui dialog to close when the download starts. Is there a javascript/jquery event that I can use to accomplish this?
I found an example with exactly what I want to do here, but since I'm using MVC instead of WebForms I can't seem to get it to work.
Two possibilities:
Target your form at a hidden <iframe>, and close your dialog from a "load" handler on the window object in the <iframe>
Have the client create a random string and post it with the form, and then start a polling loop to check document.cookie to see if it contains the random string. The server should set a cookie whose value is that random string, and it should do that in the header for the file being sent out. When the client polling loop sees the cookie, it can close the dialog.

ASP.NET Controls and Update Panels

I am creating a series of client side component controls on the fly that are nested inside a update panel. The first time I create the controls, everything works as desired, however, when i trigger an update on the update panel and it does a partial postback the controls come back with several javascript errors describing how the control is already registered on the page.
I get a series of errors that say something about like:
"Error: Sys.InvalidOperationException: Two components with the same id "master_ctl40_CCB_PALETTES" can't be added to the application"
Any ideas anyone?
Try these tricks:
On Page_Load put uxFailedControl.ID = DateTime.Now.ToString(); It will ensure your control has unique ID every time page reloads (fully or partially), so theoretically you shouldn't see anymore "same id" errors.
If you display your control in Modal Popup: Every time you hide the popup from the server, remove the control from it's container (Panel, Page, Control, etc.) Use uxModalPopupPanel.Controls.Clear(); or uxModalPopupPanel.Remove(uxFailedControl);
When you are done with debugging set ScriptMode property of your ScriptManager to "Release". It will prevent internal AJAX exceptions to be bubbled up to the browser.
In which event are you adding the components to the update panel? I.e. have you placed them inside the page load event without a postback check or have you placed them inside the update panel load event? etc...
Looks like your client object is being created more than once.
If you want your client side controls to be replaced when the update panel they're in refreshes, they should inherit from Sys.UI.Control, which takes takes an element in its constructor. When that element is replaced by the update panel, the client object will be disposed and then re-created. If you're currently using a ScriptComponentDescriptor on the server side to define the client control instance, you'll want to switch to a ScriptControlDescriptor.
By the sounds of it, your client objects just inherit from Sys.Component, which will hang around until they're manually disposed, which is why you're getting an error about having more than one component with the same ID.
I would advise against using a new ID every post back - this will just keep creating new client objects without ever cleaning up the old ones.

Asp.net server control same event handling order on server-side/client-side

I have an asp.net server control (with the asp: in its definition). The button has been set to do post back.
On the server side, I have the on click event handler
e.g btnSave_click()
On the client side, I have a javascript function to be invoked on the click event
e.g btnSave.Attributes.Add("onclick","javascript: return CheckIsDirty();")
Am not sure which order these two will be executed. Because I want first on the client side to warn of any data entry fields that are not yet filled-out before actually saving any data.
Any help?
First client side, second server-side.
So you can use it.
I also use it in some cases, like:
close.Attributes["OnClick"] = "return confirm('Are you sure?')";
In this case if the user presses 'No' then the server-side event handler does not even play a role.
The trick here is to set this global variable "Page_IsValid" false if your test fails and this will stop the post back.
Read this page http://msdn.microsoft.com/en-us/library/aa479045.aspx which explains both server side and client Validation. There is sone good code example you can use.
The way you are setting your onClick JavaScript event will actually prevent it from posting back as you are overwritten the ASP.NET event handler. The correct way to accomplish the validation you are intending is to:
btnSave.Attributes.Add("onclick", "CheckIsDirty();" + GetPostBackEventReference(btnSave).ToString());
Notice that you append the result of GetPostBackEventReference, so that in JavaScript you first call your CheckIsDirty() method and then call the ASP.NET postback method. Assuming your method returns true, then the button will post. If it returns false then it will not cause a post back.
Does that sound like what you are trying to accomplish?
I think you need a much better understanding of what it means client side and what it means server side and how they all relate together. I've seen more and more developers make a mess of it.
Of course the client side will execute first in your case. Actually there's no way to execute it after the server code is executed (except if you do something manually). I'll try to give a brief explanation:
Whatever you have in your server, will generate some HTML on the client and the user is always interacting on the client. So you have a html button that the user is clicking. What the browser will do is execute the javascript associated with it or if no javascript is specified and the button is a submit button it will submit the form. if you check the generated html you will see that for the onclick event you will have the script you have added followed by some autogenerated script that actually will submit the form to the server. Your server side code will execute only if the page will be submitted.

Resources