How to update only the part of page - asp.net

I have several combo boxes and labels. when a user select any item from the combo box, the corresponding value will be retrieved from database and will be shown on the label. I have done these part successfully.
But my query is, when I select any item from the combo box, the whole page posts back to the server (AutoPostBack set to True.)
is it possible to post back only a part of page not the whole page (i.e. only combo box controls may be posted back to server instead of whole page)?

You could use AJAX to achieve that. In ASP.NET there is the UpdatePanel control which might help you.

Related

ASP.net Using a Session Varriable to move a GridView SelectedDataKey to another page

Help please!
I am pulling out what little hair I have left over this and can't find an answer.
I am attempting to move the selected row in a grid view to another page and use the SelectedDataKey or the primary key value of the selected row to indicate what data should be displayed in a grid view on another page. This is the last little bit of a school project that I can't figure out.
What I am doing on the first page is to use a button click event to set a session variable that looks something like this. Session["Select"] = GridView1.SelectedDataKey; The button will then send the user to the next page. Response.Redirect("CustomerAccounts.aspx");
Once on the next page I want to use the primary key selected on the first page to show only the data with a coresponding value on the second page by using a where statement in the next gridview. So I am setting the [CustomerID]=? Session("Session["Select"])
Am I setting up the where correctly in the second gridview?
I like setting up such things with querystrings.
I made a video tutorial on youtube doing just that a while back
http://www.youtube.com/watch?v=HRjZ_0JpO2M&list=UUgtKyNvllU9E6c2Mi8OtzCQ&index=5&feature=plcp
I also made a tutorial showing how to load the detail gridview nested in the master gridview with jquery
http://www.youtube.com/watch?v=nJp14o_1wZQ&list=UUgtKyNvllU9E6c2Mi8OtzCQ&index=4&feature=plcp

Asp.NET AJAX control update field on form

I have a form with several text fields, a couple of drop down lists, and a custom asp.net control.
The requirement I have is that when the values of certain fields ( some are in the main form, some are inside the control ) the user will be alerted that the settings will not take place unless they also restart the processing and will have the option to reset it. If they exercise this option by pressing on the restart button, we execute an additional restart() method call on the server side on top of everything else.
In order to create this alert system I need to know when these required fields have changed. For the fields in the main form/page I store the original values in hidden fields when the page gets created (possible because the page is static). Then when the submit button is pressed I check the current values against the original values stored. If any of them differ I will alert the user.
For the fields in the custom control, I created a boolean property that indicates whether changes in the fields of interest took place. This control is highly dynamic contains a variable number of lists, some of them with over 100 items that can be selected or deselected. So this boolean property is able to identify if the changes I am looking for took place.
The problem is I need to get the value of this property when the user clicks on Submit, otherwise it will not contain the right value. But at the same time I want to avoid a postback. I do not want the whole page to reload. I want to get that value asynchronously somehow.
Since the whole page is stateless the question is how do I accomplish this? How do I accomplish the call to the property? And after I make the call and I get the result where do I store it so it's accessible from javascript code on the client side.
You can try putting a timer control in your ajax panel. Then on a set interval, you will evaluate the boolean property in your code behind.
Alternatively you can check the hidden field "changed" event using JavaScript or jQuery
http://api.jquery.com/change/

How to do a dual listbox set up in ASP.Net MVC?

This may be silly, but trying to do a dual list box in ASP.Net MVC. I have the client side part working fine with options moving back and forth, but what I would like is for the person to be able to save when they are done. This means I have to post all of the values in the "selected" list box. I don't want to rely on the user leaving the items selected, so do I have to pre-select them using the onsubmit of the form or the onclick of the button? Or am I missing something obvious?
I would use jQuery to get the list items and submit them as a custom postback

Alert on moving to a different page of a grid when user changes contents of textboxes in a Grid

In a ASP.NET application I have a paging RadGrid which shows up textbox in each row. Outside the grid, there is an OK button to save the content of all the textbox. If user changes text in any one or more of the textbox and without clicking on the "OK" button, tries to move to a different page number (of the grid by clicking on the page number), he should be prompted for confirmation of save or cancel the changes.
I am guessing that one can write a Javascript function which would look for any form input control (textbox in my case) and detect changes and If there are changes, would prompt the user. However, I am not sure where I can call this function from? Any suggestion on this or a better way to achieve this would be appreciated.
I am using RadGrid but I guess this should be applicable to GridView as well.
I am not sure if this will help exactly but it might at least give you an idea:http://www.codeproject.com/KB/ajax/ajaxdirtypanelextender.aspx

How do I trigger a PostBack with arguments from Javascript?

This is what I'm doing: Using jquery, I'm popping up a "form" over the page that lets the user search for branches of the company and select the one they want. When the form pops up, they can type in a textbox, and it will do AJAX requests back to the server to return the top n results for what they've entered, and those results will be put into a list for them. I want the user to be able to select one by clicking a link that says "select" or something, and at that point I want it to do a PostBack have the Branch Selector control that this is in change it's SelectedBranch property to the newly selected branch. I've got this all working right now with a hard coded list of LinkButtons, but how do I do the same thing with a dynamic list of links inserted with jquery?
Look at the HTML that gets emitted for your hard coded LinkButtons. You'll see that each one calls the JavaScript __doPostBack function when clicked. I believe this function takes two arguments: a control ID and an extra command argument you can use for your own purposes.
I would suggest adding a single control to the page whose only job is handling events for the dynamic links. Then, when you are creating the links with jquery, make each one call __doPostBack, passing the event handling control's ID for the first argument and some other string for the second argument that identifies which link was clicked. In the Click event for the handling control, look at the second argument value and do what you need to do.
The short answer is... you don't.
ASP.NET relies on the Viewstate for the current state of the controls, including items in a DropDownList or similar control. Dynamically updating a list on the client will not modify the viewstate, so will not be available on the back end.
The general workaround for this is to just add a hidden field which updates/stores the current selection via js on the client side. Then read it from this field on the backend rather than List.SelectedValue.

Resources