facebook iframe application ,with master page, doesn't firing OnSelectedIndexChanged event - c#

this is my radio button list:
<asp:RadioButtonList runat="server" ID="rdlTest" OnSelectedIndexChanged="rdlTst_selectedChange">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:RadioButtonList
this is the code behind:
protected void rdlTst_selectedChange(object sender, EventArgs e)
{
Response.Write("hello");
}
it's not firing the event for some reason

You need to add AutoPostBack = "true" onto the definition of the RadioButtonList.
<asp:RadioButtonList runat="server" ID="rdlTest" AutoPostBack="true" OnSelectedIndexChanged="rdlTst_selectedChange">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:RadioButtonList>

Related

UpdatePanel not refreshing on my radiobuttonlist

I have some radio buttons like this:
<li class="list-group-item">
<p>YOUR AGE IS AN IMPORTANT FACTOR IN YOUR ABILITY TO TAKE ON INVESTMENT RISK. YOUR AGE IS:</p>
<asp:RadioButtonList ID="radioBtnFirst" CssClass="radioBtnAge" runat="server" RepeatDirection="Horizontal"
TextAlign="Right" AutoPostBack="True" OnSelectedIndexChanged="radioBtnFirst_SelectedIndexChanged">
<asp:ListItem Value="1">60 and over</asp:ListItem>
<asp:ListItem Value="2">50 - 59</asp:ListItem>
<asp:ListItem Value="3">40 - 49</asp:ListItem>
<asp:ListItem Value="4">30 - 39</asp:ListItem>
<asp:ListItem Value="5">Under 30</asp:ListItem>
</asp:RadioButtonList>
</li>
Now somewhere donw I have a textbox where I want to get the value of the selected radiobutton. This is the code that is doing that:
protected void radioBtnFirst_SelectedIndexChanged(object sender, EventArgs e)
{
totalScore.Text = radioBtnFirst.SelectedValue;
}
I wanted to add UpdatePanel so it won't refresh the whole page but it's not working, when I press first one of the radio buttons it doesn't happen anything, but when I press the second time, it refreshes again the whole page.
This is the code that I used for UpdatePanel:
<h3>Total Score:</h3>
<asp:UpdatePanel ID="upScore" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox runat="server" ID="totalScore" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="radioBtnFirst" EventName="SelectedIndexChanged"/>
</Triggers>
</asp:UpdatePanel>
Now it's ok, it's working. I figured out that the problem was behind the code in Page_Load method.

Why is the selectedindexchanged event firing only once in my code?

I have two drop down lists,the first one is ddlSubjectArea and below is it's source code:
<asp:DropDownList ID="ddlSubjectArea" runat="server" AutoPostBack="True" Height="20px"
OnSelectedIndexChanged="ddlSubjectArea_SelectedIndexChanged" Width="160px"
meta:resourcekey="ddlSubjectAreaResource1" class="notranslate">
</asp:DropDownList>
Here is the code for the second one:
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlCompetency1" runat="server" Width="150px">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlSubjectArea" runat="server" />
</Triggers>
</asp:UpdatePanel>
And this is the code for the selectedindexchanged event of the first dropdownlist.
protected void ddlSubjectArea_SelectedIndexChanged(object sender, EventArgs e)
{
tblSubjectMasterDLL.BindSubjectOnSubjectArea(ddlSubjectName, Convert.ToInt32(ddlSubjectArea.SelectedItem.Value));
bIsMultipleCompetency = tblSubjectAreaMasterDLL.IsMultipleCompetency(Convert.ToInt32(ddlSubjectArea.SelectedValue));
MultipleCompetencySetting();
}
The visibility of the second dropdownlist depends on the first dropdownlist's selected index.The selectedindexchanged event fires once but after that it does not fire.I have tried selecting different values every time but had no success.Where am I going wrong?
Another piece of information that I would like to provide is that even the page load event is getting called only once.Also if I remove the update panels,everything works normally.
I would like to add one more piece of information:If I set EnableEventValidation=false for the page,things start working as expected.I have also heard that setting EnableEventValidation to false is not recommended.

DropDown not firing OnSelectedIndexChanged

I have a page with dropdown list
<asp:Content runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Cellsite</asp:ListItem>
<asp:ListItem>Agreement</asp:ListItem>
<asp:ListItem>Event</asp:ListItem>
<asp:ListItem>User</asp:ListItem>
</asp:DropDownList>
<asp:Label runat="server" ID="EntityName"></asp:Label>
<ig:WebScriptManager ID="WebScriptManager1" runat="server"></ig:WebScriptManager>
<ig:WebDataGrid ID="EntityGrid" runat="server" Width="100%">
<Behaviors>
<ig:Sorting>
</ig:Sorting>
</Behaviors>
</ig:WebDataGrid>
code behind is
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
EntityName.Text = DropDownList1.SelectedItem.Text;
}
For somereason the label is never updated the event selectedindexchanged is not firing at all I need to add a dynamic grid in this event. Any clue?
You need to add AutoPostBack on the dropdown
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
You can actually tell that there is no post back when you do not have the AutoPostBack=true attribute.
set dropdownlist property AutoPostBack="true"
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>Cellsite</asp:ListItem>
<asp:ListItem>Agreement</asp:ListItem>
<asp:ListItem>Event</asp:ListItem>
<asp:ListItem>User</asp:ListItem>
</asp:DropDownList>

Execute Update on DropDownList change

At the moment, I have a GridView with the following in the ItemTemplate:
<asp:LinkButton ID="lbEdit" runat="server" CommandName="Edit">
<asp:Label ID="Label6x" runat="server" Text='<%# Bind("progress_full") %>' /></asp:LinkButton>
This works fine and when I click on it, it displays the EditTemplate which currently contains the following:
<asp:DropDownList ID="DropDownList3" runat="server"
SelectedValue='<%# Bind("progress") %>'>
<asp:ListItem Value="0">In queue</asp:ListItem>
<asp:ListItem Value="1">Being worked on</asp:ListItem>
<asp:ListItem Value="2">Complete</asp:ListItem>
</asp:DropDownList><br />
<asp:LinkButton ID="lbUpdate" runat="server" CommandName="Update" Text="Update" />
How can I get the dropdown to automatically execute the Update command when it is changed, instantly returning back to the ItemTemplate, instead of me making the change to the DropDown and having to click Update?
You add AutoPostBack="true" to your DropDownList and set OnSelecIndexChanged="DropDownList1_SelectedIndexChanged"
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//execute here your update
......
}

Ajax TabContainerTabPanels Break postbacks

Hey guys check this out ...
<asp:TabContainer ID="jkhgjkgh" runat="server">
<asp:TabPanel ID="jkkljhgh" runat="server" HeaderText="sdkl;fgjl;kgjdf">
<ContentTemplate>
<asp:Button ID="jhgkjgh" runat="server" Text="Button" onclick="Button1_Click" />
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="jkgh" runat="server" HeaderText="gjdkl;gjdf;g" Visible="false">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropDownSelect">
<asp:ListItem Text="test" />
<asp:ListItem Text="test" />
<asp:ListItem Text="test" />
<asp:ListItem Text="test" />
</asp:DropDownList>
</ContentTemplate>
</asp:TabPanel>
nothing crazy ... just a tabcontainer with a couple of panels on it the second is hidden.
now we go to the code behind ...
protected void Button1_Click(object sender, EventArgs e)
{
TabPanel p = new TabPanel();
p.ContentTemplate = jkgh.ContentTemplate;
jkhgjkgh.Tabs.Add(p);
}
protected void dropDownSelect(object sender, EventArgs e)
{
int i = 0;
}
Here's where it all goes horribly wrong ...
I click the button on the first tab panel to create a new tab that has the template defined in my hidden panel, i then go to that panel and change the selection in the drop down ....
It does a postback but the drop down event is never raised ....
Any ideas ???
The problem is that you cant dynamically copy the hidden templated tabpanel and add a new one in to the collection.
Apparently the tabcontainer control doesn't allow for this without a lot of "hacking around".
I'm not entirely sure why but it seems that ITemplate types don't clone well for event handling.
I think it might be because your TabContainer does not have AutoPostBack set to true.

Categories

Resources