Ways to detect changed account/no account found in ASP.NET/C# - c#

I have an ASP.NET page where at the top of the page is a search box. There are 2 text boxes - one is an autocomplete extender for the Name on a database, and one is just inputting the ID.
The page features DetailsViews and GridViews primarily, and even when no account has been searched for, these display blank data which is not ideal. I sort of fixed this by using if (IsPostBack), encasing the elements in a placeholder and setting it to visible only if the page ispostback. But this doesn't cover if the user types in an incorrect ID.
Also, some accounts have huge amounts of data inside the GridView's. I had an issue where because I have no way of detecting when a data source's rows has changed, I end up binding whenever the page loads (Page_Load method). I've come to realise this is simply very bad - there are lots of times when the user can click various things in the page and have the page postback, and it takes an eternity to load each time I click something for accounts with lots of data.
Anyway, my question is essentially two-fold but I have a feeling the solution will be similar:
1: How can I detect when there are no accounts returned when searching, and disable the Grids/Detailsviews and show an error message?
2: How can I figure out when the user searches for another account and only rebind the grids after that has happened?
Thanks

This method is very ugly but it'll get the work done.
1) To Check whether there are no records; after the AutoComplete Extenders Webservice is called if no record is returned put some value in Session like
Session["NoData"]=true;
if Records are found then;
Session["NoData"]=false;
after the webservice is called do ajax request to check that session & on the basis of value do what you want.
2) You can achieve this also by following the above option.

Related

detailsview does not show all data in one page

I am trying to show the sum of totals for different kind of invoices on a web page.
I am using detailsview control, however it does not show all the data in one page. When I enable paging the other types of invoices can be seen on 2nd and 3rd pages.
My SQL command is:
SELECT CARI_HESAP_KODU, FATURA_TURU, SUM(KDV_MATRAHI) AS TUTAR FROM LNX_STD_6_016_01_SLSINVOICES WHERE CARI_HESAP_KODU=#mKodu GROUP BY FATURA_TURU, CARI_HESAP_KODU
When I run it from SQL I get the proper results:
But when I run the page and test detailsview I get:
So I have two questions:
1. Is it possible to show the results as columns (as in SQL view) instead of rows?
2. Is it possible to show all the records in one page?
Thanks in advance.
As stated in the comments by Esko, the details view only shows one record at a time. The details and Grid views are fast easy ways to display data, however if you wanted to customize how data is displayed, a more generic repeater would be the next logical choice, you would just have to do the formatting yourself.
Check out his article or google "asp.net repeater":
https://msdn.microsoft.com/en-us/library/zzx23804(v=vs.85).aspx
When I used to program in web forms a lot, I used repeaters even when a details or grid view would have done the job, because they are much more flexible and easier to maintain when someone asks for changes.
Cheers.

Active Reports - Find out what page a control is on before the final print

I need to find out what page a control is on after all the report data has been added. Depending on how much data has been added above (e.g. table rows), the control could be on page 1, 2 or even 3. The reason for needing the page number is to find out if that control straddles two pages. If it does then I want to nudge it down enough to make sure its not split over two pages
As the control in question is dynamically added during the ReportStart event I can't tell what page it will ultimately end up on as the report data hasn't been added yet.
I'm pretty sure i'll be able to do this in the Detail_BeforePrint event as it fires for each page of the report and this.PageNumber gives the current page.
Inside Detail_BeforePrint I can find the control using:
var myControl= this.Detail.Controls["MyControl"];
But myControl does not have any properties that might suggest what page its on. Can anyone help?
I'm using Active Reports 6 and Visual Studio 2010
What you're asking for is not possible to find out. You can retrieve the pageNumber from the report but that would tell you the last page the control will print to. The control does not have a page number because it is possible for it to print on more than one page.
However with that said, it is possible to get the effect you want using KeepTogether property. if you set it to true, AR will always try to keep the control on a single page and move it automatically for you. And it handles the case where the length of the control might more than a single page so it wouldn't need to be moved since that would have no effect. Hope this helps.

Returning the gridview to its original vertical location after the rowediting postback

Using a combination of asp.net, jQuery, and c# and stored procedures.
I have successfully created a gridview, which I then apply jQuery datatables plugin to provide text column filtering (I disabled most of the other datatables function/settings off)).
The Gridview works as expected and when I make use of the RowEditing and RowUpdating events also, IE the editable fields update nicely.
If the user clicks and edits, then clicks the update link, the database is updated and the page reloads. now if that person has scrolled down say record 50 (half way down for instance) in order to locate and then edit that record, then after the page refresh, the user then has to scroll back down to find that same record.
I'm trying to find a way of returning the user to the same location (record) that they had just edited before the page refresh after the page refresh.
I found a very simple solution to my problem with out a load of coding and it turned out to be MaintainScrollPositionOnPostback="True" page directive.
Unless I've misunderstood; your dilemma is nothing to do with gridviews etc, and is all to do with merely maintaining page scroll position on post-back... have a read of this JavaScript solution from the 4 guys
P.S. Google is your friend

Don't post back textbox

I have a fairly complex form (user control actually) with one textbox control on it that needs to NOT post back. Is there a way to remove a control from the post? Yes, this textbox is editable.
More info: This is for a credit card processing form, so the "final" submit will post to another site's page. However, prior to this there is plenty of server-side processing that goes on. I know that I can move the the credit card number text box to another page - but this requirement came very late and I'll trying to not have to re-work a lot of things.
The easiest way would be to use an html input as opposed to an ASP TextBox. These are not accessible from code if runat="server" is not set on them.
Or use the viewstate property (http://msdn.microsoft.com/en-us/library/system.web.ui.control.enableviewstate.aspx)
So the situation is that you have a form that is rendered in the user's browser with an action pointing to a different site and you need to make sure that one of the form fields will not be sent when the form is submitted.
Sounds to me like you cannot in that case make absolutely sure that the value is not posted. There are many different possible ways to solve this using javascript (disable input, clear value, etc before submit) but if scripting is turned off I think you're out of luck.
But since you can prepare for sending the form to the other server (change action on form or enable button with PostBackUrl), I guess you could also then set the Enabled property on the textbox to false. That would mean that it can no longer be edited on the final page beforr posting to the other server. Or you could hide the textbox a (so it's not renered at all) and show the field as a label or literal instead.
But even then you still have to somehow make sure the secret value is not included in the viewstate of the form. Which it will be in case you use a label or literal. And also for a textbox that was disabled or hidden on the last postback. Normally the viewstate is just a base64 encoded string so it would be trivial to find the credit card number from there. You could probably fix this by turning off viewstate for the control in question (or even for the whole page) in the last post back to your page before setting the form up for posting to the other server.
If you cannot tell for sure which will be the last postback to your server, then I think you're out of luck without more significant changes. Sorry to be a downer. Some seemingly trivial things are just hard with Asp.Net web forms.
Maybe you could add a separate page that you populate with just the data that you need to send to the other server and have that a sort of "Confirmation page". In that page you could turn off viewstate, show all the data summarized (using labels and literals etc) and the actual data to post could be included in the form as hidden fields. Then that form would post to the other server when the user "Confirms".

ASP.NET 4.0, ScriptManager and HistoryPoints

I've got an ASP.NET 4.0 site. In the site there's a treeview control inside an UpdatePanel.
Keep in mind - when the user first visits the page, no postback has occurred (more on this in a minute).
When the user clicks on nodes in the tree, it triggers a postback. I can set history points as the user is moving through the tree - that's not a big deal. The history point is the ID of the selected node. (I want to use this to drive other information on the page)
There are two behaviors I'm seeing, and I'm stumped as to how to rectify these:
First, the history points always seem to point to the current item. If I start on Item A, then click Item B, when I hit the back button, I wind up at Item B for a couple of clicks (as if the history points are all set to the same value). I thought the history should be a running list of the nodes the user clicked...but in this case, it seems like the list is always a collection of history points with the current ID. (If anyone knows how to expose the collection of history points in the scriptmanager, I'd love to hear how)
Second, and more of a headache, is that when the tree initially loads, there's no postback. Is there a way to set a history point without an Ajax postback? (I'd like to have a way to preserve the default state for the tree, but right now going to item A from the root, then clicking back takes the user to whatever page they were on before the hit my page)
Has anyone else noticed weird behavior with the ScriptManager's history points?
I've also thought about alternatives - like viewstate, hidden fields, cookies, session variables...but I haven't had any luck with any of the solutions I've tried. Is there a way to get the back button to work without the history points? (I don't think there is)
To set a history point without a postback, you call ScriptManager.AddHistoryPoint().
I would venture a guess that adding your history points is not the problem, but in the ScriptManager.Navigate, you are not correctly loading the state back, or maybe you are relying on session information that has already been updated to Item B.
One way to see what is in the history state is to give each history entry a name/title that is descriptive enough to identify the state of the page. For testing, you could use a shortened version of the state string hash or just build a string to identify the state of the page and then when you click and hold the back button to view recent browser history, you will see the pages with descriptive names to identify them.
Here's the MSDN page talking about that: http://msdn.microsoft.com/en-us/library/cc472966.aspx
BTW: Sorry I'm late getting to this question. If you are still having problems, post some code so we can see what you're doing. I have implemented the history point functionality on pages with the tree control in an update panel on several of my pages.

Categories

Resources