|
The code in this article is a little old-fashioned (VS 2003) but it works like a charm! Thank you.
|
|
|
|
|
i need code for dynamically created controls,which are binded with the database,i.e. link buttons are created depending upon the no of values.and when i click on link the event would handled. plz help me if any one had idea regarding this
hi,im ilyas ali ,i am working as software developer in MS.NET
|
|
|
|
|
|
what is the path to the control?I used FindControl
and got null
|
|
|
|
|
Hi,
After postback, dropdownlist got disappeared.
Appriciate your suggestion.
Thanks.
Hi,
i need tree view structure.For example,
One state has corresponding city.
in the initial,state should be show as
+ Alabama
when click on + sign,the corresponding city will be drill down as
Alabama
- Birmingham
Please help me asap.give the suggestion on this and if you have code,let me know.
Thanks,
Vijayan.
|
|
|
|
|
Found solution. Go here : Click Here to view Solution for Dynamic Dropdownlist[^]
Hi,
i need tree view structure.For example,
One state has corresponding city.
in the initial,state should be show as
+ Alabama
when click on + sign,the corresponding city will be drill down as
Alabama
- Birmingham
Please help me asap.give the suggestion on this and if you have code,let me know.
Thanks,
Vijayan.
|
|
|
|
|
I am creating a SubMenuList at runtime which generated at runtime according to MainMenulist in a web form. Everything works fine at the first page load. When switch MainMenulist (by click different menuitem in MainMenulist), the SubMenuList MenuItemClick can not be handled at the first time click on the SubMenuList Item. Click again, everything is fine. This problem occurs each time switch MainMenuList. Can anyone help me out. Many tanks in advance.
Here is my code:
protected override void OnLoad(EventArgs e)
{...
this.placeHolderMain.Controls.Add(GetMenu());//Create MainMenuList
if (Session["MenuE"] != null)
{
string menue = Session["MenuE"].ToString(); //Session["MenuE"] is to record MainMenuList Item Value
PopulateSubMenu(menue); //Create SubMenuList according to param "menue"
}
...}
private void mainMenu_MenuItemClick(object sender, MenuEventArgs e)
{
string menue = e.Item.Value;
PopulateSubMenu(menue);
}
protected void PopulateSubMenu(string menue)
{
...
submenu.MenuItemClick+=new MenuEventHandler(submenu_MenuItemClick);
|
|
|
|
|
I would like to know how i can postion an Imagebutton through x, and y co-ordinates through code. appreciate your help thanks
regards
joanne
|
|
|
|
|
I understood almost everything about having to recreate the controls on the page and subscribe to the events again. I just couldn't figure out how to tell asp.net that it was the same control... I just assigned an ID to the control... Thankx
|
|
|
|
|
This is great, but , what about adding controls in flow layout (for example in specified cell of a table).
Also I'm interested is there a way to dynamically put the controls in datarepeater/datalist/datagrid.
Dejan Mitev
|
|
|
|
|
I want to create a table automatically and put in its rows of a particular column radion buttons and control them programmatically in Asp.net. In controlling them, I will be able to know when they are clicked and do some computation as a result of that click.
|
|
|
|
|
hello sir,
i am making a project on asp.net(C#.net).
on my form there is a dropdownlist box by which user will select his choice for entering no of item record.
for it as user will select his choice from dropdownlist box(like 5),i want to create 5 new dropdownlist box and in each box data will fill from database and also i want to fire selectedindex change event for each box.this no of item is not fixed..
plz send me any appropriate proj example or code on my mail id"chiluka_satish@yahoo.com".
thank you
i am waiting for ur reply
satish chiluka
|
|
|
|
|
Leon Langleyben,
I've been looking for ways to do this forever!!! You have truely saved me a great deal of time and effort with this simple approach!
Thank you so much!
-brian
|
|
|
|
|
hello sir,
i am making a project on asp.net(vb.net).
on my form there is a dropdownlist box by which user will select his choice for entering no of item record.
for it as user will select his choice from dropdownlist box(like 5),i want to create 5 new dropdownlist box and in each box data will fill from database and also i want to fire selectedindex change event for each box.this no of item is not fixed..
plz send me any appropriate proj example or code on my mail id"dearvivek_singh@rediffmail.com".
thank you
i am waiting for ur reply
vivek singh
|
|
|
|
|
Great article, very useful.
I'm trying to use LinkButton and ImageButton (within a SharePoint web part, just to be realy silly ) and the LinkButton works no problems and the Command event fires. The ImageButton *appears* to work, but the Command event does not get fired!
Any suggestions for what might be the problem or how to fix this problem?
Thanks.
|
|
|
|
|
use ImageClickEventHandler Deleagate to call function on click event
Mahendra
|
|
|
|
|
firstly, thank you very much for this article. it was a great help for a dynamic control problem I was having. my particular problem was a little more complicated than the example in the article.
the problem occurs when dynamic controls 'push' a viewstate populated control to another location in the control tree.
for example, if you had a table that contains a SELECT box populated on the initial load in the last column of the table. selecting an option from the SELECT and clicking a button inserts a column into the table, the dropdown always remains in the last column. when asp.net comes around to populating the select box on the second postback the received __viewstate contains the dynamic cell, the dynamic cells don't exist yet, so the select doesn't match up. the select won't be populated.
to fix this problem, a better approach would be to RecreatePersistedControls immediately after LoadViewState, e.g:
protected override void LoadViewState(object savedState)
{
base.LoadViewState (savedState);
RecreatePersistedControls();
}
this way the dynamic controls have been built at the point where asp.net comes around to populating the select box, and everything matches. and the viewstate collection is available if you are storing your data/controls in there.
this article has a very good explanation of what is happening in the page creation sequence.
|
|
|
|
|
Ok, this is what I've been trying to do all day:
Dynamicaly add a user control to an ASP.Net web page in the position of a placeholder. Then, when a user selects a different node in a treeview control, postback the page and load a different user control based upon the Text property of the selected node.
The main problem with this despite my best efforts is that the recommended way to load a dynamic control is in the Page_init event handler, however, this only works if the control that is loaded is of the same type on every post back otherwise the server will throw a 'Failed to load viewstate...' error. In this scenario, the user control could be a different one on each postback, so this could not work for me.
The other problem is that when you put the code to dynamicaly load the user control in the Page_init event handler, since this is a SelecteNodeIndexChange event, there is no way to determine the new value before the Page_Init is called. I have tried everything, even overriding the DeterminePostBackMode event handler which does come before Init. however, there is no way to access properties of Controls at this point becuase it takes place after the page has been posted back and before the LoadViewState occurs. So, what kept happeneing is that the dynamically loaded control would be the same as it was on the post back before and only on the next post back would it be the correct user control. Again, that is becuase the SelectedNodeIndexChange value doesn't really update until after the postback and after the Init event.
What I did:
So on the 1st Page_Load event I go ahead and do the following:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Session("IsPostBack") = True
FillTree(oTree) 'fills my treeview control with parent nodes
FillList2() 'fills the child nodes for each parent node in the treeview
LoadUserControl() 'routine to load control in the placeholder controls collection
BindUserControl() 'routine to bind the child controls of the User Control
Else
SetSelectedIndex() 'Determines the SelectedIndex of the treeview after a postback
LoadUserControl()
BindUserControl()
End If
End Sub
The actual code to add the control to the placeholder is inside my LoadUserControl() method within a Select Case block using the Session("ControlToLoad") as the case and looks like such (select case not shown):
Private Sub LoadUserControl()
uc = LoadControl("~/Controls/DynamicUserControl1.ascx")
uc.ID = "DynamicUserControl1" 'can be any id you wish though you might want to make it unique for each type of possible user control you plan to load just for safety.
ph.Controls.Add(uc)
End Sub
Note: 'uc' was declared as Protected Withevents uc as Control and 'ph' was a placeholder added to my web form in design view.
This adds a dynamically determined user control to my static placeholder (ph)controls collection,not the page's controls collection, on the first trip to the page. Then when I go to bind any of the controls in this user control i just added, I have to type cast the user control in order to call any methods or properties in the code-behind pages of that user control. i do this like such inside of my BindUserControl() method inside of another Select Case block to determin again which tpype of control was added (select case not shown):
CType(uc, DynamicControl1).BindControls(arguments) 'BindControls would be a method in the DynamicControl1.ascx.vb file, not the code-behind file of the current .aspx page.
One thing to note is that I could have put the above code inside of the LoadUserControl() method and saved myself the trouble of writing redundant Select Case blocks.
Now, the hard parts - when a user clicks on a certain node in my Treeview control, I want to load a different type of user control depending upon the Text property of the selected tree node. I determined this in the SetSelectedIndex() method as such:
Session("ControlToLoad") = oTree.GetNodeFromIndex(oTree.SelectedNodeIndex).Text 'oTree = TreeView control
Now, remember that I can only determine the Text property of the selected node after the page has been re-initialized in the page load event, but I also must make sure that the new control that is to be loaded is of the same type of control as was before the postback. Why? becuase the LoadViewState expects to load the viewstate of the control that was there not the new one you plan to load.
So once I've determined the new user control to load and enter my routine to actualy load it, I have to make sure I have logic in place to do the following:
1) Make sure I add the control that was added on the first trip to the page to a Session variable, so I can compare it on subsequent trips
2) If this is a subsequent trip to the page then I need to compare the user control store in my session variable to that of the new user control that is to be added. All I did here was make sure to set the ID property of the user control and compare the uc.ID's to each other.
3) If the controls have the same ID's then they are the same, so simply add the new control that you determined from the Session("ControlToLoad") variable.
4)If the controls do not have the same ID's then we need to load the control that was on teh previous postback first, so that when the recursive loadviewstate function is called on it, it's viewstate is loaded and the error that we were getting before will not appear.
5) Remove the old user control from the placeholder's collection and add the new control as determined by the Session("ControlToLoad") variable.
So, as you see in the above logic, that you will load the control determined by the Session("ControlToLoad") variable no matter what, but you just need to make sure that if you are loading a different control than before, that you load the old one first to satisfy the viewstate and then delete it and load the new one it's place and all is well. One thing I was concerned about was seeing the first control load and the dissapear and then the new control load, however, since we are doing all of this in the Page_load event, it's seemless and works well.
Hope this workaround helps somebody.
later!
JasonERivera.com
|
|
|
|
|
Thanks Jason, that workaround is just what I was looking for.
|
|
|
|
|
Hello!
I have generated a Table dynamically with several Buttons and showing rows from a Database.
Now,I am inserting a row on this Button Click event through a Button Click Event Handler.
Once i Click the button one row is inserted,but then when i Refresh the page
it again goes to Button Event Handler method and insert the same row again,even if i don't clicked the Button.
Kindly guide me.
|
|
|
|
|
Can i get ur code snippet that u have used.
|
|
|
|
|
Hi,
I want to get click event of the runtime button on calendar control in ASP.NET.
my e-mail is nirav_bodiwala@yahoo.co.in
please give reply as soon as possible,
thank u,
nirav4u
|
|
|
|
|
Dear Sir,
I want to get click event of the runtime button on calendar control in ASP.NET.
my e-mail is nirav_bodiwala@yahoo.co.in
please give reply as soon as possible.
thank u,
nirav4u
|
|
|
|
|
Dear Sir,
I want to get click event of the runtime button on calendar control in ASP.NET.
my e-mail is nirav_bodiwala@yahoo.co.in
please give reply as soon as possible.
thank u,
nirav4u
|
|
|
|
|
|