Let me tell you that I am a beginner of Ajax and Jquery along with asp.net,
I have a aspx page with backend coding in c#.
I ahve a single update panel which contains a asp:table an in turn, one column contains a form with two fields and a button to add a department of the organisation, and the other column of a table contains a gridview to list all the departments of the organisation.
My problem: whenever i submit a form in the update panel,
some times it shows a message in the left column as "Department has been added successfully", and sometimes gridview will be updated, and sometimes none of the above two changes(even though the department has been added in database), and sometimes neither the changes are made, nor the department is added in the database.
After working on the same, came to know that, the second time submission of form is doing nothing. first time everything is working perfectly, but when am submitting the second department, $.POST() is not working.
I'd make it work without an update panel. Make it work without ajax (step through the code), then add the .net ajax components afterwards. If you're a beginner, it helps to break the problem apart, start small and add fancy features once the core functionality is working.
Related
Fairly new to MVC Core and have a View which contains two forms and a single button within one of the form tags. I have a ViewModel so that I can pass multiple objects in and out of the View.
The problem I am seeing is the button only POSTs back the contents of the form it's within and not the data contained within the other form on the same View, even though it populates the ViewModel correctly; I have tested this by putting a button inside each form and depending on which button you have clicked, that form's data is passed back to the Controller.
As a newbie, I assumed that once the property within the ViewModel had been populated the POSTing back of the submit button would capture all entered data - this is not the case.
The examples I have seen seem to pertain to having the requirement for different functions within the same View (eg. Login/Register) but I would like all the data collected to be passed back in one POST, is this possible?
If you want some source, I can submit but I think the above hopefully explains my problem well enough.
TIA.
This is not a problem related to ASP as this runs on your server and generates the html code delivered to the browser. It's the browser who posts back the data ... and hence when a form is submitted, the browser collects the contained input fileds and creates the post request from their data. In fact, the browser doesn't know anything about viewmodels.
You might work around that by generating hidden input fields into each form for the viewmodel's locally unused properties. This way both forms contain all data and the resulting post will be 'complete'. But from my experience, that is ugly to maintain. So I'd recommend you should consider using separate forms with separate post endpoints.
Going with agua's answer although it didn't expressly resolve the issue (if indeed it is solvable).
Apologies if this is vague or too general, I know we are supposed to ask specific programming questions, but this is to try and understand how postbacks work in ASP.NET when something is rendered on page initially, and not touched on postback, yet still appears on screen after these postbacks.
Detail: I have an ASPX page - on initial page load it sets up all the labels and controls and a repeater with thumbnails in it.
I can follow the code through as it sets up all components, which will then be rendered.
On postback, if a value has been changes (status for example), the page makes updates to database, and then re initializes the screen (calls the init method with postback set to false), setting up everything again (I think the aim was to set up certain controls like radio buttons for the status), including the image repeater again (which I think is a waste of time).
I have tested skipping the code that sets up the image repeater etc. on a status update (postback), and the image repeater displays fine in the browser - however I am not sure why - ASP.NET is stateless, so on a postback, if the page does not render all the components on the page everytime how can they persist between postbacks?
I know there is a reason out there, just can't frame my question well enough in google to find it. Does the server send back and update which the browser merges with the existing displayed page? Leaving all unchanges components as is?
The reason I need to know this, is I have a screen with a lot of images on it, and I do not want to be setting them every time unless I have to.
This link - provided by Steve (thank you very much) - was what I was looking for goes into depth on ViewState - vaguely remember reading about that when I first stated doing .NET - have completely forgotten about it, but this explains it perfectly!
Understanding ASP.NET ViewState
https://msdn.microsoft.com/en-us/library/ms972976.aspx
I have a page where users can work with their data. The page has 2 gridviews. Initially, the top grid display records that can be selected with a "check box" column and added to the other gridview with Add/remove buttons.
This works well and has worked well for years. Suddenly, now, for some datasets, clicking the button does not seem to trigger the button click event. This work for others datasets. I know this is probably a specific situation but any comment would be highly appreciated.
Many thanks in advance
B
Given that its only happening for some datasets I would suggest that its the data which is causing the problem.
check you don't have duplicate Ids
check you don't have special characters (ms word single quotes, £,# etc)
also sometimes users don't click hard enough. check they are clicking hard
Problem:
I am loading one of several user controls based on a selected tab within RadTabstrip Control which is on the parent page. I've captured the Selected Tab and assigned it to a Session variable within the OnTabClick event to use in each User Control to determine if that particular control needs to be rendered.
The reason for this is because each User Control queries a database to render different charts and I don't want unneccesary processing occuring on every post back to the server. I'd like to add that each User Control has several Labels in their Markup that only gets the Text values assigned during runtime based on the content retrieved from the database.
When I load the main page, the selected tab variable is checked by each User Control and everything works fine from that scope. (The first tab at index 0 has no Charts)
Problem is when I select a Tab which has a User Control, the appropriate code to acquire the data from the database and build the chart works fine but the TEXT value of the Label controls in the Markup don't show up on the Page, although the TEXT values are being set in the Code-Behind at the same time the data is being retreived.
If I perform a Post Back of the same page, the TEXT values of the Label controls appear.
I believe this is because the 1st stages of the Page Life Cycle which include the rendering of the Markup aren't firing on the initial loading of the User Control, but get fired on subsequent Reloads or Refreshes of the Page.
Is there a way to work around this? I am figuring a call to the Render event after hitting the database would work but I may be way off base on my thoughts.
Can anybody provide some advice or a potential solution???
Thanks
I was never able to resolve the late binding issue which prevented the text of the labels from appearing until after a manual refresh of my page so I approached the issue from a different angle. I still retained the logic that only allowed the data of each User Control to get populated if their corresponding Tabs were selected by the user, but I moved the in-line code which was embedded in my Markup to my Code-Behind file.
I was not 100% certain as to the order that the mark-up vs. the code-behind got processed, so I researched and found that anything done declaratively in the aspx page is processed first, and the objects are created before being accessed or updated in the code behind.
So with this information I totally separated the two and was able to get the Text to render on the labels without any issue.
I still would haved liked to have known the appropriate way to force a page to call the Render event to simulate or mimick a manual Postback after the initial Page_Load, but going with the flow of the Page Cycle is the much easier and probably a more preferable way to do things.
One way to approach your problem is to consider use of the "Update Panel". It will allow you to render the entire page and then on an event only refresh the area of the update panel.
Generally I would love this feature for performance reasons but there is a catch. Some browsers (e.g. versions of Safari and Opera) do not render these correctly. Is your application a web application intended for general use by consumers? If so you may need to consider a full page refresh on the same page and pass the user data (unless Opera / other browsers have fixed this shortcoming - I have not tested in in 4 months).
I am building an iPhone app with MonoTouch and it gets its data from a web service.
The trouble I am having is that the first screen gets a list of say countries. When the user selects a country it should then retrieve the list of cities from the web service only for that selected country... Once a city is selected, the user is then taken through 2-3 more screens to add additional details like text, dates etc and there is a confirmation screen on the end where all the data is collected and posted to the web service.
I am struggling to find an optimum solution and determine if this can be achieved with MonoTouch.Dialog or if I should be using standard UINavigation views.
I have tried the first list with dialog and it successfully lists the countries that can be selected and they show an empty view when selected with a back button, however I am stuck in trying to find a way to populate that next view.
Any help please?
George
There are several samples available for MonoTouch.Dialog, starting with it's own Sample application that will show you how to use every elements (and multiple levels).
Another one is Touch.Unit that shows something similar to what you want to do, i.e. it initialize its UI from a list of TestSuite (instead of countries) and, when selected, shows a list of TestCase (instead of cities). That should be very close to what you're trying to achieve.