RadioButtonList selection IndexChanged - asp.net

My Scenario,
When i select the option in list i need to perform some action like Textbox should be disabled. But i don find my breakpoint pointing to that action to be performed.Pls help

I guess you mean the SelectedIndexChanged event does not fire that is so because you'vent set the AutoPostBack to true.
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
</asp:RadioButtonList>
Code
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox4.Enabled = false;
}

Related

aspx dropdownList does not maintain selected value

Inherited code with a dropdownlist which is used to populate some GridViews. When a selection is made in the dropdownlist, the selection does not keep and it jumps back up to the first record. A requently mentioned fix is to add the !Page.IsPostBack in the Page_Load event, however in doing so does not resolve the issue.
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true"
DataSourceID="SqlDataSource2" DataTextField="FullAddress"
DataValueField="UniqueRecordID" Width="445px" Height="20px"
style="margin-left: 0px" TabIndex="8" AppendDataBoundItems="true"
OnSelectedIndexChanged="resetGridsAndLabel">
</asp:DropDownList>
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList2.DataSource = sqlDataSource2;
DropDownList2.DataBind();
}
Are you setting the data source for the DDL anywhere else on the page?

Dropdownlist SelectedIndexChanged not firing on aspx page

I want to auto click the search button whenever user select a value from drop down list.
code snippet:
Added the event handler in InitializeComponent() :
this.ddltrim.SelectedIndexChanged += new System.EventHandler(this.ddltrim_SelectedIndexChanged);
code:
private void ddltrim_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(ddlStores.Items.Count ==1)
btnSearch_Click("Search", null);
}
In designer:
<asp:dropdownlist id=ddltrim width="100%" Runat="server" AutoPostBack="True" EnableViewState="True">
<asp:ListItem Value="Select Submodel" Selected="True">
Select SubModel
</asp:ListItem></asp:dropdownlist>
But selectIndexChanged in not firing when i select any value from ddl. Have to manually click the button search.
Try
<asp:dropdownlist id=ddltrim width="100%" Runat="server" AutoPostBack="True" EnableViewState="True" onselectedindexchanged="ddltrim_SelectedIndexChanged">
<asp:ListItem Value="Select Submodel" Selected="True">Select SubModel</asp:ListItem>
Try to set your add event code in Page_PreInit method
protected void Page_PreInit(object sender, EventArgs e)
{
this.ddltrim.SelectedIndexChanged += new System.EventHandler(this.ddltrim_SelectedIndexChanged);
}

Button Control not working with RowCommand Event

<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="lbShowGroup" CommandName="View" CommandArgument='<%# Eval("Topic") %>'
runat="server" Text="View"></asp:Button>
</ItemTemplate>
</asp:TemplateField>
Code behind:
protected void tblTopics_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "View")
{
Response.Redirect("Group.aspx?Topic=" + e.CommandArgument.ToString());
}
}
Debugging doesn't reach the RowCommand event, but when I change the button control to LinkButton, it works. What's wrong?
Do you databind your grid on postbacks?
You must not bind your grid on postbacks in Page_Load, only when something has changed that causes the GridView to reload data(f.e. Sorting,Paging) and only in the appropriate even-handlers.
So wrap the databinding in a PostBack-check:
protected void Page_Load(Object sender, EventArgs e)
{
if(!IsPostBack)
{
DataBindGrid();
}
}
Another possible reason: Have you disabled ViewState somewhere?
I had the same issue and found out that my problem was in the Master Page where EnableViewState="false".
I changed the Master page to use EnableViewState="True".
And the rowcommand event fired as expected.

asp.net + listbox +change of value

I have a listbox in asp.net
<asp:ListBox ID="ListBox1" class="listItem" runat="server"
onselectedindexchanged="ListBox1_SelectedIndexChanged">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:ListBox>
I want to trigger a function when somebody changes it values...
code which i tried is
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Label6.Text = Label6.Text + "hello";
}
What's wrong here..
By setting the autopostback as true, my problem is solved but the page is reloaded everytime i change its value which i dnt want as large amount of data get reloaded on every autopostback(bcoz of images on the page).Even i put the following code in page load
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
}
but it didnt work out...
The problem here is that you expect that the SelectedIndexChanged event is triggered immediately. But by default the ListControl's AutoPostBack property is set to false.
true if a postback to the server automatically occurs whenever the
user changes the selection of the list; otherwise, false. The default
is false.
So set it to true:
<asp:ListBox ID="ListBox1" AutoPostBack="true" class="listItem" runat="server"
onselectedindexchanged="ListBox1_SelectedIndexChanged">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:ListBox>
AutoPostBack="true" is missing add it on ListBox1

Handling the checkedchanged event of inner repeater Checkbox control in asp.net nested repeaters

I have nested repeaters on my aspx page.In the outer repeater I am displaying a list of products and in the inner repeater I am displaying a list of additional options associated with each product.The inner repeater contains a checkbox,textbox,label and other stuff.I would like to find the controls inside the outer repeater when a user selects a checkbox in the inner repeater.In order to handle this I am using the following code.
<asp:Repeater ID="OuterRepeater" runat="server"
onitemdatabound="OuterRepeater_ItemDataBound" >
<ItemTemplate>
<asp:Label ID="CodeLabel" runat="server" Text='<%# Eval("Code") %>'></asp:Label>
<asp:Repeater ID="InnerRepeater" runat="server" OnItemCreated="InnerRepeater_ItemCreated">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true"/>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
......
.......
</ItemTemplate>
</asp:Repeater>
......
......
</ItemTemplate>
</asp:Repeater>
protected void InnerRepeater_ItemCreated(object sender, RepeaterItemEventArgs e)
{
RepeaterItem ri = (RepeaterItem)e.Item;
if (ri.ItemType == ListItemType.Item || ri.ItemType == ListItemType.AlternatingItem
)
{
CheckBox cb = ri.FindControl("CheckBox1") as CheckBox;
cb.CheckedChanged += new EventHandler(CheckBox1_CheckedChanged);
}
}
private void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
if (cb.Checked)
{
//do something
}
else
{
//do something
}
}
But the checkedChanged event of the checkbox is not firing for some reason.Also I am not sure how to access the textbox of the outer repeater in the checked changed event of the innter repeater checkbox control.
Could someone please help me with this?
Thanks
It does not fire the CheckedChanged event, since you have declared the event handler as private, You have to make it Protected or Public
Protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
You can access the Textbox control like..
private void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox checkBox = (CheckBox)sender;
Textbox textbox1 = (TextBox)checkBox.Parent.FindControl("TextBox1");
String textboxText = textbox1.Text;
}
It doesn't look like you defined an event handler in your markup.
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox1_CheckedChanged" />
Muhammad Akhtar's answer helped me a lot today!
I just needed to set a specific ID to my dynamic generated checkboxes inside my reapeater to recover the origin of the event, and do the rest of the processing, and it worked perfectly.
chkAtivo.ID = DataBinder.Eval(e.Item.DataItem, "id").ToString();
Reovered just as the sample.
Cant vote up yet, but thank you.

Resources