how to access dynamically added radiobutton in update panel - c#

ive product detail page , ive radiobutton in this page which i created dynamically in an updatepanel because of postback... i created it very well , there is an checkedchanged event for all radiobuttons it works very well but i need to get radiobutton text value but i cant reach the radiobutton, it looks as control in updatepanel... but here thing at least for me:D... after i deleted update panel i can reach radiobuttons easily... why it happens like this , i couldnt understand... but i know something i need to prevent page postback on radiobuttons checkedchanged event so how can i do this by using ajax or updatepanel something...
thx...

You said that you can reach radiobutton but it looks like a control. I think you access like that:
myUpdatePanel.Controls[0] // or in a foreach or something like that
What about cast each of that controls?
var myRadioButton = (RadioButton)myUpdatePanel.Controls[0];

Related

How do you get a AjaxFileUpload control to see what is in a textbox on a form

I know that AjaxFileUpload is asynchronous, but is there a work around to get the control to see the value of a text box on the same form?
I would like to have the text box for the user to type in the description of the uploaded file, but in the OnUploadComplete event handler, the control basically sees nothing. I hope there is a workaround.
I think you can try this:
Set AutoPostBack for the DropDownList to true and handle the SelectedIndexChanged event to set the selected value in Session. Then consume the Session value in OnUploadComplete event.

dynamically created listbox c#

I have to create multiple listbox and bind them as they created dynamically. I have created listbox as loop is for creating no of listbox as needed
for(int i=0;i<requirement;i++)
{
Listbox dynamiclistbox = new listbox();
//then i bind it with a list<>
//then i add listbox to a panel
panel.Controls.Add(dynamiclistbox);
}
My problem is that when i click on submit button the dynamic controls disappear as dynamic controls loose state on postback
can someone help me to create no. of listbox dynamically and bind also bind them on same button click . and get the listbox on postback
i.e, to know the selected item on listbox
You will need to put your code inside Page_Load event. If it is already there, then you probably have it inside something like
if (!Page.IsPostBack) {
//Your code
}
If that is the case, then you will need to put your code outside the if, since it is only adding the controls when it is not a postback and you need to add them when it is postback as well.
EDIT:
Currently the controls are created on button click. It is advisable to have a separate function which receives an input and generates the controls, add them to panel. Call this function from your click event. When this is correct, create an asp:HiddenField and set its Value to the input you need in the click handler. On Page_Load call your function with the Value of your HiddenField.
write code for binding in !IsPostBack section
for(int i=0;i<requirement;i++)
{
Listbox dynamiclistbox = new listbox();
dynamiclistbox.CssClass = "";
dynamiclistbox.ID = ""
dynamiclistbox.EnableViewState = true;
if (!IsPostBack){}

Button List inside the DataList control

I am a facing a situation in which I need to use something like a ButtonList inside a DataList control.
Since there is no control like ButtonList, should I nest a DataList/Repeater inside the DataList or there is some other better option to handle the situation.
I am not exactly sure what you are looking for but this is what I assume you want:
YourListItem1
ButtonAction1
ButtonAction2
ButtonAction3
ButtonAction4
YourListItem2
ButtonAction1
ButtonAction3
YourListItem3
ButtonAction1
ButtonAction2
YourListItem3
ButtonAction3
ButtonAction4
Or something similar?
To produce this you could just have a DataList with a Repeater inside that contains the buttons you need. You could implement the OnDataBinding event of your DataList (YourListItem) and then bind the data that produces the buttons based on some data. Then in the Repeater you could implement each button's OnDataBinding event and assign the CommandArguments with the ID or detail you need to make the button act specific to the row it is on.
This method would allow you to make one function for each button used in your template and the CommandArgument would define the details of the action.

Check box with autopostback = "true" inside of repeater, inside of UpdatePanel pops page back to top when clicked

I have an UpdatePanel that contains a repeater that basically builds a list of checkboxes. Those check boxes are set to AutoPostback with an "OnCheckedChanged" event.
When the user checks a checkbox, everything happens as expected except for one thing, the page pops (or scrolls) back to the top.
Other controls that cause this UpdatePanel to refresh don't cause this issue, even just plain checkboxes that ARE NOT inside of my repeater, but still within the UpdatePAnel, work fine (no scroll back to top)...
Any ideas?
open your page in designview (Source) at the top you will find pagedirectives
try adding MaintainScrollPositionOnPostback="true"
hope it helps !!!

UpdatePanel in Repeater

I have a UserControl which contains voting buttons inside an UpdatePanel, and outside a Repeater, it works perfectly. In the repeater, clicking the button fires off the appropriate event. That event is supposed to update the text of a control within the User Control, and that update should be reflected when the UpdatePanel refreshes.
If tried the UpdatePanel in UpdateMode Always and Conditional (firing the Update event after making the changes to the properties in the _Click method, and the same problem happens both ways.
Is there something about how UpdatePanels behave in Repeaters that I'm missing?
Thanks.
The reason might have nothing to do with the update panel, but with the postback loosing track of your UserControl. Possibly assigning unique IDs to your user controls may help.
Your repeater is building a table correct? The problem is most likely that an update panel generates a div tag and it's probably outside any TR and TD tags so the browser doesn't know what to do with it.
http://www.netortech.com/blog/?articleid=8

Categories

Resources