Ajax TabContainerTabPanels Break postbacks - c#

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.

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.

Checkbox does not get checked/unchecked when used as control for CollapsiblePanelExtender

Has anyone else tried to use checkbox as control to collapse/expand the AJAX CollapsiblePanelExtender?
The panel collapses/expands fine when I am clicking the checkbox. But the checkbox itself won't get checked.
Did that happen to you too?
I know there's a work around this, but I can't rest until I understand why.
Here's the code just in case someone wants to see:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div class="standard">
<asp:UpdatePanel ID="UpdatePanelBespokeRates" runat="server">
<ContentTemplate>
<asp:CheckBox ID="checkbespoke" runat="server" AutoPostBack="False" Checked="false" Text="Click and unclick this checkbox" />
</p>
<asp:UpdatePanel ID="UpdatePanelBespoke" runat="server">
<ContentTemplate>
<asp:CollapsiblePanelExtender ID="CollapsibleExtender2" runat="server"
TargetControlID="PnlBespokeRates" CollapseControlID="checkbespoke"
CollapsedSize="1" ExpandControlID="checkbespoke" SuppressPostBack="True"
Enabled="True" Collapsed="True"></asp:CollapsiblePanelExtender>
<asp:Panel ID="PnlBespokeRates" runat="server" Visible="True" Height="300px" Width="200px" BackColor="White">
<p>Another Hello World text</p>
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="checkbespoke" EventName="CheckedChanged" />
</Triggers>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>
<p>
</div>
in the Code behind it is:
protected void Page_Load(object sender, EventArgs e)
{
CollapsibleExtender2.ClientState = "true";
CollapsibleExtender2.Collapsed = true;
}
Try removing Checked="false" from the asp:CheckBox declaration. I suspect that the postback trigger may be reloading the checkbox and re-initialising it.
What worked was:
SuppressPostback="false" in the CollapsiblePanelExtender attribute
and
Autopostback="true" in the checkbox control
remove all manual C#
And then voila.

partial page postback using javascript/jquery

I have two asp.net updatepanels on my page. One of them has a checkbox and other one has some labels. I want to update the contents of second updatepanel when checkbox is checked/unchecked. I am using following code:
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm._doPostBack('UpdatePanel2', '');
but it is doing full page post back.
Please suggest a solution.
You can set checkbox's AutoPostback to True and make it a trigger of the second UpdatePanel:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="CheckBox1" EventName="CheckedChanged" />
</Triggers>
</asp:UpdatePanel>
And then you can add label changing code in checkbox's "CheckedChanged" event handler, e.g.
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
Label2.Text = DateAndTime.Now;
}
It seems you are looking for update panel triggers, you don't need to trigger it by javascript...

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

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>

Categories

Resources