CheckBoxList OnSelectedChange event not fired - asp.net

I Have this type of code in Gridview in UpdatePanel..
Now when I Checked CheckBox then it fire its OnSelectedIndexChanged event But When I Select two or three CheckBox and then uncheck any checkbox among selected then it's
OnSelectedIndexChanged event is not fired..why this happen
<asp:Label ID="lbltempCity" runat="server" Text="City"></asp:Label>
<asp:CheckBoxList ID="lst" AutoPostBack="true" runat="server" Width="100px" Height="100px" BorderWidth="1px" BackColor="White" OnSelectedIndexChanged="hello">
<asp:ListItem>Test1</asp:ListItem>
<asp:ListItem>Test2</asp:ListItem>
<asp:ListItem>Test1</asp:ListItem>
<asp:ListItem>Test2</asp:ListItem>
</asp:CheckBoxList>
<asp:DropDownExtender ID="DropDownExtender1" runat="server" DropArrowWidth="300px" TargetControlID="lbltempCity" DropDownControlID="lst">
</asp:DropDownExtender>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblCity" runat="server" Text='<%# Eval("tempCity") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="15%" />
</asp:TemplateField>

I tested the code it is working fine. May be cause of problem is in grid or any other control in your page. post the full code so that we can help.

Related

Gridview TemplateField checkbox postback behavior in asp.net

I have GridView inside UpdatePanel and UpdateMode of the UpdatePanel is set to conditional.
Gridview contains asp:CheckBox as TemplateField and rest of the columns are boundfields which are dynamically created.
Checbox AutoPostBack is set to true and I update a datatable (which is inside session) based on checkbox value.
Here is markup:
<asp:GridView ID="ObjList" runat="server" CssClass="ObjList" AutoGenerateColumns="false" OnRowDataBound="ObjList_RowDataBound" AutoGenerateSelectButton="false" AllowPaging="False">
<Columns>
<asp:TemplateField HeaderText="&nbsp">
<HeaderTemplate>
<asp:CheckBox AutoPostBack="true" ID="chkAll" runat="server" OnCheckedChanged="HeaderChk_Changed" />
<asp:HiddenField ID="LinkNumIndexHead" runat="server" Value="-1" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox AutoPostBack="true" ID="chkRow" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem, "Selection")%>'
OnCheckedChanged="ChkRow_OnCheckChange" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
In Deployed version only:
Whenever user click 2 or more checkboxes in fast speed. Postback of first checkbox fires and rest of checkboxes get unchecked. How can I control this behavior?
When Local IIS is running:
Postback of every checkbox fires.
In Firebug debugging it is noticed that Postback of first checkbox takes quite a time.
Please tell me how can I avoid this situation.
Try this
<asp:GridView ID="ObjList" runat="server" CssClass="ObjList" AutoGenerateColumns="false"
OnRowDataBound="ObjList_RowDataBound" AutoGenerateSelectButton="false" AllowPaging="False">
<Columns>
<asp:TemplateField HeaderText="&nbsp">
<HeaderTemplate>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:CheckBox AutoPostBack="true" ID="chkAll" runat="server" OnCheckedChanged="HeaderChk_Changed" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:HiddenField ID="LinkNumIndexHead" runat="server" Value="-1" />
</HeaderTemplate>
<ItemTemplate>
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<asp:CheckBox AutoPostBack="true" ID="chkRow" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem, "Selection")%>'
OnCheckedChanged="ChkRow_OnCheckChange" />
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

ASP.NET - Get control in RowCommand event

Trying to access a RequiredFieldValidator control that's inside a GridView in the RowCommand event and having trouble.
Here's the partial GridView code:
<asp:TemplateField HeaderText="Password">
<ItemTemplate>
<asp:TextBox ID="txtPassword" runat="server" CssClass="GridViewTextbox" TextMode="Password" Text='<%#Eval("WebPassword") %>' Enabled="false"></asp:TextBox>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtWebPassword" runat="server" TextMode="Password" Text='<%#Eval("WebPassword") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvPassword" runat="server" SetFocusOnError="true"
ControlToValidate="txtWebPassword" Display="None" ErrorMessage='<%# Constants.Strings.PasswordRequired %>'></asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtAddWebPassword" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvAddPassword" runat="server" SetFocusOnError="true"
ControlToValidate="txtAddWebPassword" Display="None" ErrorMessage='<%# Constants.Strings.PasswordRequired %>'></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
As you can see, there's a RFV for the EditTemplate and FooterTemplate. My issue is this; when the page loads, it has all the records in it, including an emtpy row at the bottom (Footer). If I click Edit on a populated row, the data is populated correctly, then when I hit UPDATE, I get all the error messages from the FOOTER RFV's firing off, which isn't correct. So, in the RowCommand event, I'd like to attempt this: If the user clicks the EDIT button, then disable all the RFV's in the footer row (the add new row), if they click anything else, enable them.
Ideas?
Sorry, meant to put this in the first time. In the RowCommand event, I am able to find the control but when I set the properties to something bogus, it seems to get overridden later, by the RowDataBound event:
RequiredFieldValidator rfv = (RequiredFieldValidator)gvUsers.FooterRow.FindControl("rfvAddWebLogin");
rfv.ControlToValidate = string.Empty;
rfv.ErrorMessage = "sdfgsdfgsdgsdfgsdfgsdfgsdfg";
rfv.Enabled = false;
You should use different ValidationGroups in your EditItemTemplate and FooterItemplate:
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Button ID="BtnEdit" CausesValidation="False" Text="Edit" CommandName="Edit" runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="BtnUpdate" ValidationGroup="UpdateUser" Text="Update" CommandName="Update" runat="server" />
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="BtnInsert" ValidationGroup="InsertUser" Text="Add" CommandName="Insert" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Password">
<ItemTemplate>
<asp:TextBox ID="txtPassword" runat="server" CssClass="GridViewTextbox" TextMode="Password"
Text='<%#Eval("WebPassword") %>' Enabled="false"></asp:TextBox>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtWebPassword" ValidationGroup="UpdateUser" runat="server" TextMode="Password" Text='<%#Eval("WebPassword") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvPassword" ValidationGroup="UpdateUser" runat="server" SetFocusOnError="true"
ControlToValidate="txtWebPassword" Display="None" ErrorMessage='<%# Constants.Strings.PasswordRequired %>'></asp:RequiredFieldValidator>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtAddWebPassword" ValidationGroup="InsertUser" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvAddPassword" ValidationGroup="InsertUser" runat="server" SetFocusOnError="true"
ControlToValidate="txtAddWebPassword" Display="None" ErrorMessage='<%# Constants.Strings.PasswordRequired %>'></asp:RequiredFieldValidator>
</FooterTemplate>
</asp:TemplateField>
http://msdn.microsoft.com/en-us/library/bb426882.aspx#aspnett19_vldcntredtuics_topic7
Note: If you're using ValidationSummaries, you need to add the appropriate ValidationGroup to every ValidationSummary. If you leave this property blank, only controls without a specified ValidationGroup will be listed.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.validationsummary.validationgroup.aspx

ASP.NET - Fill/update row in gridview when a textbox loses focus

I have the following gridview that is inside an updatepanel:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="ButtonAdd" runat="server" OnClick="ButtonAdd_Click" Text="Novo Artigo" />
<asp:GridView ID="Dados" runat="server" AutoGenerateColumns="False" CssClass="Grid">
<Columns>
<asp:TemplateField HeaderText="Artigo">
<ItemTemplate>
<asp:TextBox ID="Artigo" runat="server"></asp:TextBox>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID="Artigo"
PopupControlID="PanelArtigos"
>
</asp:ModalPopupExtender>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Descrição">
<ItemTemplate>
<asp:TextBox ID="Descricao" runat="server" Width="300px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="IVA">
<ItemTemplate>
<asp:TextBox ID="IVA" runat="server" Width="40px" Enabled="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Pr. Unit.">
<ItemTemplate>
<asp:TextBox ID="PU" runat="server" Width="50px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="% Desc.">
<ItemTemplate>
<asp:TextBox ID="Desconto" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UN">
<ItemTemplate>
<asp:TextBox ID="UN" runat="server" Width="50px" Enabled="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quant.">
<ItemTemplate>
<asp:TextBox ID="Quantidade" runat="server" Width="50px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Liquido">
<ItemTemplate>
<asp:TextBox ID="TotalLiquido" runat="server" Enabled="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="RemoveArtigo" runat="server" OnClick="RemoveArtigo_Click">Remover
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle Font-Size="Small" />
<RowStyle Font-Size="Small" CssClass="grid" />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
As you can see, i have some textbox's.
When i change a value in a textbox, for example, the Desconto value, and leave that textbox, i want that the row where i am to be updated, using the new value present in the textbox. It's like a TextChanged or onBlur, but inside the update panel it's not working.
what is the best way to do it?
I am using VB.NET.
Thank you.
EDIT:
When adding the OnTextChanged="Desconto_TextChanged" i receive this compilation error:
Compilation Error Description: An
error occurred during the compilation
of a resource required to service this
request. Please review the following
specific error details and modify your
source code appropriately.
Compiler Error Message: BC30456:
'Desconto_TextChanged' is not a member
of 'ASP.index_aspx'.
Source Error:
Line 204:
Line 205:
Line 206:
Line 207:
Line 208:
Source File:
C:\inetpub\wwwroot\Facturas\Facturas\index.aspx
Line: 206
TextBox controls will not initiate a postback by default. you can set AutoPostBack to true for each textbox control.
I believe the event you need is TextChanged. Like lincolnk said, you need AutoPostBack set to True for the textbox to fire the postback. Then, inside the event handler, call Dados.DataBind() to reload the GridView's data.

ASP Updatepanel inside content disappears

I have an update panel with a gridview and some radios inside it. Senario is that when user select a radio, some bottoms get visible. But after radio eventhandler is trigered, updatepanel contents get dissapered. Any idea about this problem?
<asp:ScriptManager ID="scriptManager_main" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="updatePanel_main" runat="server">
<ContentTemplate>
<asp:GridView ID="gridView_stLists" runat="server" AutoGenerateColumns="False" CellPadding="3"
BorderStyle="NotSet" CssClass="table_layout" Width="500">
<RowStyle CssClass="table_body" />
<Columns>
<asp:TemplateField HeaderStyle-Width="20">
<ItemTemplate>
<asp:RadioButton ID="rdBtn_stdl" runat="server" OnCheckedChanged="rdBtn_stdl_CheckedChanged"
AutoPostBack="True" GroupName="stdl" value='<%# Eval("uri") %>' />
</ItemTemplate>
<HeaderStyle Width="20px" />
</asp:TemplateField>
...
The RadioButton is doing an AutoPostBack. Are you rebinding to the GridView after postback and thus overridding your changes/state? Only DataBind if !IsPostBack and this might address the issue.

ASP.Net AJAX TabControl

I have placed an AJAX Tabcontrol on my page.
Inside the TabControl, I also placed a gridview.
<cc1:TabContainer id="tabconLandTransPlan" runat="server" Height="300px" ActiveTabIndex="0" AutoPostBack="True">
<cc1:TabPanel runat="server" ID="tabMasterPlan" HeaderText="Master Plan" >
<HeaderTemplate>
<span style="font-size: 8pt; font-family: Arial">Master Plan</span>
</HeaderTemplate>
<ContentTemplate>
<asp:GridView id="gvBuffer" runat="server" Width="100%" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Type of Services">
<HeaderStyle Width="26%"></HeaderStyle>
<ItemTemplate>
<asp:Label id="Label1" runat="server" Text='<%# EVAL("code_desc") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tariff Code">
<HeaderStyle Width="4%" HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# EVAL("res_code") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</cc1:TabPanel>
When I retrieve the gridview, the gridview boundaries extend beyond the Tab Control boundaries. How Can I ensure that the gridview will be just within the boundaries of the tab control? The height of the Gridview is extending beyond the tab control. The width is just fine.
Thanks.
I may have found the answer to this little problem.
Apparently, the ajax tab control follows the size (height) of the controls inside it.
So what I did was set the height of the tabcontrol to Nothing (VB.Net).
Setting it to zero or any other percentage (conversion) values would otherwise throw an error.
Thanks to those who viewed.
Increase the height of the tab control!

Resources