Confused of dynamically added controls on AJAX page
-
Sorry for bad English, as it`s only 3rd language... In every post regarding adding controls, it is written that I should add them OnInit event, however at that time, I do no know, witch control I must add. :( If I add them on Button click, all shows as planed, but if I add them at ScriptManager OnNavigate event, they do not show up :(
It`s nothing to wory before something happen and when it happents it`s alredy to late to wory! :)
-
Sorry for bad English, as it`s only 3rd language... In every post regarding adding controls, it is written that I should add them OnInit event, however at that time, I do no know, witch control I must add. :( If I add them on Button click, all shows as planed, but if I add them at ScriptManager OnNavigate event, they do not show up :(
It`s nothing to wory before something happen and when it happents it`s alredy to late to wory! :)
Here is some tips for adding dynamic control. . You have to create all the control before
Page_Load()
, Preferably onPage_PreInit()
. Because if we create any dynamic control afterPage_load()
, The control will not maintain,ViewState
andPostback data
. Because, View State and Post back Load just before Page_load. So, if we create any control after postback, it will not able to get the view state and postback data. Let me know if you have any problem. Hope this information will help you :-DAbhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
-
Here is some tips for adding dynamic control. . You have to create all the control before
Page_Load()
, Preferably onPage_PreInit()
. Because if we create any dynamic control afterPage_load()
, The control will not maintain,ViewState
andPostback data
. Because, View State and Post back Load just before Page_load. So, if we create any control after postback, it will not able to get the view state and postback data. Let me know if you have any problem. Hope this information will help you :-DAbhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
I know that :( But I do not care about viewstate or Postback, all controls that should talk to server are in main page, not in update panel, only thing that do not work as wanted is ScriptManagers OnNavigate event. It fires too late. I need that event to handle f5, back and forward. If controls are added as fallows: protected void mi1_click(object sender, EventArgs e) { test(); } all is ok :( But in this case: public void OnNavigateHistory(object sender, HistoryEventArgs e) { test(); } it will not work :( void test() { //This line works fine in both cases. It sets couple of properties, as label texts and session variables. set_title("Test title"); //Instead of button I need my usercontrol, but even button will not show up. Button btn = new Button(); btn.Text = "I bitīt matos!!!!!!!!!!!"; PHolder.Controls.Clear(); PHolder.Controls.Add(btn); sm.AddHistoryPoint("aa", "bb"); }
It`s nothing to wory before something happen and when it happents it`s alredy to late to wory! :)
modified on Friday, July 31, 2009 3:15 PM