I have two update panels on my page. The first has a form that contains required field validators and a button that triggers the update panel and sends the info to a database. It also has a trigger for the button.
The second update panel holds a gridview that shows a few columns from the collected data. As of right now I have the gridviews update panel set to conditional and its trigger is the button that submits the first form. It's supposed to work on the click event, but the gridview isn't updating.
In other words, I want the gridview to update when I insert a new record through the form in the first update panel.
In the code behind for the button that submits the form add GridView1.DataBind(); at the end. Now changes will be reflected automatically in the gridview. Pretty neat.
Related
ive got a ddl in a gridview with two values: 0 = no and 1 = yes. I've also got an event on the dll SelectedIndexChanged so when the user selects 1 then it shows a panel with a form in it. the form has two buttons: submit and cancel.
what i'd like to do is when the user selects cancel reset the ddl in the gridview back to 0.
I have an event on the cancel button and can hide the panel with the form but I'm not sure how to find the ddl that triggered the event to show the panel. do i need to use the row datakey such as the id?
When your SelectedIndexChanged event occurs, note down the row index - in which the DropDownList is present - for example saving the row index in a hidden field. Then when the cancel Button is clicked, use that hidden field, extract the row index, find the DropDownList in GridView in that row and reset it.
Hint: Use Control.Parent to find the host of a control, for example CType(mydropdown1.Parent, GridViewRow).RowIndex
However doing all this through JavaScript would be much better, in this way your user would NOT experience the server round trips on each click, but obviously requires good grip on JavaScript.
I have an update panel that includes a dropdownlist control and a detailsview control. The dropdownlist is populated by a sqldatasource control which grabs the data from a table called Places (just a list of venues). The detailsview is insert mode only and inserts places into the database table that populates the dropdownlist. I am trying to allow someone to insert a new place inside the update panel and have the dropdownlist refreshed at the same time so the user will see all places in the dropdownlist, including the one they just added with the details view. Right now, the detailsview is adding the place to the database properly but not updating the dropdownlist. If I refresh the page after adding a new place, the droplist updates with the new place. Any suggestions?
Disclaimer: This answer was posted before any code was posted in the question.
This also assumes both controls are inside the update panel.
In the event handler for Updating or Inserting for your DetailsView control, you need to add the following code:
MyDropDownList.DataBind()
And, worst case scenario, you can do this if the update panel is causing you problems. It's not the greatest performance-wise though.
Response.Redirect(Request.RawURL)
This is what I'm trying to do with AJAX:
[DropDownList]
I have a DropDownList (not inside an UpdatePanel), populated by different Products to "Add" to the database.
[UpdatePanel #1]
Below, I have an Conditional UpdatePanel that listens for "SelectedIndexChanged" on the DropDownList, when that event is triggered it adds TextBoxes to a div "productForm" inside the UpdatePanel. It creates the Form according to the Product to add.
[Button]
Below the UpdatePanel I have a button that "should" submit the form above.
[UpdatePanel #2]
I have an update panel that listens for the event on Button "Click" event. I also have a div in the ContentTemplate that should post out data that was submitted from the "Add Product Form" in the first UpdatePanel.
The thing is, when I submit (and the Controls are still visible in the first UpdatePanel. It can't read the data from the TextBoxes becaus they aren't there. Also, if I try to add all this to the same UpdatePanel, the Controls disappear whenever I click the Submit button.
Any ideas how to make something similar work?
Without the code I can suspect that when you dynamically populate first div on dropdown selected index changed event, since its within update panel, viewstate is never made aware of new controls and on submit can't post them back to server.
I've had some bad experiences with update panel and never use it other than very simple scenarios. Try getting familiar with jQuery ajax. I would do what you want to do using jQuery and web methods.
I have a button on my page and and few textboxes which alters their context on page_load event. when I open the page for the first time it loads random data from a database to textboxes with a function in pageload and also I create those textboxes dynamically. what I want is to make some changes on textboxes texts and click the button than send new context of textboxes to database. But when I click on button, PageLoad event fires again and It regenerates the textboxes and the context of them alter naturally since they are newly created textboxes. I tried to use "if(!Page.isPostBack)" in pageload but then the textboxes and related objects are not being created and they become null.
how can I overcome this problem?
best thing I can think of is to find some way to fire buttons click event without firing PageLoad event, but I dont know how can I do it.
any help would be appreciated;)
From Comments
Can you regenerate the Textbox on each Page load Execution? and data assignment to these Textbox should be under !Page.IsPostback. All you have to do is to keep the IDs of the Textbox in ViewState only first time page load and next regeneration of Textbox will have the previous stored ID and you also have to store the ID corresponding data in ViewState. Makes sense?
I have connected GridView with a datasource. It works fine but it is displayed just at form load. I want to show it when user clicks the button. How to make it so?
Thanks
Try setting the Visible attribute of the GridView to false. In the Click handler of the button, set the Visible attribute of the GridView to true. Rebind and use an update panel if necessary.
If you post some source code, we can give you a working example.