It is a strange problem. I am setting the pagesize of gridview in dropdownlist selectedindexchanged which is i gridview pager template. Here is my html source
<PagerTemplate>
<div class="grid-footer">
<div class="gridfooter_size"> <asp:DropDownList ID="pageSize2" runat="server" AutoPostBack="true"
onselectedindexchanged="pageSize2_SelectedIndexChanged">
<asp:ListItem Value="10" Selected="True">10</asp:ListItem>
<asp:ListItem Value="25">25</asp:ListItem>
<asp:ListItem Value="50">50</asp:ListItem>
<asp:ListItem Value="100">100</asp:ListItem>
</asp:DropDownList>
</div>
<div class="gridfooter_info">
<asp:Label ID="lblSummary" runat="server"></asp:Label>
</div>
<div class="gridfooter_paginate">
<asp:LinkButton ID="lnkFirstbnt" runat="server" CommandName="Page" CssClass="pagerclass-nxt"
CausesValidation="false" CommandArgument="First">First</asp:LinkButton>
<asp:LinkButton ID="lnkPrevbnt" runat="server" CommandName="Page" CssClass="pagerclass-prev"
CausesValidation="false" CommandArgument="Prev">Previous</asp:LinkButton>
<asp:Label ID="CurrentPage" CssClass="pagerclass-number" Visible="false" runat="server"
Text="Label"></asp:Label>
<asp:LinkButton ID="lnkNextbnt" runat="server" CommandName="Page" CssClass="pagerclass-next"
CausesValidation="false" CommandArgument="Next">Next</asp:LinkButton>
<asp:LinkButton ID="lnkLastbnt" runat="server" CommandName="Page" CssClass="pagerclass-last"
CausesValidation="false" CommandArgument="Last">Last</asp:LinkButton>
</div>
</div>
</PagerTemplate>
Here is my code behind
Protected Sub pageSize2_SelectedIndexChanged(sender As Object, e As System.EventArgs)
Dim gvr2 As GridViewRow = GridView2.BottomPagerRow
Dim ddPageSize2 As DropDownList = DirectCast(gvr2.Cells(0).FindControl("pageSize2"), DropDownList)
GridView2.PageSize = Convert.ToInt32(ddPageSize2.SelectedValue)
Call GetDataTables2()
End Sub
When post back is occured the pageSize2_SelectedIndexChanged event is firing for all the selectd values of dropdownlist, but the page is not rendering. It is jumping from the pageSize2_SelectedIndexChanged event Call GetDataTables2() method. If the dropdownlist selectd value is 10, then the page is rendering, it strange. What might be the problem, Please suggest solution
The problem is, I am using two gridviews in the same update panel. And those two gridviews having the controsl with same IDs under the templates of two gridviews. This might be a bug in visual studio. It did not tell me any compile time exception and not even in runtime until I remove the updatepanel. I ahve changed the control IDs. Now it is working fine.
Related
A GridView will list rows which have to be approved/rejected. First column is named 'Action', which when clicked will display the ajax popupcontrolextender panel with two links (Approve/Reject). After the link is clicked, I need to update the status in the DB & refresh the GridView. ObjectDataSource is used to Bind the GridView. I have used the below code inside RowCommand event:
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim gvRow As GridViewRow = GridView1.Rows(index)
If e.CommandName = "Approve" Then
BusinessLogicLayer.UpdateFileStatus(sID, Approve)
ElseIf e.CommandName = "Reject" Then
BusinessLogicLayer.UpdateFileStatus(sID, Reject)
End If
GridView1.DataBind()
DirectCast(gvRow.FindControl("pceMenu"), AjaxControlToolkit.PopupControlExtender).Cancel()
HTML of the TemplateField 'Action':
<asp:TemplateField HeaderText="Action" >
<ItemTemplate>
<ajax:PopupControlExtender ID="pceMenu" runat="server" TargetControlID="imgMenu" PopupControlID="pnlMenu" Position="Right" >
</ajax:PopupControlExtender>
<asp:Image ID="imgMenu" runat="server" ImageUrl="~/Images/gear.png" CssClass="popupImage" />
<asp:Panel ID="pnlMenu" runat="server" CssClass="popupControl" Width="85px" Height="50px" style="display:none;">
<div class="menu-row" style="border-top: none;">
<asp:Image ID="imgApprove" runat="server" ImageUrl="~/Images/tick.png" style="float:left;"/>
<asp:LinkButton ID="lnkApprove" runat="server" Text="Approve" ToolTip="Approve" style="margin-left:10px;" CommandName="Approve" />
</div>
<div class="menu-row">
<asp:Image ID="imgReject" runat="server" ImageUrl="~/Images/delete16.png" style="float:left;"/>
<asp:LinkButton ID="lnkReject" runat="server" Text="Reject" ToolTip="Reject" style="margin-left:10px;" CommandName="Reject" />
</div>
</asp:Panel>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left"/>
<ItemStyle HorizontalAlign="Center" Width="5%"/>
</asp:TemplateField>
Tried the below methods, but no success:
Suppress the panel's visibility using style="display:'';"
Called the Cancel() method of the PopupControlExtender
Note: The pop-up disappears if I don't bind the GridView inside the RowCommand event. But, I need to refresh the results displayed after Approve/Reject.
Appreciate any help. Thanks!
Hi you can hide ajax control toolkit's modal popup extender from code behind try this code:
IdOfYourModelPopup.Hide();
i am trying to fill checkbox list in asp.net 4.0 inside update panel my code is,
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:PopupControlExtender ID="TextBox1_PopupControlExtender" runat="server" DynamicServicePath=""
Enabled="True" ExtenderControlID="" TargetControlID="TextBox1" PopupControlID="Panel1"
OffsetY="22">
</asp:PopupControlExtender>
<asp:Panel ID="Panel1" runat="server" Height="116px" Width="145px" BorderStyle="Solid"
BorderWidth="2px" Direction="LeftToRight" ScrollBars="Auto" BackColor="#CCCCCC"
Style="display: none">
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataTextField="holiday_name" DataValueField="holiday_name" AutoPostBack="True"
OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
</asp:CheckBoxList>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
my code behind is as,
CheckBoxList CheckBoxList1 = (CheckBoxList)Page.FindControl("CheckBoxList1");
CheckBoxList1.DataSource = Dcon.Tables[0];
CheckBoxList1.DataBind();
Dcon is dataset having values like,
holiday_name
mon
tue
wed
thur
I have not mentioned here checkboxlist1_selectedindex change event as on load it is giving error while populating checkbox list error is,
nullreferenceexception was unhandled by user code
on line,
CheckBoxList1.DataSource = Dcon.Tables[0];
i dont know why it is giving error when dataset has data ? and i initialy find control checkbox list as it is in ajax update panel and not finding this control directly
Hopes for your suggestion thanks in advance.
if it is a Content page of master page
then first..
find master page ContentPlaceHolder than find your control
ContentPlaceHolder mycont = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
CheckBoxList CheckBoxList1 = (CheckBoxList)mycont.FindControl("CheckBoxList1");
CheckBoxList1.DataSource = Dcon.Tables[0];
CheckBoxList1.DataBind();
I am working on a page that is using a gridview to display data. I have some dynamically created textboxes inside an ItemTemplate which contains several textboxes per row. Now I also have an update panel that is using ajax and should only render once my link button is clicked. The datalist is bound in my code behind after the I would like this to occur without causing a full postback. However, right now when I click the link button it causes a full post-back which eliminates my dynamically created controls.
I feel I am very close to a solution. I need one of these to happen (option 1 seems more useful):
Do not cause a postback when the linkbutton is clicked, but still render my full datalist in the update panel
or
my dynamically created controls are not removed during post back.
Here is my code:
<ItemTemplate>
[ <asp:LinkButton ID="SelectCommand" CommandName="Select" runat="server" Text="+" CssClass="sunocoBold"/> ]
<%-- start sub panel--%>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Vertical"
OnItemCommand="DataList_OnItemCommand">
<ItemTemplate>
<asp:LinkButton ID="Select" CommandName="SelectCommand" CommandArgument='<%#Eval("ship_to_num")%>' runat="server" Text='<%#Eval("ship_to_num")%>' />
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
<%-- end sub panel--%>
</ItemTemplate>
<asp:TemplateField HeaderText="Site Owner" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:Panel ID="pnlNames" runat="server">
</asp:Panel>
<%-- <asp:Literal ID="NameList" runat="server" /> --%>
</ItemTemplate>
</asp:TemplateField>
UpdatePanel.Triggers is made for this!
Take a look at it here: Understanding UpdatePanel.Triggers
So I have this Checkboxlist and I want to implement a Select All feature for the elements inside it. I placed it inside an UpdatePanel, but everytime I click an item, the entire page is reloaded. This is my code:
<asp:UpdatePanel ID="CBLPanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<div class="LeftAligned">
<asp:Label ID="FilterLabel" runat="server" Text="Filter by:" />
<asp:DropDownList runat="server" ID="FilterDDL" AutoPostBack="true" OnSelectedIndexChanged="FilterDDL_SelectedIndexChanged" />
<asp:ImageButton ID="FB" runat="server" ImageUrl="~/images/filter.png" AlternateText="VALUE"
CssClass="filter_button" OnClick="FB_Click" />
<div onmouseout="javascript:bMouseOver=false;" onmouseover="javascript:bMouseOver=true;"
class="filter_div">
<asp:CheckBoxList AutoPostBack="true" ID="FilterCheckBoxList" ClientIDMode="Static"
runat="server" CssClass="filter_checklist collapsed" OnSelectedIndexChanged="FilterCheckBoxList_Selected">
</asp:CheckBoxList>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
I though I should set ChildrenAsTriggers to false and this way I would update only from the code, but it doesn't seem to work.
This looks like a familiar .NET Bug. Setting ClientIDMode=Auto on the CheckBoxList should fix it
I am annoyed with a problem I have repeater control in updatepanel like this.
<asp:UpdatePanel ID="UpdPnlConstituentRepeater" ChildrenAsTriggers="true" runat="server">
<ContentTemplate>
<asp:Repeater ID="repConstituentInformation" runat="server" OnItemDataBound="repConstituentInformation_ItemDataBound">
<ItemTemplate>
<asp:DropDownList ID="dropRegistrantDownCostType" runat="server" AppendDataBoundItems="true"
AutoPostBack="true" OnSelectedIndexChanged="dropRegistrantDownCostType_SelectedIndexChanged"
EnableViewState="true">
<asp:ListItem Text="Select Type" Value="0" Selected="True" />
</asp:DropDownList>
<asp:CheckBoxList ID="chkBoxListRegistrantBenefits" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="chkBoxListRegistrantBenefits_SelectedIndexChanged">
</asp:CheckBoxList>
</itemTemplate>
</ContentTemplate>
</asp:UpdatePanel>
The problem I face that whenever I select any value from dropdown all the page gets refreshed After spending hours on the google I found a solution i.e, on itemdatabound event of repeater we just need to add the following code after finding the dropdown,
Dim sm As ScriptManager = ScriptManager.GetCurrent(Page)
sm.RegisterAsyncPostBackControl(objDropdownlist)
It worked very well for the dropdown but same is not working for checkboxlist like using the scripmanager instance if I write sm.RegisterAsyncPostBackControl(chkBoxListRegistrantBenefits), it is not working :(
Add ClientIDMode="AutoID" to the Repeater control.
You should not have to add any triggers and you should not even have to call RegisterAsyncPostBackControl. The ChildrenAsTriggers should take care of that.
on Repeater ItemDataBound event
use screiptmanager method RegisterAsyncPostBackControl
this.ScriptManager1.RegisterAsyncPostBackControl(
e.Item.FindControl(" put here your checkbox ID "));
Add this Before start of <ContentTemplate>:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="objDropdownlist" EventName="OnSelectedIndexChanged" />
</Triggers>