Save button functionality getting fired before updatepanel code updated - asp.net

I have an updatepanel with multiple Dropdown. When user select value from the dropdown and hits save button (which is outside updatepanel) immediately, the dropdown previous selected value data is getting displayed instead of loading new value data.
So how to stop postback (save button) until updatepanel data gets loaded.
Thanks in advance.

UseSubmitBehavior="false" on the button will stop postback from happening.

Related

How to bind TextBox from DropdownList in ASP NET without page refresh

I have a dropdownlist control and a text box control in asp.net. dropdownlist is getting data from database. suppose some data are x-ray,USG,MRI and their value are 100,200,300. So if i select x-ray from the dropdown i want it's value 100 binds at the textbox without page refresh. How can i do this??? Please Help.
Using .net, to have something happen on the server side when something is selected from DropDownList, having property AutoPostBack=true is required. This means when you change the SelectedIndex, the page refreshes (postback), then the SelectedIndexChanged event is fired.
Theres a few approaches. In your page_load event, put everything you want to happen on the first page load in If Not IsPostBack Then ... End If block. Then when a PostBack happens, like DropDownList_SelectedIndexChanged, the code in If Not IsPostBack Then won't happen, because it IS a postback.
The above approach still has a page reload, but you can choose what happens when its this type of PostBack page reload. You may have javascript thats re-firing, though...
The second approach would be to have no postback event happen from the dropdownlist, and handle the Binding of the selected item in DropDownList to the TextBox with javascript.

Can't change ImageButton tooltip or style on GridView fired postback event

Hi I'm having a really strange issue here. I have an ImageButton and Gridview, both of which I create on runtime. The Image button is a seperate control on the webform and is not linked in anyway to the Gridview. What I am trying to achieve is when the user completes the editing of a line in the GridView and clicks on the update row button, I perform a set of calculations on the input entered. If an error is found with the data entered, I then make visible the ImageButton which when clicked displays the error message. The function I am using to make visible or hide the Image button through
picCross.Style.Value = "display: none;"
and
picCross.Style.Value = "display: block;"
gets called on the Page.PreRender function. What I have discovered is that I am able to make changes to the ImageButton (changing the button's tooltip, setting its Style's value ) during a postback not fired by the GridView, such as when the user clicks on a button else where on the web form. If however I try making changes to the Imagebutton during the post back event of the GridView, such as when the user clicks on the edit row or update row button/link. The changes are not saved. What is even more strange is I do not have such an issue with labels. I can change the text of labels regardless on whether the change was made during the postback fired off by the Gridview control.
I have tried setting the ImageButton's EnableViewState to true and false but neither makes a difference. I have tried the same approach with panels and the same thing occurs, I can't change its properties during a postback caused by the gridview. My GridView has EnableViewState = True
P.S I'm binding the GridView on runtime too. Only my GridView's RowUpdating event fires. The RowUpdated event does not fire. I was hoping to try changing the ImageButton on RowUpdated, not that I think it would have made much of a difference anyway.
You should create the dynamic controls (Gridview and ImageButtons) in the PreInit event. Init event if you have a Master Page.

Can I fire button click event without firing pageload event?

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?

Gridview populates on second time clicking the button

I have an updatepanel. Inside that i have some controls for selecting search criteria. For search button onclientclick iam calling javascript functon for validation and in onclick iam calling the mathod to populate the gridview. On clicking search first time it is not loading the grid and clicking the second time it populates.
Remove from the updatePanel your code and checks for errors on the first click, then place it again.
Its probably have to do with your viewstate that is not populate correctly so your first click gets an error that you do not see because of your updatePanel.

onclick event not working after ASP.net AJAX save

I have an gridview that I am adding onclick events to a checkbox column via:
cb.InputAttributes.Add("onclick", "checkClick()");
everything works fine, but when the user clicks the save button on the form, (which is within the updatepanel), suddenly the onclick event of the checkboxes stops firing!
Is this a problem with the ASP.NET AJAX?
The weird thing is that I am seeing the onclick event on the source, it just doesn't fire.
Help!
The source will show you the state of the document when first received from the server, not the current state of the DOM. What is likely happening is the update panel content is being replaced by new HTML content. The elements to which the original click events were bound are no longer in the dom.
The onclick events will need to re-bound to wire-up to the new elements that have arrived.

Resources