UpdatePanel not firing inside Wizard - c#

I have an Update panel within a wizard:
<asp:WizardStep ID="WizardStep2" runat="server" StepType="Auto"
Title="Set the number of users required.">
...
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Always" runat="server">
<ContentTemplate>
<asp:Label runat="server" ID="ProgressInd" Text="Progress..." />
<asp:Button runat="server" OnClick="GoButton_Click" ID="ProgressBtn" Text="Go" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:WizardStep>
...
protected void GoButton_Click(object sender, EventArgs e)
{
ProgressInd.Text = "Progress... Moving";
}
When I take the update panel out of the wizard it works nicely but inside the wizard the click event just won't fire. I'm using Firefox to test, but IE doesn't work either. Any ideas or help appreciated.

For the record. Paolo spotted my problem. There were page validators that were preventing the event from firing.

Related

AsyncPostBackTrigger for Checkbox control not firing

Context of the problem:
I have a checkbox and a button. The button is disabled and colored grey upon the page load. I want the checkbox to enable and re-color the button if checked, and revert the change if unchecked. Think of it as a User Agreement page, where the user accepts the terms and needs to click on the checkbox to proceed.
There is a grid view and other components above the page that would break upon a postback, so searching online I found that I could use an UpdatePanel. Thought this would be more simple than writing jQuery for the checkbox, but it isn't working
Code:
ASPX
<asp:UpdatePanel ID ="upCheckbox" runat="server">
<ContentTemplate>
<asp:CheckBox ID="checkLabel" runat="server" OnCheckedChanged="checkLabel_CheckedChanged"/><asp:Label ID="AknowledgementLabel" runat="server" Text="Info is correct & Enable button"></asp:Label>
<br /><br />
<asp:Button ID="btnSubmit" Text="Submit Application" CssClass="jqbutton" OnClick="btnSubmit_Click" runat="server"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="checkLabel" EventName="CheckedChanged"/>
</Triggers>
</asp:UpdatePanel>
Code Behind:
protected void Page_Load(object sender, EventArgs e)
{
btnSubmit.Enabled = false;
btnSubmit.ForeColor = System.Drawing.Color.Gray;
}
protected void checkLabel_CheckedChanged(object sender, EventArgs e)
{
if (checkLabel.Checked)
{
btnSubmit.Enabled = true;
btnSubmit.ForeColor = System.Drawing.ColorTranslator.FromHtml("#336699");
}
else
{
btnSubmit.Enabled = false;
btnSubmit.ForeColor = System.Drawing.Color.Gray;
}
}
Problem:
The checkbox does not work and the submit button remains disabled. Not sure if I am using Update Panels for the appropriate purpose or if am missing something. Is it possible to accomplish this the way that I am trying to, or should I move on to jQuery?
You are missing AutoPostback="true" in your CheckBox control. By default it is set to false. With autopostback missing your event won't reach server side.
<asp:UpdatePanel ID ="upCheckbox" runat="server">
<ContentTemplate>
<asp:CheckBox ID="checkLabel" runat="server" AutoPostback="true" OnCheckedChanged="checkLabel_CheckedChanged"/>
<asp:Label ID="AknowledgementLabel" runat="server" Text="Info is correct & Enable button"></asp:Label>
<br /><br />
<asp:Button ID="btnSubmit" Text="Submit Application" CssClass="jqbutton" OnClick="btnSubmit_Click" runat="server"/>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="checkLabel" EventName="CheckedChanged"/>
</Triggers>
</asp:UpdatePanel>

button OnClick event doesn't fire at the first time in UpdatePanel

I have an issue on button OnClick event.
There is a refresh button in a user control ("header") which will refresh a place holder ("phContent") that generates some other user controls at run time. However, the button OnClick event doesn't fire until the whole place holder content loads.
Page.aspx
<ext:ContentHeader ID="header" runat="server" Visible="false" />
<asp:UpdatePanel ID="upControl" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:PlaceHolder ID="phContent" runat="server"></asp:PlaceHolder>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="header" EventName="OnFormSubmit" />
</Triggers>
</asp:UpdatePanel>
UserControl.ascx
<div>
<asp:Button ID="btnRefresh" runat="server" Text="Refresh" OnClick="btnRefresh_OnClick" />
</div>
UserControl.cs
protected void btnRefresh_OnClick(object sender, EventArgs e)
{
//some code
OnFormSubmit(this, e);
}
public delegate void UserControlFormSubmit(object sender, EventArgs e);
public event UserControlFormSubmit OnFormSubmit;
Not sure what exactly the page and source code is.
But from front-end, take for jQuery as example.
You can try something like:
jQuery(function(){
jQuery('#btnRefresh').on('click',function(){
//load the content by ajax
jQuery('#phContent').load('#chart');
});
});
You have to place the button in updatepanel as well.
<ext:ContentHeader ID="header" runat="server" Visible="false" />
<asp:UpdatePanel ID="upControl" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:Button ID="btnRefresh" runat="server" Text="Refresh" OnClick="btnRefresh_OnClick" />
</ContentTemplate>
</asp:UpdatePanel>

Not able to enable Panel which is outside the update panel from the update panel in asp.net

Here is the scenario,
I have one update panel in which I have radio button.
On check of radio button I want to enable Panel which is outside the update panel.
I have tried following 2 things:
Placing the panel in another update panel didn't work.
Using JavaScript on click of radio button didn't work.
placing the panel in another updatepanel and set update mode as conditional.
You need to do one more thing
On check of radio button event you need to call update method of newly added update panel
UpdatePanel1.Update();
I hope this code sample helps you.
<asp:UpdatePanel ID="udp1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:RadioButton ID="rb1" runat="server" AutoPostBack="true" OnCheckedChanged="Control_CheckedChanged"
Text="Text" GroupName="Group1" />
<asp:RadioButton ID="rb2" runat="server" AutoPostBack="true" OnCheckedChanged="Control_CheckedChanged"
Text="Text2" GroupName="Group1" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="udp2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnl1" runat="server" Visible="false">
<asp:Label ID="lblText" runat="server" Text="Text"/>
</asp:Panel>
</ContentTemplate>
<asp:AsyncPostBackTrigger ControlID="rb1" />
<asp:AsyncPostBackTrigger ControlID="rb2" />
</asp:UpdatePanel>
protected void Control_CheckedChanged(object source, EventArgs e)
{
pnl1.Visible=rb1.Checked;
}

Stopping auto page refresh

I use the below code to auto refresh the page every 60 seconds via the AJAX tools in VS2010. Works perfectly.
<asp:MultiView ID="MultiView1" runat="server">
<asp:View ID="View1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ViewStateMode="Enabled" UpdateMode="Conditional">
<ContentTemplate>
ASP.NET/HTML Code
<p>
<asp:Button ID="Button2" runat="server" Text="Click here" OnClick="Button2_Click" /> to disable the pages automatic refresh.</p>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer ID="Timer1" runat="server" Interval="60000">
</asp:Timer>
</asp:View>
<asp:View ID="View2" runat="server">
etc.
</asp:MultiView>
I want to include a button on the asp.net page to cancel the auto refresh.
I tried to include the below but when I clicked the button, it didn't work. The below is the Code Behind for an OnClick event for a Button. The asp.net code is in the above code.
protected void Button2_Click(object sender, EventArgs e)
{
Timer1.Interval = 0;
}
Where am I going wrong? Is this even a way to do this or do I need to go another route in order to allow the user to cancel the auto page refresh?
Thanks to PeterJ I have found the solution. I modified the code and since I clicked it the page has not refreshed. The issue was with my code behind for the button OnClick event. I had:
Timer1.Interval = 0;
When I should have had:
Timer1.Enabled = false;

Not using asp listbox well

All I wish to do is simply click a button and the text in a textbox is automatically added as an item in the listbox. Shouldn't this be straight forward? Whilst debugging, the item is added and I can see the text by watching ListBox1.Items[0], but nothing is displayed in the web page. I had the same problem which i did not solve, in a console application! Can some one please guide me to what I am doing wrong?
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Add(new ListItem(TextBox1.Text));
}
Many thanks
Edit:
In a past project, I used the DataSource property, which worked perfectly. I have never yet managed to use the add Items! May be there is some sort of refresh or update?
Page code:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:ListBox ID="ListBox1" runat="server" Height="150px" Width="295px"></asp:ListBox>
<asp:UpdatePanel ID="updatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
Looks like your listbox is outside of the update panel. Pop it inside the update panel:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="AddItem" />
</ContentTemplate>
</asp:UpdatePanel>
You have to move the ListBox into the UpdatePanel, otherwise it will not be updated.
The reason for that is, that ASP.NET is sending the whole HTML of the UpdatePanel back to the client. Since the ListBox is not part of the UpdatePanel, it won't be updated.

Categories