Button click not working inside gridview inside updatepanel - c#

I have a div that has a gridview inside an updatepanel, that I use bootbox.js to show modal.
Inside the gridview is an itemtemplate with an asp.net button "Button1" which I need to click to edit the row after modalpopup but this doesnt fire
Please what am I missing
<div id="userForm" class="form-horizontal" style="display:none;width:100%;border:solid 0px;" >
<input ID="btnshowRun" type="button" Value="Show Leave" class="btn btn-warning " style="float:lefts;" OnClick ="showhide();"/>
<asp:UpdatePanel ID="UpdatePanel5" runat="server" style="display:none;">
<ContentTemplate>
<asp:GridView ID="GridView2" runat="server" AllowSorting="False"
AutoGenerateColumns="False" DataKeyNames="EntryID"
EmptyDataText="There are no data records to display."
ShowFooter="False" HorizontalAlign="Center" OnRowCommand="gvl_RowCommand"
ShowHeaderWhenEmpty="True" CssClass="table table-striped table-bordered table-hover table-responsive table-condenseds " Width="100%" GridLines="None">
<Columns>
<asp:TemplateField HeaderText="Total" SortExpression="Total">
<EditItemTemplate>
<asp:TextBox ID="tot" runat="server" Text='<%# Bind("Total") %>' class="form-control"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Total") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="CommandButton" runat="server" CommandArgument='<%# Eval("EntryID") %>' UseSubmitBehaviour=true CausesValidation="False"
CommandName="Update" OnCommand="Updates_Command" Text="Update" class="btn btn-primary btn-sm contrl" Style="margin-right: 10px;"
/>
<asp:LinkButton ID="Button2" runat="server" CausesValidation="False" CommandName="Cancel" class="btn btn-warning btn-sm contrl" Style="margin-right: 10px;"
Text="Cancel" />
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="Button1" runat="server" CommandArgument='<%# Eval("EntryID") %>' class="form-control btn btn-default btn-blocks contrl btn-sms"
CommandName="Edit" OnCommand="Button1_Command" Text="Edit" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle HorizontalAlign="Center" Font-Bold="True" ForeColor="Black"></HeaderStyle>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>

The problem with modals is that they usually place the contents outside of the <form> tag. And then the Buttons do not work anymore.
Replace the Buttons with LinkButtons. They perform a PostBack with JavaScript and will work from a Modal.

I wasnt handling rowediting event hence I was getting an error when I checked the developer view in firefox.Now it fires for me to edit but its after the second click of the link button before it enables the editing.Any ideas?

Related

ajax calendar not displaying in child gridview

Ajax Calendar not displaying in child GridView
<asp:GridView ID="GVCollapse" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" OnClick="Show_Hide_ChildGrid" ImageUrl="~/images/plus.png" CommandArgument="Show" Height="20" Width="20" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none;">
<asp:GridView ID="gvOrders" runat="server">
<asp:TemplateField HeaderText="Dispatch Date">
<ItemTemplate>
<asp:TextBox Width="90px" ID="txtDispatchDate" runat="server" Text=""></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" Format="dd/MM/yyyy"
PopupButtonID="txtDispatchDate" TargetControlID="txtDispatchDate">
</ajaxToolkit:CalendarExtender>
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Ajax Calendar is not working in child gridview whereas I did the same thing with parent gridview then it's working well
is Ajax calendar not working with child gridview?? or I did any mistake. I posted my design code

Is there a way to turn a Button in GridView to a link text?

The size of the button really kills the width of my GridView and so I am looking to just change the buttons into a link (like if you were to use AutoGenerateEditButton or AutoGenerateDeleteButton). Here's what I have:
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="editButton" runat="server" CommandName="Edit"
Text="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="BtnUpdate" runat="server" CommandName="Update"
Text="Edit" />
<asp:Button ID="BtnCancel" runat="server" CommandName="Cancel"
Text="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
How would I change what I have into just a text that is like a link (once again, like if it was from AutoGenerateEditButton). I can't set that to true because I need to conditionally hide it and I can't seem to do it if it's automatically generated. If you know a way to conditionally hide it when it's automatically generated, please let me know!
Take note that I'm using a SQLDataSource.
Use a LinkButton MSDN
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="editButton" runat="server" CommandName="Edit">Edit</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<div style="white-space: nowrap;">
<asp:LinkButton ID="BtnUpdate" runat="server" CommandName="Update">Edit</asp:LinkButton>
<asp:LinkButton ID="BtnCancel" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
</div>
</EditItemTemplate>
</asp:TemplateField>

ValidationGroup on Fileupload

I have a FormView where there is a FileUpload with a RequiredFieldValidator and I need to have a validationGroup on the FileUpload or else my Button won't go it's PostBackUrl.
My code:
<asp:FormView ID="fwResultsInsert" runat="server" DataKeyNames="ResultsID"
DataSourceID="ObjResults" DefaultMode="Insert">
<InsertItemTemplate>
<asp:Label ID="lblImagess" runat="server" Text="Resultat Billede:"></asp:Label>
<asp:FileUpload ID="fuResultsImages" runat="server" />
<asp:RequiredFieldValidator ID="rfvImage" runat="server" ErrorMessage="*Her mangler noget!!" ControlToValidate="fuResultsImages"></asp:RequiredFieldValidator>
<asp:Label ID="lblOutput" runat="server" Text="" Visible="True"></asp:Label>
<asp:Label ID="Error" runat="server" Text="" Visible="True"></asp:Label>
<asp:ImageButton ID="imgPicture" runat="server" Visible="True" />
<br />
<asp:LinkButton ID="btnInsert" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insæt" onclick="btnInsert_Click" ForeColor="#000000" Font-Underline="True" />
<asp:LinkButton ID="btnCancel" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Fortryd" ForeColor="#000000" Font-Underline="True" />
</InsertItemTemplate>
</asp:FormView>
<asp:Button ID="btnHome" runat="server" Text="Forsiden" PostBackUrl="~/BackEnd/Default.aspx" />
I need to have some kind of validation on my FileUpload, so there have to be something in the fileupload-box when I clink insert, atm I have a RequiredFieldValidator, but there is a conflict with another Button I have outside the FormView, atm when I click the button nothing happens unless there is something in the FileUpload, and that's not the point.
Add CausesValidation="false" to the Button which you have outside the FormView.
Ex:
<asp:Button ID="btnHome" runat="server" Text="Forsiden" PostBackUrl="~/BackEnd/Default.aspx" CausesValidation="false" OnClick="btnHome_Click" />

make grid view auto scrollable

I have a grid. I have a button down that if i click on that button it will add an empty row to that grid in which i will edit and save. I need to display a scroll bar so that when i click on that button it will add empty row in the end of grid with scroll bar at the end
<div id="Div" runat="server" class="divFieldRow">
<div>
<center>
<div style="overflow: auto; height: 150px">
<asp:GridView ID="gvEventMechanic" runat="server" AutoGenerateColumns="False" PageSize="5"
GridLines="None" AllowSorting="true" BorderWidth="1"
BorderColor="Brown" AlternatingRowStyle-BackColor="Cyan" HeaderStyle-BackColor="ActiveCaption"
FooterStyle-BackColor="DimGray" EnableViewState="true" >
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Disable
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:CheckBox ID="chkDelete" runat="server" AutoPostBack="true" OnCheckedChanged="cbDelete_OnCheckedChanged"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<HeaderTemplate>Event</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="lblDesc" Visible='<%# ! IsInEditMode %>' runat="server" Text='<%# Eval("Description") %>' />
<asp:TextBox ID="txtDesc" Visible='<%# IsInEditMode %>' runat="server" Text='<%#Eval("Description")%>' MaxLength="255">
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</center>
</div>
Using a div that wraps the grid with fixed height and overflow should do the trick in case the table exceeds the fixed height. With paging involved you may switch to the last available page in the grid and rebind it, if that is what you want to achieve.

Usercontrols which don't trigger events for visitors

This UpdatePanel is contained by an UserControl. When the LinkButton is pressed arow should be added in another GridView. When an user is logged in this control is working well.
The problems appears when an user is not logged in and try to push that button. No event triggers.
Someone suggested me to give a permission for accessing this control in web.config. That didn't work.
Anyone has another idea?
<asp:UpdatePanel runat="server" UpdateMode="Conditional" EnableViewState="true" ID="IngredientsUpdatePanel">
<ContentTemplate>
<asp:ObjectDataSource ID="sourceIngredients" runat="server" SelectMethod="GetAll">
</asp:ObjectDataSource>
<asp:GridView ID="Ingredients" AllowPaging="true" runat="server" DataKeyNames="IngredientId"
EnableViewState="true" DataSourceID="sourceIngredients" PageSize="5"
AutoGenerateColumns="false" HorizontalAlign="Center" OnSelectedIndexChanged="Ingredients_SelectedIndexChanged">
<RowStyle HorizontalAlign="Center" />
<HeaderStyle Font-Bold="true" ForeColor="Black" />
<Columns>
<asp:TemplateField HeaderText="Ingrediente" ItemStyle-Font-Size="10">
<ItemTemplate>
<asp:Label ID="lblId" Text='<%# Bind("IngredientId") %>' Visible="false" runat="server"/>
<asp:Label ID="lblPrice" Text='<%# Bind("Price") %>' Visible="false" runat="server"/>
<asp:Label ID="lblDescr" Text='<%# Bind("Description") %>' Visible="false" runat="server"/>
<asp:Label ID="lblName" Text='<%# Bind("Name") %>' Visible="false" runat="server"/>
<asp:Label ID="lblPict" Text='<%# Bind("Picture") %>' Visible="false" runat="server"/>
<div style="text-align:left;">
<img id="img" style="float:right;" src='<%# Eval("Picture") %>'
height="75" runat="server" alt="Picture" />
<b>
<%# Eval("Name") %>
</b>
<br />
<br />
Price: <b><%# Eval("Price") %></b>
<br />
<br />
<br />
</div>
<hr />
<div style="text-align:left;">
<b>Description</b>
</div>
<div style="width:300px;">
<%# Eval("Description") %>
</div>
<br />
<asp:LinkButton Enabled="true" runat="server" Text="Add" CommandName="Select" ID="cmdAdd" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
I solved the problem in a tricky way.
I deleted the LinkButton and before TemplateField I put a ButtonField and all is working fine.
Now the code looks like:
<Columns>
<asp:ButtonField Text="Add" CommandName="Select" />
<asp:TemplateField>
......
</asp:TemplateField>
</Columns>
Still I'm not understanding why the control had that behavior.
Don't forget to give the webresource.axd enough rights in the web.config?

Categories

Resources