Better example, so you can watch the non-AJAX fire properly.
<%@. Page Language="C#" AutoEventWireup="true" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><body> <script runat="Server"> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ddl_customers_specific.Items.Add(new ListItem("Test")); ddl_patients_specific.Items.Add(new ListItem("Test")); } } protected void rb_customers_all_CheckedChanged(object sender, EventArgs e) { ddl_customers_specific.BackColor = System.Drawing.Color.Red; } protected void rb_customers_specific_CheckedChanged(object sender, EventArgs e) { ddl_customers_specific.BackColor = System.Drawing.Color.Blue; } protected void rb_patients_all_CheckedChanged(object sender, EventArgs e) { ddl_patients_specific.BackColor = System.Drawing.Color.Red; } protected void rb_patients_specific_CheckedChanged(object sender, EventArgs e) { ddl_patients_specific.BackColor = System.Drawing.Color.Blue; } </script> <form id="form1" runat="server"> <asp:ScriptManager runat="server" ID="sm" /> <table> <tr><td colspan="2">AJAX</td></tr> <tr> <td> <asp:RadioButton ID="rb_customers_all" runat="server" Text="All Customers" AutoPostBack="true" Checked="true" GroupName="g_Customers" OnCheckedChanged="rb_customers_all_CheckedChanged" /> </td> </tr> <tr> <td> <asp:RadioButton ID="rb_customers_specific" runat="server" Text="Specific Customers" AutoPostBack="true" GroupName="g_Customers" OnCheckedChanged="rb_customers_specific_CheckedChanged" /></td> <td> <asp:UpdatePanel ID="up_customer" runat="server" UpdateMode="conditional"> <ContentTemplate> <asp:DropDownList ID="ddl_customers_specific" runat="server" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="rb_customers_all" EventName="CheckedChanged" /> <asp:AsyncPostBackTrigger ControlID="rb_customers_specific" EventName="CheckedChanged" /> </Triggers> </asp:UpdatePanel> </td> </tr> </table> <table> <tr><td colspan="2">Non AJAX</td></tr> <tr> <td> <asp:RadioButton ID="rb_patients_all" runat="server" Text="All patients" AutoPostBack="true" Checked="true" GroupName="g_patients" OnCheckedChanged="rb_patients_all_CheckedChanged" /> </td> </tr> <tr> <td> <asp:RadioButton ID="rb_patients_specific" runat="server" Text="Specific patients" AutoPostBack="true" GroupName="g_patients" OnCheckedChanged="rb_patients_specific_CheckedChanged" /></td> <td> <asp:DropDownList ID="ddl_patients_specific" runat="server" /> </td> </tr> </table> </form></body></html>
HiNXTwoThou,
I copied you first code example. When you delete the checked=true property of you first radiobutton control. the event fires when you click on it.
Regards,
Removing Checked="true" does allow it to behave properly, but, when you putrb_customers_all.Checked = true; in Page_Load, it goes back to not working. Unfortunately, the page is not functional for my users without default settings.
Rewrote it to show all the scenarios. Removing checked=true works, until you do any other post back, then its dead again. Use the AJAX without checked="true", then use Non-AJAX, then try the AJAX without checked="true" again.
<%@. Page Language="C#" AutoEventWireup="true" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><body> <script runat="Server"> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ddl_customers_specific.Items.Add(new ListItem("Test")); ddl_patients_specific.Items.Add(new ListItem("Test")); rb_customers3_all.Checked = true; } } protected void rb_customers_all_CheckedChanged(object sender, EventArgs e) { ddl_customers_specific.BackColor = System.Drawing.Color.Red; } protected void rb_customers_specific_CheckedChanged(object sender, EventArgs e) { ddl_customers_specific.BackColor = System.Drawing.Color.Blue; } protected void rb_customers2_all_CheckedChanged(object sender, EventArgs e) { ddl_customers2_specific.BackColor = System.Drawing.Color.Red; } protected void rb_customers2_specific_CheckedChanged(object sender, EventArgs e) { ddl_customers2_specific.BackColor = System.Drawing.Color.Blue; } protected void rb_customers3_all_CheckedChanged(object sender, EventArgs e) { ddl_customers3_specific.BackColor = System.Drawing.Color.Red; } protected void rb_customers3_specific_CheckedChanged(object sender, EventArgs e) { ddl_customers3_specific.BackColor = System.Drawing.Color.Blue; } protected void rb_patients_all_CheckedChanged(object sender, EventArgs e) { ddl_patients_specific.BackColor = System.Drawing.Color.Red; } protected void rb_patients_specific_CheckedChanged(object sender, EventArgs e) { ddl_patients_specific.BackColor = System.Drawing.Color.Blue; } </script> <form id="form1" runat="server"> <asp:ScriptManager runat="server" ID="sm" /> <table> <tr> <td colspan="2"> AJAX<br /> (with Checked="true")</td> </tr> <tr> <td> <asp:RadioButton ID="rb_customers_all" runat="server" Text="All Customers" AutoPostBack="true" GroupName="g_Customers" OnCheckedChanged="rb_customers_all_CheckedChanged" Checked="true" /> </td> </tr> <tr> <td> <asp:RadioButton ID="rb_customers_specific" runat="server" Text="Specific Customers" AutoPostBack="true" GroupName="g_Customers" OnCheckedChanged="rb_customers_specific_CheckedChanged" /></td> <td> <asp:UpdatePanel ID="up_customer" runat="server" UpdateMode="conditional"> <ContentTemplate> <asp:DropDownList ID="ddl_customers_specific" runat="server" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="rb_customers_all" EventName="CheckedChanged" /> <asp:AsyncPostBackTrigger ControlID="rb_customers_specific" EventName="CheckedChanged" /> </Triggers> </asp:UpdatePanel> </td> </tr> </table> <hr /> <table> <tr> <td colspan="2"> AJAX<br /> (without Checked="true")</td> </tr> <tr> <td> <asp:RadioButton ID="rb_customers2_all" runat="server" Text="All customers2" AutoPostBack="true" GroupName="g_customers2" OnCheckedChanged="rb_customers2_all_CheckedChanged" /> </td> </tr> <tr> <td> <asp:RadioButton ID="rb_customers2_specific" runat="server" Text="Specific customers2" AutoPostBack="true" GroupName="g_customers2" OnCheckedChanged="rb_customers2_specific_CheckedChanged" /></td> <td> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional"> <ContentTemplate> <asp:DropDownList ID="ddl_customers2_specific" runat="server" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="rb_customers2_all" EventName="CheckedChanged" /> <asp:AsyncPostBackTrigger ControlID="rb_customers2_specific" EventName="CheckedChanged" /> </Triggers> </asp:UpdatePanel> </td> </tr> </table> <hr /> <table> <tr> <td colspan="2"> AJAX<br /> (without Checked="true",<br /> but set Checked in Page_Load)</td> </tr> <tr> <td> <asp:RadioButton ID="rb_customers3_all" runat="server" Text="All customers3" AutoPostBack="true" GroupName="g_customers3" OnCheckedChanged="rb_customers3_all_CheckedChanged" /> </td> </tr> <tr> <td> <asp:RadioButton ID="rb_customers3_specific" runat="server" Text="Specific customers3" AutoPostBack="true" GroupName="g_customers3" OnCheckedChanged="rb_customers3_specific_CheckedChanged" /></td> <td> <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="conditional"> <ContentTemplate> <asp:DropDownList ID="ddl_customers3_specific" runat="server" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="rb_customers3_all" EventName="CheckedChanged" /> <asp:AsyncPostBackTrigger ControlID="rb_customers3_specific" EventName="CheckedChanged" /> </Triggers> </asp:UpdatePanel> </td> </tr> </table> <hr /> <table> <tr> <td colspan="2"> Non AJAX</td> </tr> <tr> <td> <asp:RadioButton ID="rb_patients_all" runat="server" Text="All patients" AutoPostBack="true" Checked="true" GroupName="g_patients" OnCheckedChanged="rb_patients_all_CheckedChanged" /> </td> </tr> <tr> <td> <asp:RadioButton ID="rb_patients_specific" runat="server" Text="Specific patients" AutoPostBack="true" GroupName="g_patients" OnCheckedChanged="rb_patients_specific_CheckedChanged" /></td> <td> <asp:DropDownList ID="ddl_patients_specific" runat="server" /> </td> </tr> </table> </form></body></html>
Hi NXTwoThou,
Add the following to you pageload: rb_customers_all.InputAttributes["checked"] = "true"; and i think it will work for you.
Regards,
Works until I do the Non-AJAX call, then it only fires once afterwards.
Hi NXTwoThou,
It works for me even with the NON Ajax code:
<%
@.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default2.aspx.cs"Inherits="Default2" %>
<!
DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><
htmlxmlns="http://www.w3.org/1999/xhtml"><
body><scriptrunat="Server">protectedvoid Page_Load(object sender,EventArgs e){
if (!IsPostBack){
ddl_customers_specific.Items.Add(
newListItem("Test"));ddl_patients_specific.Items.Add(
newListItem("Test"));rb_customers_all.InputAttributes[
"checked"] ="true";rb_patients_all.InputAttributes[
"checked"] ="true";}
}
protectedvoid rb_customers_all_CheckedChanged(object sender,EventArgs e){
ddl_customers_specific.BackColor = System.Drawing.
Color.Red;}
protectedvoid rb_customers_specific_CheckedChanged(object sender,EventArgs e){
ddl_customers_specific.BackColor = System.Drawing.
Color.Blue;}
protectedvoid rb_patients_all_CheckedChanged(object sender,EventArgs e){
ddl_patients_specific.BackColor = System.Drawing.
Color.Red;}
protectedvoid rb_patients_specific_CheckedChanged(object sender,EventArgs e){
ddl_patients_specific.BackColor = System.Drawing.
Color.Blue;}
</script><formid="form1"runat="server"><asp:ScriptManagerrunat="server"ID="sm"EnablePartialRendering="true"/><table><tr><td><asp:RadioButtonID="rb_customers_all"runat="server"Text="All Customers"AutoPostBack="true"GroupName="g_Customers"OnCheckedChanged="rb_customers_all_CheckedChanged"/></td></tr><tr><td><asp:RadioButtonID="rb_customers_specific"runat="server"Text="Specific Customers"AutoPostBack="true"GroupName="g_Customers"OnCheckedChanged="rb_customers_specific_CheckedChanged"/></td><td><asp:UpdatePanelID="up_customer"runat="server"UpdateMode="conditional"><ContentTemplate><asp:DropDownListID="ddl_customers_specific"runat="server"/></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="rb_customers_all"EventName="CheckedChanged"/><asp:AsyncPostBackTriggerControlID="rb_customers_specific"EventName="CheckedChanged"/></Triggers></asp:UpdatePanel></td></tr></table><table><tr><tdcolspan="2">
Non AJAX
</td></tr><tr><td><asp:RadioButtonID="rb_patients_all"runat="server"Text="All patients"AutoPostBack="true"GroupName="g_patients"OnCheckedChanged="rb_patients_all_CheckedChanged"/></td></tr><tr><td><asp:RadioButtonID="rb_patients_specific"runat="server"Text="Specific patients"AutoPostBack="true"GroupName="g_patients"OnCheckedChanged="rb_patients_specific_CheckedChanged"/></td><td><asp:DropDownListID="ddl_patients_specific"runat="server"/></td></tr></table></form>
</
body></
html>Regards,
if it works now (aned hope it does) please mark it as answered :)
Here's a sequence to reproduce the problem with the last set of code given:
On the AJAX table, click specific customers..turns the dropdown blue...click all customers, turns it red. Click the Non AJAX specific patients, turns it blue, AJAX stays red. Click specific customers in AJAX, turns blue. Now click all customers in AJAX...stays blue..aka, no workie. If you then switch the Non AJAX, it'll change the top to red.
I've tried this on 3 other machines here in the office to see if it was just something funky with my machine(abiet all IE7), but the top(AJAX table) stays blue until I make a Non AJAX call.
Hi TwoThou,
i see your problem. Why don't you use also an updatepanel for the patients table. This will make it work!
<%
@.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default2.aspx.cs"Inherits="Default2" %>
<!
DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><
htmlxmlns="http://www.w3.org/1999/xhtml"><
head></
head><
body><scriptrunat="Server">protectedvoid Page_Load(object sender,EventArgs e){
if (!IsPostBack){
ddl_customers_specific.Items.Add(
newListItem("Test"));ddl_patients_specific.Items.Add(
newListItem("Test"));rb_customers_all.InputAttributes[
"checked"] ="true";rb_patients_all.InputAttributes[
"checked"] ="true";}
}
protectedvoid rb_customers_all_CheckedChanged(object sender,EventArgs e){
ddl_customers_specific.BackColor = System.Drawing.
Color.Red;}
protectedvoid rb_customers_specific_CheckedChanged(object sender,EventArgs e){
ddl_customers_specific.BackColor = System.Drawing.
Color.Blue;}
protectedvoid rb_patients_all_CheckedChanged(object sender,EventArgs e){
ddl_patients_specific.BackColor = System.Drawing.
Color.Red;}
protectedvoid rb_patients_specific_CheckedChanged(object sender,EventArgs e){
ddl_patients_specific.BackColor = System.Drawing.
Color.Blue;}
</script><formid="form1"runat="server"><asp:ScriptManagerrunat="server"ID="sm"EnablePartialRendering="true"/><table><tr><td><asp:RadioButtonID="rb_customers_all"runat="server"Text="All Customers"AutoPostBack="true"GroupName="g_Customers"OnCheckedChanged="rb_customers_all_CheckedChanged"/></td></tr><tr><td><asp:RadioButtonID="rb_customers_specific"runat="server"Text="Specific Customers"AutoPostBack="true"GroupName="g_Customers"OnCheckedChanged="rb_customers_specific_CheckedChanged"/></td><td><asp:UpdatePanelID="up_customer"runat="server"UpdateMode="Conditional"><ContentTemplate><asp:DropDownListID="ddl_customers_specific"runat="server"/> </ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="rb_customers_all"EventName="CheckedChanged"/><asp:AsyncPostBackTriggerControlID="rb_customers_specific"EventName="CheckedChanged"/></Triggers></asp:UpdatePanel></td></tr></table><table><tr><tdcolspan="2">
Non AJAX
</td></tr><tr><td><asp:RadioButtonID="rb_patients_all"runat="server"Text="All patients"AutoPostBack="true"GroupName="g_patients"OnCheckedChanged="rb_patients_all_CheckedChanged"/></td></tr><tr><td><asp:RadioButtonID="rb_patients_specific"runat="server"Text="Specific patients"AutoPostBack="true"GroupName="g_patients"OnCheckedChanged="rb_patients_specific_CheckedChanged"/></td><td> <asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional"><ContentTemplate><asp:DropDownListID="ddl_patients_specific"runat="server"/></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="rb_patients_all"EventName="CheckedChanged"/><asp:AsyncPostBackTriggerControlID="rb_patients_specific"EventName="CheckedChanged"/></Triggers></asp:UpdatePanel> </td></tr></table></form>
</
body></
html>Regards,
Because I have several pages that require full post backs in various sections.
I'm hopeful this isn't a "a page must have every control in an update panel to work right, plus you have to use some obscure page_load commands to set default values" scenario.
Here's another extension, really what led me to discover this whole mess in the first place. I've got a datagrid which contains a list of invoices that has all sorts of buttons for new/edit/print/options/etc. I added a textbox above all of this as a "quick lookup" feature where the customer types in the patients name and presses enter to limit the datagrid to just what they are looking for. Its a quick way of accessing one of the sections under options(aka, when the textchanged event fires on the textbox, if the textbox is empty, I set it for all patients, if its got some text, I set it for specific patient and fill in the text).
I even wrapped the whole thing in an update panel, got rid of conditional mode, trying to make it work properly.
<%@. Page Language="C#" AutoEventWireup="true" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head></head><body> <script runat="Server"> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { rb_patients_all.InputAttributes["checked"] = "true"; } } protected void TextChanged(object sender, EventArgs e) { string PatientName = (sender as TextBox).Text.ToLower(); if (PatientName.Length > 0) { //rb_patients_all.InputAttributes["checked"] = "false"; //rb_patients_specific.InputAttributes["checked"] = "true"; rb_patients_specific.Checked = true; //rb_patients_all.Checked = false; } else { //rb_patients_specific.InputAttributes["checked"] = "false"; //rb_patients_all.InputAttributes["checked"] = "true"; rb_patients_all.Checked = true; //rb_patients_specific.Checked = true; } this.tb_patients_specific.Text = PatientName; } protected void rb_patients_all_CheckedChanged(object sender, EventArgs e) { tb_patients_specific.BackColor = System.Drawing.Color.Red; } protected void rb_patients_specific_CheckedChanged(object sender, EventArgs e) { tb_patients_specific.BackColor = System.Drawing.Color.Blue; } </script> <form id="form1" runat="server"> <asp:ScriptManager runat="server" ID="sm" EnablePartialRendering="true" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <table> <tr> <td> <asp:RadioButton ID="rb_patients_all" runat="server" Text="All patients" AutoPostBack="true" GroupName="g_patients" OnCheckedChanged="rb_patients_all_CheckedChanged" /> </td> </tr> <tr> <td> <asp:RadioButton ID="rb_patients_specific" runat="server" Text="Specific patients" AutoPostBack="true" GroupName="g_patients" OnCheckedChanged="rb_patients_specific_CheckedChanged" /></td> <td> <asp:TextBox ID="tb_patients_specific" runat="server" /> </td> </tr> <tr> <td colspan="2"> Type and press enter <asp:TextBox ID="searchBox" runat="server" OnTextChanged="TextChanged" AutoPostBack="true" /></td> </tr> </table> </ContentTemplate> </asp:UpdatePanel> </form></body></html>
Hi NXTwoThou,
Take 8. I switched the radiobuttons with a radiobuttonlist. I hope this helps. I really hope
<%
@.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default2.aspx.cs"Inherits="Default2" %>
<!
DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><
htmlxmlns="http://www.w3.org/1999/xhtml"><
head></
head><
body><scriptrunat="Server">protectedvoid Page_Load(object sender,EventArgs e){
if (!IsPostBack){
this.RadioButtonList1.SelectedIndex = 0;ddl_patients_specific.Items.Add(
newListItem("Test"));}
}
protectedvoid TextChanged(object sender,EventArgs e){
string PatientName = (senderasTextBox).Text.ToLower();if (PatientName.Length > 0){
this.RadioButtonList1.SelectedIndex = 1;tb_patients_specific.BackColor = System.Drawing.
Color.Red;}
else{
this.RadioButtonList1.SelectedIndex = 0;tb_patients_specific.BackColor = System.Drawing.
Color.Blue;}
this.tb_patients_specific.Text = PatientName;}
protectedvoid rb_patients_all_CheckedChanged(object sender,EventArgs e){
ddl_patients_specific.BackColor = System.Drawing.
Color.Red;}
protectedvoid rb_patients_specific_CheckedChanged(object sender,EventArgs e){
ddl_patients_specific.BackColor = System.Drawing.
Color.Blue;}
</script><formid="form1"runat="server"><asp:ScriptManagerrunat="server"ID="sm"EnablePartialRendering="true"/><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><table><tr><td><asp:RadioButtonListID="RadioButtonList1"runat="server"><asp:ListItemSelected="True">All patients</asp:ListItem><asp:ListItem>specific patient</asp:ListItem></asp:RadioButtonList></td><td><asp:TextBoxID="tb_patients_specific"runat="server"/></td></tr><tr><tdcolspan="2">
Type and press enter
<asp:TextBoxID="searchBox"runat="server"OnTextChanged="TextChanged"AutoPostBack="true"/></td></tr></table></ContentTemplate></asp:UpdatePanel><table><tr><tdcolspan="2">Non AJAX</td></tr><tr><td><asp:RadioButtonID="rb_patients_all"runat="server"Text="All patients"AutoPostBack="true"Checked="true"GroupName="g_patients"OnCheckedChanged="rb_patients_all_CheckedChanged"/></td></tr><tr><td><asp:RadioButtonID="rb_patients_specific"runat="server"Text="Specific patients"AutoPostBack="true"GroupName="g_patients"OnCheckedChanged="rb_patients_specific_CheckedChanged"/></td><td><asp:DropDownListID="ddl_patients_specific"runat="server"/></td></tr></table></form></
body></
html>Hi NXTwoThou,
I'am very curious if it works for you. Let me know.
Regards,
No comments:
Post a Comment