.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to DataBind in a PostBack Event

Posted By:      Posted Date: October 25, 2010    Points: 0   Category :ASP.Net


  First off I'm very new to ASP.NET. My data-binding problem is this: I have a user control that contains a DataList, withing the user control I have an array of objects that are binded to the data list. This works fine and the datalist displays exactly what I want. I have also set up an event that changes the background color of one of the controls on a click. So when the click event happens through a bubble event I change the controls backcolor and then try to call the DataList.DataBind(). This does not work when all the controls Page_Load happens my binded object from the Array is now null. All the examples I have found in code that seem to work have you recreating the data source before calling the DataBind function in the PostBackEvent asp.net step. I don't understand why this is or how I'm suppose to resolve my situation since my datasource in my user control can't easily be recreated. I hope I explained this well I have included a test program that sort of duplicates the issue I'm having. If you run this code you will not get the data list to display at all on a click event. But if you call the BindList function it will work correctly.


%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs&quo

View Complete Post

More Related Resource Links

jquery click event doesn't fire after postback anymore

Hello there,I have a small website where I want to display a confirmation dialog after clicking on a button.When you click the confirmButton the dialog appears. Then you can choose between Yes or No to either continue with the PostBack or to return.Problem: The first time you get into the site all works fine. But after you click Yes to continue with the PostBack, no click event will be triggered anymore.Here is some code.<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <script type="text/javascript"> function loadConfirmDialog() { //Dialog configurieren jQuery('#confirmDialog').dialog({ autoOpen: false, width: 400, modal: true, resizable: false }); //Dialog öffnen jQuery('#confirmButton').bind('click', function () { jQuery('#confirmDialog').dialog('open'); return false; }); //Postback ausführen jQuery('#continueButton').bind('click', function () { jQuery('#confrimDialog').dialog('destroy'); __doPostBack('confirmButton', ''); }); //Postback abbrechen jQuery('#cancel

Row Command Event (Grid View) and PostBack

I have a grid view with a number of columns in Page1.aspx.The last column is a template field with a button. On it's row command event,The control is transferred to Page2.aspx.  Initially, I had not put the PostBack property in Page1.aspx and when I used breakpoint in the RowCommand event the control never entered inside the event.However,it worked fine once I did the postback property. Can anyone explain why did this happen?  I have a grid view with a number of columns in Page1.aspx.The last column is a template field with a button.On it's row command event,The control is transferred to Page2.aspx. Initially, I had not put the PostBack property in Page1.aspx and when I used breakpoint in the RowCommand event the control never entered inside the event.However,it worked fine once I did the postback property.Can anyone explain why did this happen?  

URL Routing + PostBack not firing BeginRequest event


hi all,

we are having some weird issues with URL Routing in ASP.NET 3.5. 

We have a search box that does a search and redirects to a routed URL.

 When we search for the first time (aka Press a button that forces a postback) everythign works as expected.  we get:

1. BeginRequest event.

2. Determines Route

3. Calls Routehandler to match the route item to the actual destination page

4. Routes the url appropriately.

After you do one search successfully and try again it fails to call the BeginRequest event.  Because of this the routing data never gets called and so the url is never routed to its correct destination.   What is weirder still if we append a "/" (trailing slash) to the url after the initial postback it DOES work properly again. 

So our search route looks like this


entering a term and pressing the SEARCH button would yield a result url like this:



Going back (after 1 successful search) you then need to use this url or else BeginRequest will never fire:

mydomain.com/Search/ < (note the extra "/" at the end)


Anyone have an idea a

AjaxControlToolkit TextBoxWatermarkExtender fires TextChanged Event on every postback


I haven't been able to find anything on the net about this yet. A project that used to work fine all of a sudden started having trouble with a couple users. The TextBoxWatermarkExtenders for these users are now always firing the TextChanged event of the textboxes they are assigned to for every postback. I don't think this is what they are supposed to do. They didn't use to do this. Has anyone else experienced this? I can add code to ignore these unintentional events, but I would like to know why all of a sudden the change in behavior.

Any information about this would be greatly appreciated.


How can i safe value of variables in javascript code in PostBack event?


Hi Experts.

I need to define some Boolean variables in my javascript code and use them  when  the any onfocusout methods of controls  is fired. Like this:


            Var is_ValidateTextBox1 = false;

            Var is_ValidateTextBox2 = false;

            Var is_ValidateTextBox3 = false;

Function focusout_TextBox1()

{ValidateTextBox1 = true; }


When onfocusout of TextBox1 is fire, I want to set  " is_ValidationTextBox1=true;".  But when the post back is fired from the form, the variable reset to false because the line of defining the "Var is_ValidateTextBox1 = false;" is run again in post back!

Now how can I to solve this problem? How can i safe value of variables in javascript code in PostBack event?

With Regards. Mojtaba

Prevent postback but need to trigger an event



Is there a way that to prevent a postback on button click? But at the same time, when click on the button, it should be able to trigger a function.

I want sometime like Onclick = "runFunction", but to disable the postback.


Why is there a postback with every timer event?


The handler for my timer event checks the status of a table in my database.  If there is any change, it causes a redirection of the web page to occur so that the change will be displayed.  But, when the timer event handler ends without any change, it still causes the page to be re-posted with every tick.  Why?  How can I conclude each timer event without causing a postback, which interferes with the user's ability to scroll down and view the entire page?



Bug? OnClick event prevents postback on CommandField BUTTONs


This has been asked a few times before but I can't find a definitive answer.  If I have a delete button in a commandField and programmatically add an OnClick javascript confirm, then the page never posts back after the dialog appears.  When using the same approach using a LINKBUTTON, everything works perfectly.  Is there any way to get this functionality to work using BUTTONs??

This works fine (using a LINKBUTTON):

<asp:CommandField Visible="false" ItemStyle-Width="150" ButtonType="Link" ShowDeleteButton="true" DeleteText="Delete" />

Sub gvRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.RowState = DataControlRowState.Normal OrElse e.Row.RowState = DataControlRowState.Alternate Then
e.Row.RowState = 0 OrElse e.Row.RowState = 1 Th

asp:button Click event (inside a repeater) lost on postback.


 I have been writing C# code for about 3 years now and have never had this happen.

I am using an asp:repeater (inside an update panel):

<asp:Repeater runat="server" ID="rptRedFolderDocs" OnItemDataBound="rptDataBound">

inside the repeater I have a button with a click event with server side code.

When the page loads, the repeater is databound to a datatable popuplated from SQL connection.  The repeater is NOT bound on postback. I wanted the data to persist.

When the button is click

have collapsiblePanelExtender event call databind


using vb.net/asp.net 2005

I have an outerGridview and for each row returned I am displaying a collapsiblePanelExtender and when the user clicks on the collapsiblePanelExtender it displays the results of the InnerGridview.

My problem is that it takes several minutes for all data to be returned so what I am thinking is this:

Return a record for each OuterGridview since this is only displaying one field (a ProductCategoryID) and then when the user clicks on the collapsiblePanelExtender call some function, probably an AJAX page that will query the database and then fill the InnerGridview for the results (products) based on the selected ProductCategoryID.

has anyone done something like this?

I've done something similar with linkbuttons but never with CollapsiblePanelExtenders.



Keeping onclick event after postback


We have a 3 tab setup using css and the following javascript, if im on tab2 or tab3 and i submit the form within that tab, when the page posts and reloads, the tab defaults to tab1

Is there anyway to update this logic to keep the viewstate or would i be better off going with the tab control for our page?

        function goSearchOption(theoption) {
            for (var i = 1; i <= 3; i = i + 1) {
                if (i != theoption) {
                    document.getElementById('searchOption' + i).style.display = "none";
                    document.getElementById('nav' + i).setAttribute("class", "searchnav");
                else {
                    document.getElementById('searchOption' + i).style.display = "block";
                    document.getElementById('nav' + i).setAttribute("class", "searchnavHL");



jQuery $(document).ready() and ASP.NET Ajax asynchronous postback

Many call it the ASP.NET jQuery postback problem, but using the technique below should make it no problem anymore. $(document).ready() isn't called after an asynchronous postback. What this means? You lose the functionality that should be executed within $(document).ready() after an UpdatePanel rendered its contents after an asynchronous postback.

jQuery live() and ASP.NET Ajax asynchronous postback

The issue is that normally $(document).ready() is called when the DOM is ready to be manipulated. But this doens't happen after an ASP.NET Ajax asynch postback occurs.

This means that the initial jQuery bindings won't be automatically available after the asynchronous postback is over. I underline "automatically" here because my last post describes more possibilities, how this issue can be worked around.

ASP.NET repeater control - databind with style

even used the inline editing features, which I at the time thought was the coolest way possible to write ASP.NET code ( I managed to write code to hide all other rows and only show the current one - the row being edited). With a nice looking EditTemplate it looked indeed very slick but it really turned into giant and hard to manage code behind files.

Maintain HTML Radio Button Selection Inside GridView After Postback

Long time ago I wrote an article about getting the value of the selected RadioButtons inside the GridView control. The code did not addresssed the postback issue which means that the selected radio button was cleared after the postback occurs.

Radio Button Event

Here I have explained the events of radio button with javascript.
Let me explain the scenarion first,
We are having two radio button say radioobtn1 and radiobtn2. If I click on the button 1 then I need to show one DIVor FORM. same as when I click on radiobtn 2. I have given the code for the above scenarion.

how to impose javascript event processing?


If I have some form control like textbox and I want the event handler to be located in the html instead of at the server side, how to do that? Of course I can copy paste javascript code in the aspx file. But is it possible to do that using some object oriented approach (ie programmatically in the code behind)?


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend