asp.net Update Panel capturing Button clicks - asp.net

I have a page that has an ASP.NET UpdatePanel on it. The UpdatePanel contains a repeater, and within the repeater is a command button. (please see the code example below)
When I click on the button the first time, nothing happens. But the second time I click on the same button, then I get the event I was expecting triggered. I am at a loss as to why this is, though I am sure there is a simple explanation. Any advice would be helpful.
<!-- Drivers Table -->
<asp:UpdatePanel runat="server" ID="DriverUpdatePanel" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:HiddenField runat="server" ID="DriverErrors" />
<asp:Repeater ID="DriverRepeater" runat="server" OnItemDataBound="DriverRepeater_ItemDataBound" OnItemCommand="DriverRepeater_ItemCommand">
<HeaderTemplate>
<table cellspacing="0" class="section-table">
<tr>
<td class="bg_mid" colspan="7"><img src="/images/sections/drivers.png" alt="Drivers" /></td>
</tr>
<tr>
<td class="text_1 left-cell">#</td>
<td class="text_1">Name</td>
<td class="text_1">Date Of Birth</td>
<td class="text_1">Gender</td>
<td class="text_1">License #</td>
<td class="text_1">Relationship</td>
<td class="text_1" align="right"> </td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr id="DriverRow" runat="server">
<td class="text_2 required left-cell"><asp:Label ID="DriverNumber" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "DriverNumber")%>'></asp:Label></td>
<td class="text_2 required"><asp:Label ID="DriverName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "FirstName")%>'></asp:Label></td>
<td class="text_2 required"><asp:Label ID="BirthDate" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "BirthDate")%>'></asp:Label></td>
<td class="text_2 required"><asp:Label ID="Gender" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Gender").ToString() == "F" ? "Female" : "Male" %>'></asp:Label></td>
<td class="text_2 required"><asp:Label ID="DriversLicenseNumber" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "LicenseInformation.DriversLicenseNumber")%>'></asp:Label></td>
<td class="text_2 required"><asp:Label ID="RelationshipToApplicant" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "RelationshipToApplicant")%>'></asp:Label></td>
<td class="text_2 right-cell" align="right"><asp:ImageButton runat="server" ID="DriverEditButton"
ImageUrl="/images/edit.jpg" AlternateText="Edit" CommandName="Edit" CausesValidation="false" /></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>

make UpdatePanel Mode="Conditional" and enableviewstate="true"
you not need to defined trigger and you work is done without it.

Related

Update panel with each row in repeater

I have repeater and when i put update panel in each row its still loading all other update panels is there any reason for this?
It should only update that part only that is i want to achieve.
<asp:Repeater runat="server" ID="grd" >
<HeaderTemplate>
<table class=" table-serviceline table table-hover table-bordered">
</HeaderTemplate>
<ItemTemplate>
<tr class="service-line-item" id="<%#"serviceline"+ Eval("ClaimServiceID") %>">
<td class="fw65">
<table class="table-small-pad">
<tr>
<td>
<asp:Label ID="lblID" ClientIDMode="Static" Text='<%#Container.ItemIndex+1 %>' runat="server"></asp:Label>
</td>
</tr>
</table>
</td>
<td class="fw150">
<table class="table-small-pad">
<tr>
<td>
<asp:UpdatePanel ID="upd" runat="server">
<ContentTemplate>
<div class="input-group">
<asp:TextBox ID="txtCODE" runat="server" CssClass="form-control" Text='<%# Bind("Code") %>' ToolTip="Code" MaxLength="15" />
<span class="input-group-addon"></span>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
I believe that the combo of
UpdateMode="Conditional"
and
ChildrenAsTriggers="True"
in the UpdatePanel is what you are looking for. If you don't set the first parameter, UpdatePanels update on any postback.

Control inside repeater causing full postback even after keeping in update panel

In my page, I have one search button and a repeater. I have wrapped everything inside UpdatePanel. My search button do not causes full postback, i.e ideal but RadioButtonList inside Repeater control does. I have no idea what to do.
<asp:UpdatePanel ID="up" runat="server">
<ContentTemplate>
<table align="center" border="1" cellspacing="0" class="tabmn6">
<tr id="trheader" runat="server">
<th id="trEdit" runat="server">Edit</th>
<th>User Name </th>
<th>Role</th>
<th>From Date</th>
<th>To Date</th>
<th>Comment</th>
<th>Status</th>
</tr>
<asp:Repeater ID="rpUserDetails" runat="server" OnItemDataBound="rpUserDetails_ItemDataBound">
<ItemTemplate>
<tr>
<td id="tdRPEdit" runat="server" align="center">
<input type="button" class="editbtn" name="btnEdit" id="btnEdit" runat="server" onclick='<%# string.Format("javascript:return AddBoardCast(\"{0},{1}\")", Eval("BC_ID"),"Edit") %>'>
</td>
<td id="trRPTL" runat="server" align="center">
<asp:Label ID="lblUName" runat="server" ForeColor="Red" Text='<%#Eval("UserName")%>' />
</td>
<td align="center">
<asp:Label ID="lblRoleName" runat="server" ForeColor="Black" Text='<%#Eval("RoleName")%>' />
</td>
<td align="center">
<asp:Label ID="lblToDate" runat="server" ForeColor="Black"><%#DataBinder.Eval(Container.DataItem, "BC_FromDate", "{0:dd/MM/yyyy}")%></asp:Label>
</td>
<td align="center"><asp:Label ID="lblFromDate" runat="server" ForeColor="Black"><%#DataBinder.Eval(Container.DataItem, "BC_TODate", "{0:dd/MM/yyyy}")%></asp:Label></td>
<td align="center" width="20%">
<div style="color: black"><%#Eval("BC_Comment")%></div>
</td>
<td align="center">
<asp:HiddenField ID="hdnBC_ID" runat="server" Value='<%#Eval("BC_ID") %>' />
<asp:HiddenField ID="hdnUserID" runat="server" Value='<%#Eval("UserID") %>' />
<asp:RadioButtonList ID="rdStatus" runat="server" Height="48px" RepeatDirection="Horizontal" AutoPostBack="true" OnSelectedIndexChanged="rdStatus_SelectedIndexChanged" CssClass="rad">
<asp:ListItem Text="Active" Value="1"></asp:ListItem>
<asp:ListItem Text="Deactive" Value="0"></asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</ContentTemplate>
</asp:UpdatePanel>

Ajax UpdatePanel not working in IE9

I am using updatepanel to avoid the postback and the code is working fine in IE8 and firefox but not in IE9. I also tried installing latest ajax toolkit from codeplex but it did not help me either.Please help me with this. My code is something like below/....
<table width="800px">
<tr>
<asp:UpdatePanel runat="server" ID="upCountry">
<ContentTemplate>
<td class="TextLabelForHeader" width="300px">
Country:
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="ddlCountry"
ErrorMessage="*" InitialValue="Select.." ValidationGroup="VGHeader"></asp:RequiredFieldValidator>
</td>
<td align="left">
<asp:DropDownList ID="ddlCountry" runat="server" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged"
AutoPostBack="true" OnDataBound="ddlCountry_DataBound" onchange="SelectCurrency(this);"
ValidationGroup="VGHeader">
</asp:DropDownList>
</td>
<td align="left">
</td>
</ContentTemplate>
</asp:UpdatePanel>
</tr>
<tr>
<asp:UpdatePanel runat="server" ID="upCurrency">
<ContentTemplate>
<td class="TextLabelForHeader" width="300px">
Currency:
</td>
<td align="left">
<asp:DropDownList ID="ddlCurrency" runat="server" ValidationGroup="VGHeader">
</asp:DropDownList>
</td>
<td align="left">
</td>
</ContentTemplate>
</asp:UpdatePanel>
</tr>
<tr>
<td class="TextLabelForHeader" width="300px">
Client:
<%--<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="ddlClient" ErrorMessage="*" InitialValue="Select.."
ValidationGroup="VGHeader"></asp:RequiredFieldValidator>--%>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtClient"
ErrorMessage="*" ValidationGroup="VGHeader"></asp:RequiredFieldValidator>
</td>
<td align="left">
<%-- <asp:DropDownList ID="ddlClient" runat="server" Height="16px" Width="143px" Enabled="false"
OnDataBound="ddlClient_DataBound" onchange="DisplayTextbox(this);" ValidationGroup="VGHeader">
</asp:DropDownList>--%>
<asp:TextBox ID="txtClient" runat="server" Width="143px" ReadOnly="true" ValidationGroup="VGHeader"></asp:TextBox>
<%--<div id="form_ProductContainer" style="display: none;">
<asp:TextBox ID="txtNewClientName" runat="server"></asp:TextBox>
</div>--%>
</td>
<td class="TextLabelForHeader" style="text-align: left;">
<asp:Button ID="btnContinue" runat="server" OnClick="btnContinue_Click" Text="Continue"
ValidationGroup="VGHeader" />
</td>
</tr>
</table>
Discussion: Is it vital that it uses IE9 as is? If it isn't then you could just force it to render as IE8 with the following code inserted in the head section of the page or master page.
Possible Solution:
<meta http-equiv="X-UA-Compatible" content="IE=IE8" />
Updated Response
Identified Issue: I had a look at your code and you have no update Panel inside the last TR element. I imagine now that the code originally worked in IE8 because you probably had another update panel that covered the entire table.

how to show header row either listview has data or not?

I have a list view and i want to add a header row in it which will come when the listview has data or not. in each and every condition i want it there. I have used LayOut Template to do so but its showing the Header row only if the listview has data.Then i tried EmptydataTemplate, Its showing the header row but now the button in it is not working.
My code is
<asp:UpdatePanel ID="upViewSchedule" runat="server">
<ContentTemplate>
<asp:ListView ID="lstuser" runat="server" ItemPlaceholderID="trItem" DataKeyNames="id"
OnItemDataBound="lstuser_ItemDataBound">
<LayoutTemplate>
<table cellspacing="0">
<tr class="hdrRowColor1">
<td align="left">
name
</td>
<td align="left">
salary
</td>
<td align="left">
address
</td>
<td align="left" style="border-right: 1px solid #6398cc">
Actions
</td>
</tr>
<tr class="OddRowColor">
<td align="left">
<asp:DropDownList ID="drphdrname" runat="server" Width="120px">
</asp:DropDownList>
<ajaxCtrl:CascadingDropDown ID="csddrphdrName" runat="server" TargetControlID="drpname"
Category="Name" ServicePath="~/Resources/WebService.asmx" ServiceMethod="GetName">
</ajaxCtrl:CascadingDropDown>
</td>
<td>
<asp:TextBox ID="txtaddress" runat="server" Width="110px"></asp:TextBox>
</td>
<td width="50px" class="last">
<asp:ImageButton ID="imgBtnHdrAdd" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/add_new.png"
OnClick="imgBtnHdrAdd_Click" ToolTip="Add user." />
</td>
</tr>
<tr id="trItem" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class='<%# Convert.ToBoolean(Container.DataItemIndex % 2) ? "OddRowColor" : "EvenRowColor" %>'>
<td align="left" width="138px">
<asp:DropDownList ID="drpname" runat="server" Width="120px">
</asp:DropDownList>
<asp:Label ID="lblCreatedBY" Text='<%# Eval("CreatedBy") %>' runat="server" Visible="false"></asp:Label>
<asp:Label ID="lblId" runat="server" Visible="false"></asp:Label>
<ajaxCtrl:CascadingDropDown ID="casddrpContacts" runat="server" TargetControlID="drpname"
Category="name" ServicePath="~/Resources/WebService.asmx" ServiceMethod="Getuser">
</ajaxCtrl:CascadingDropDown>
</td>
<td align="left" width="138px">
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("salary") %>' Width="110px"></asp:TextBox>
</td>
<td align="left" width="138px">
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("address") %>' Width="110px"></asp:TextBox>
</td>
<td align="left" class="last">
<asp:ImageButton ID="imgBtnEdit" runat="server" ImageUrl="~/App_Themes/ThemeNew2/images/update.png"
CommandArgument='<%# Eval("id") %>' OnClick="imgBtnEdit_Click" ToolTip="Update user" />
<asp:ImageButton ID="imgBtnDelete" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/delete.png"
CommandArgument='<%# Eval("id") %>' OnClientClick="return confirm('Are you sure you want to delete this user ?');"
ToolTip="Delete user" OnClick="imgBtnDelete_OnClick" />
</td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
<table cellspacing="0">
<tr class="hdrRowColor1">
<td align="left">
name
</td>
<td align="left">
salary
</td>
<td align="left">
address
</td>
<td align="left" style="border-right: 1px solid #6398cc">
Actions
</td>
</tr>
<tr class="OddRowColor">
<td align="left">
<asp:DropDownList ID="drphdrname" runat="server" Width="120px">
</asp:DropDownList>
<ajaxCtrl:CascadingDropDown ID="csddrphdrName" runat="server" TargetControlID="drpname"
Category="Name" ServicePath="~/Resources/WebService.asmx" ServiceMethod="GetName">
</ajaxCtrl:CascadingDropDown>
</td>
<td>
<asp:TextBox ID="txtaddress" runat="server" Width="110px"></asp:TextBox>
</td>
<td width="50px" class="last">
<asp:ImageButton ID="imgBtnHdrAdd" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/add_new.png"
OnClick="imgBtnHdrAdd_Click" ToolTip="Add user." />
</td>
</tr>
<tr id="trItem" runat="server">
</tr>
</table>
</EmptyDataTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
my Code behind code is
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BIndAddress();
// BindRoleDrop();
drpAddress.Items.Insert(0, new ListItem("Select Area", ""));
drpRoom.Items.Insert(0, new ListItem("Select Room", ""));
ViewState["sortCol"] = "tblUser.id";
ViewState["sortDir"] = "Desc";
ViewState["nmbr"] = 1;
BindData(ViewState["sortCol"].ToString(), ViewState["sortDir"].ToString(), Convert.ToInt32(ViewState["nmbr"]), 7999);
}
else
{
lblMessage.Visible = false;
}
}
And one thing more please let me know how can i apply validations on these.
I did some testing locally. I found that if I have a button in the EmptyDataTemplate it's OnClick event will fire as expected as long as you do not modify the state of the ListView before the event fires.
I'm guessing therefore that you have some code that modifies the state (re-binds it for instance) of the ListView which runs before the imgBtnHdrAdd_Click event handler for the button in question.
The Page_Load method would have been the primary suspect, but based on your code it is properly checking for !IsPostBack.
I'm assuming that it is the call to BindData that is used for setting databinding the ListView. Look for other places in you code behind where that method is called and verify that none of those places are being run before the event handler for the button.

asp.net (Visual Studio 2010) form validation controls

Afternoon All,
I have a web form that i wish my user to fill out. On the form i have three fields that i wish to set validation on. One of these is a normal textbox, the other a textbox associated with a calendar icon and my last field is a drop down list that has data held in it populated from an Enum list.
Im not too worried about my dropdown list yet, but i am getting slightly frustrated with my other two textboxes. I have used a 'Required Filed Validator' on both of these and only want the validation to kick in when the users clicks the submit button. At the moment if you tab or click between these two fields the validation kicks in.
Here is my web form....
<table id="table-3">
<tr>
<td style="width: 385px">
<asp:Label ID="lblOrganiser" runat="server" Text="Meeting Organiser:">
</asp:Label></td>
<td class="style4" style="width: 23px">
<asp:TextBox ID="txtOrganiser" runat="server" >
</asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldVal0"
ControlToValidate="txtOrganiser"
ErrorMessage="Meeting Organiser"
Text="*"
runat="server"/>
</td>
<td>
<asp:Label ID="lblDate" runat="server" Width="40px" Text="Date:">
</asp:Label>
</td>
<td class="style5">
<asp:TextBox ID="txtAgendaDate" runat="server" ForeColor="Black" >
</asp:TextBox>
<asp:ImageButton runat="Server" ID="ImageButton1" ImageUrl="~/images/contact_date_SM3.png"
AlternateText="Click here to display calendar" ImageAlign="AbsMiddle" />
<asp:calendarextender ID="CalendarExtender3" runat="server"
TargetControlID="txtAgendaDate" PopupButtonID="ImageButton1" Format="dd/MM/yyyy"></asp:calendarextender>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldVal1"
ControlToValidate="txtAgendaDate"
ErrorMessage="Date"
Text="*"
runat="server"/>
</td>
</tr>
<tr>
<td style="width: 385px"><asp:Label ID="lblAgendaTypeDescription" runat="server" Text="Type Of Meeting:"></asp:Label></td>
<td class="style4" style="width: 23px">
<asp:TextBox ID="txtAgendaTypeDescription" runat="server" Text="Monthly" BackColor="#F4F4F4" ReadOnly="True"></asp:TextBox>
</td>
<td></td>
<td class="style7" style="width: 24px"><asp:Label ID="lblTime" runat="server" Text="Time"></asp:Label></td>
<td><asp:TextBox ID="txtTime" runat="server"
Text="4pm" style="margin-top: 2px"></asp:TextBox></td>
<td></td>
</tr>
<tr>
<td style="width: 385px">
<asp:Label ID="lblVenue" runat="server" Text="Venue"></asp:Label>
</td>
<td class="style4" colspan="6"><asp:TextBox ID="txtVenue" runat="server"
Text="Room 1" Width="550px" TextMode="SingleLine" ></asp:TextBox></td>
</tr>
<tr>
<td style="width: 385px"><asp:Label ID="lblRead" runat="server" Text="Please Read:"></asp:Label></td>
<td class="style4" colspan="6">
<asp:TextBox ID="txtRead" runat="server"
Width="550px" TextMode="SingleLine" Font-Names="Verdana" ></asp:TextBox></td>
</tr>
<tr>
<td style="width: 385px"><asp:Label ID="lblBring" runat="server" Text="Please Bring:"></asp:Label></td>
<td class="style4" colspan="6">
<asp:TextBox ID="txtBring" runat="server"
Width="550px" TextMode="SingleLine" Font-Names="Verdana" ></asp:TextBox></td>
</tr>
<tr>
<td style="width: 385px"><asp:Label ID="lblAgendaStatus" runat="server" Text = "Agenda Status" ></asp:Label></td>
<td class="style4" style="width: 23px">
<asp:DropDownList ID="AgendaStatus"
runat="server" Height="24px" Width="125px"> </asp:DropDownList>
</td>
<td> <asp:RequiredFieldValidator ID="RequiredFieldVal2"
ControlToValidate="AgendaStatus"
ErrorMessage="Agenda Status"
Text="*"
runat="server"/>
</td>
</tr>
</table>
<br />
<asp:ValidationSummary ID="ValidationSummary2"
HeaderText="You must enter a value in the following fields:"
DisplayMode="BulletList"
EnableClientScript="true"
runat="server"/>
<br />
<div style="text-align: right;">
<asp:ImageButton runat="Server" ID="btnAddMonthlyTemplate" ImageUrl="~/images/Addbutton.png"
AlternateText="Add Weekly Template" />
</div>
If anyone cant point me in the right direction that would be great. Many thanks in advance.
Betty
You can set the EnableClientScript property of the RequiredFieldValidator to false:
<asp:RequiredFieldValidator ID="RequiredFieldVal1"
ControlToValidate="txtAgendaDate"
ErrorMessage="Date"
Text="*"
EnableClientScript="false"
runat="server"/>
that way the validation will accur only after the user posts the form.
Hope this helps,
Shai.

Resources