Do I need to get rid of a postback or? - c#

I've got a problem with my code.
I have this in my page load:
result = objdboDoc.searchFattura(Convert.ToInt64(Session["id_utente"]), id_cliente);
what does it do?
Well I have a gridview on the top of the page which shows me all the invoices a user submitted for a customer.
so I call the stored procedure "Look for invoices" made by "user", to "customer".
I have an another gridview in the middle of the page with all my customers.
When I click on "Select customer", the page is being posted back, and then I get the id of the customer I want to show my invoices for.
Since the page is posted back before executing the "Select customer" command, when I click select I still have the invoices of the old customer.
Only if I click select again I get the right customer's id
It's mind blowing because I need
result = objdboDoc.searchFattura(Convert.ToInt64(Session["id_utente"]), id_cliente);
to load the invoices of the customer selected in the previous page

first, the page is not posting back before "Select Customer" it's posting back because of the click.
After you process the select from the middle grid and choose a customer I assume that someplace you are setting Session["id_utente"] which is used by the first grid. after setting the session variable it should just be a matter of rebinding the first grid with a call to DataBind.
Page Life Cycle

Related

How to get the id of specific field in tabel asp.net c#

So i have a transaction table that contains only the transactions that haven't been confirmed yet.
it contains the transaction number (PK), the transaction status which is pending, and the confirmation (which is a button for uplouding a picture of the accomplished transaction). what i need is, if the user uplouded the picture, the tranaction status will change to accomplished according to which tranasction the user chose.
I do not know how to connect the uploud pic button with the transaction number. I tried to connect them by the id and retrieve the id but it didn't work. i did 4 choices of tags (, , and asp:Button) and tried to retrieve it with request.form("name") just to test if its retrieve something, but it returns nothing.
Do you have a single button separate from the table, or a button for each row in the table?
If there is a button in each row, then assign the transaction ID to the Button as a CommandArgument. Assuming you load the table from a database, it could look something like this:
<asp:Button ID="ConfirmTransaction" runat="server" CommandArgumant='<%#Eval("TransactionNumber")%>' OnClick="UploadPicture" />
Then you can retrive the CommandArgument of the button in the OnClick event and use it in your update statement.
But as said above, you could post a snippet of how your table and buttons look like, as without seeing it it's hard to give a proper answer.

Keep selected values in multiple nested dropdown after return to view

I have view with 2 nested dropdown lists that filters data from database and show filtered result in a table.
In that table, i have an link to another view that shows details for selected database record.
Is it possible (and how) to keep selected values of master view dropdowns after user click on a "back" button in browser when viewing details view?
you should use viewstate
dont use session it is heavy weight object so take more loading on server
Why not put it in a Session
Request.Session["Value1"] = "Your value"

MVC 4 Submit button in each row of a "grid" - how to?

How can I have a submit button in each row of a "grid", where, when that button is clicked, I can POST three pieces of data in the row to the controller?
Here's the scenario:
A screen shows my system's users in an html table "grid". One link in each row says "Associate Customer". This goes to another screen showing a list of customers that this user can be associated with. Their UserID is in the URL like AssociateCustomer/14
On the second screen, I want to display in an html grid, CustomerID, CustomerName, and a link/button that either:
Says "Associate" if they aren't associated with that customer, or
Says "Disassociate" if they are already associated with that customer
I got that much working, but I don't know the next part: when the user clicks a button on the grid, I need to pass CustomerID, the UserID, and "Associate/Disassociate" to the controller. How can I do that in an MVC way?
Something like:
# Html.ActionLink("Click Me!","Associate","SomeController",new{userId=item.UserID,customerID=item.CustomerID})
You don't have to post the form to do what you are asking (though that would be one way to do it).
Generally you won't post the form in this case.
I would create Associate and Disassociate actions in your controller that accept the parameters you require as querystrings. Then build an ActionLink for each row of your grid that builds that appropriate URL.

Transferring DropDownList values from one page to the next

I have 2 pages, both with 3 similar DropDownLists. The first DropDownList needs to be populated before selecting the second, and the second before the third (which then populates a gridview).
Usually, a user will view data on one page, click a button, and then view data on the next page (usually with the same DropDownList selections). Is there any way to have the dropdownlists pre-populated with their old selections?
You can pass values from one page to the other using the PreviousPage parameter that asp.net provides you. A small example:
You set the second page on the submit button as:
PostBackUrl="SecondPage.aspx"
On SecondPage.aspx you declare where you can get informations
<%# PreviousPageType VirtualPath="~/FirstPage.aspx" %>
and you get them by...
if (Page.PreviousPage != null)
{
if(Page.PreviousPage.IsCrossPagePostBack == true)
{
// and get the controls of the previous page as
var SomeVariable = PreviousPage.DropDownlListId.SelectedValue;
}
}
Some reference.
Cross-Page Posting in ASP.NET Web Pages
ASP.NET how to access public properties?
Cross-page postbacks and back again retaining data from source page
Cross-page posting. Is it a good pratice to use PreviousPage in Asp.net?
If you have the form where the button that the users click post to the second page, the second page can look for the values of the DDL and set them on page load.
There is a way:
pass selections to the second page either via Session or Query String
populate first dropdown
select appropriate item
repeat 2-3 for the rest of dropdowns
If you're looking for a magic solution that just "does that", I don't think this is possible.
p.s. You might rethink your design (if this is an option) and have the grid on the first page; bind the grid when user selects a value from the last dropdown (make sure you have AutoPostback set to True on your last dropdown in order to trigger the final postback)

Design Question - DataSet or List - Update Changes

Not sure if I have the correct subject line. Here is my issue. I have a form with 2 GridView. One GridView has a list of all zipCodes. The users is to select a location from a dropdown list, then select the zipcodes he/she wants to be assigned to that location and then click the "Add" button. The zipcodes then appear in the second GridView. When the user clicks the "Save" button, the data is sent to the database. The is also a "Remove" to remove zipcode(s) in the second GridView.
How do I track changes only in the second GridView. There could be 1000's of zipcode in the second GridView. Do I just remove and re-insert the list for that location evertime the user click save? I was thinking of using a DataSet, add DataRows and then update, however I am not using a DataAdapter to load my dataset, so there is no way for me to use DataAdapter.Update(ds). I am using the SQLHelper.ExecuteDataset(parms)
Any ideas?
Anyone?
Forget Dataset. Dataset is a nightmare. Instead use a BindingList.

Categories