Please I need someone to help me with this issue:
When I select an item from an .ascx usercontrol 'DropDownList Box' added to a master page with PlaceHolder1.Controls.Add(LoadControl("//UserControls/mycontrol.ascx"));
The .ascx user control disappears after the item has been selected
You don't show your code, so it's hard to provide an exact answer. but probably you add your user control dynamically only one time and it disappears after each postback.
You need to load Usercontrol after each postback so you need to load Usercontrol in something like Page_load method if you don't.
Related
I have an aspx Page that contain a userControl that contains textboxes.
in the page_load method, it reads from the database, and i want to fill the textboxes of the usercontrol with the data been read.
the problem i am facing, that the flow of page loading is
Page_Load of the page, where i am assigning the text field, then it page_load of the userControl, so here all the data will be erased, then it will show the page.
how i can fix this.
use OnDataBinding or OnPreRender
in this case, you have to fill the data of UserControl in Page_Init not Page_Load, the problem here will be solved :)
I have two user controls on a page - UC1,UC2. Each usercontrol have a asp:button. Now if I click the any of the buttons the page post back. Now if I click the button of UC1 then the following happen.
Viewstate load for two user controls.
Page load called for two user controls.
The event handler of UC1 button is fired.
Now if user click on the UC1 button, I do not want to load the view state of UC2 user controls at server because the viewstate of UC2 is large.
The execution of UC1 is not dependent of UC2.
Please suggest how can I achive this.
Thanks!
What it sounds like your asking for is the ability to do partial postbacks. That is postbacks that only affect a portion of the page. There are a number of ways to accomplish this such as using the Microsoft provided AJAX controls (http://www.asp.net/ajax) or rolling your own with JQuery and web methods (this method however is stateless and should be expected as such). Specifically you will want to look at UpdatePanels and PostBack Triggers.
Hope this helps.
I have registered a usercontrol dynamically and called it in page load.
In Button click i used "Viewstate.clear" , for that usercontrol but it is not working.
Can anybody suggest me to clear the Viewstate.
Thank u,
We have created a UserControl. Inside user control we are creating an update panel. Inside the panel we are creating various controls such as TextBox, Button, DropDownList and ListBox and event associated with them buttonclick(),DropDown_selectedIndexChanged(),TextBox_TextChenged() etc. All the controls(including update panel) are created programatically using c#.
To ajaxify the events we have used ScriptManager.
ScriptManager is added on OnInit function programatically like as shown:
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
if (scriptManager == null)
{
scriptManager = new ScriptManager();
//scriptManager.EnablePartialRendering = true;
this.Controls.AddAt(0,scriptManager);
}
Every time after page load only one event get fired partial postback(which is desired) but after that no event gets fired .
All valid changes have already been done in web.config file for AJAX .
Please suggest the possible cause and solution of the problem.
On a partial postback, the ScriptManager will not be added because you are trying to add it outside the UpdatePanel (where it has to be). This works on the first page load because it's not a partial postback. But after the partial postback, the dynamically added ScriptManager won't be available to the page, and because you are trying to add it outside the UpdatePanel -- AddAt(0,...) - after a partial postback, it won't actually be added. On a partial postback you can only affect things inside the UpdatePanel that initiated the postback.
Bottom line is, you really can't add a ScriptManager dynamically, since it will never be there after a partial postback. Just like you can't dynamically add any other control outside of an UpdatePanel after an event sourced inside it.
I've seen code to handle MasterPage events in the content Page, but if I'm loading a UserControl dynamically into the Page, can I handle the event in the UserControl instead?
Basically I have a button on the MasterPage, when it's clicked I need to make the UserControl do something, such as display text or change a value in a form.
Failing that, is it possible to make an event from one dynamically loaded UserControl fire in another on the same page? I could then replace the button in the MasterPage with one in another UserControl
Thanks all.
This is very similar to this stackoverflow question.
The answer to that question should also apply to yours: your Page knows its master and knows its child controls. It can wire-up a handler on the child control to an event on the master page, so the child control can perform necessary functionality when the even occurs on the master page.