What property of a Templatefield will make an asp button visible? - asp.net

I have the following code on my aspx page that has an onclick event to produce a popup control but the button is invisible. What can I use in place of ItemTemplate as a property of Templatefield to make the button visible?
<asp:TemplateField HeaderText="Performance Status (adults):">
<ItemTemplate>
<asp:button skinID="tabbutton" CssClass="Clickable" id="btnWhoStatus" runat="server" Text="?" BorderStyle="None" TabIndex="-1" />
<cc1:PopupControlExtender
ID="PopupControlExtender2" runat="server" Position="Top"
TargetControlID="btnWhoStatus" PopupControlID="pnlWhoStatus"
DynamicServicePath="" Enabled="True" ExtenderControlID="">
</cc1:PopupControlExtender>
<asp:Panel runat="server" ID="pnlWhoStatus" BackColor="#FFFFFF" style="width:640px; display:none " >
<controls:WhoStatusPopup id="WhoStatusPopup" runat="server" />
</asp:Panel>
</ItemTemplate>
<ItemTemplate>
<asp:Label skinid="tablabelblack" id="lblPerformanceStatus" runat="server" Text='<%# Eval("PerformanceStatus") %>' />
</ItemTemplate>
</asp:TemplateField>

Related

Gridview Not Triggering Events

I'm trying to use the events on my Gridview control. But its not firing the events when expected. i.e, for OnSelectedIndexChanged, when changing the selected cell/row nothing happens. I've tried with OnSelectedIndexChanged as well as OnRowUpdating. The breakpoint is never hit in gvQ15_RowUpdating. I've even tried using the OnTextChanged event for the child textboxes or the gridview and they are not firing.
Markup
<asp:GridView AutoPostBack="true" ID="gvQ15" runat="server" AllowPaging="false" AutoGenerateColumns="false" >
<Columns>
<asp:TemplateField HeaderText="Prescription Medication Name" ItemStyle-Width="25%">
<ItemTemplate>
<asp:TextBox ID="txtPrescriptionMedicationName" runat="server" Width="100%" OnTextChanged="txtPrescriptionMedicationName_TextChanged" BordewWidth="0" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date Originally Prescribed" ItemStyle-Width="10%">
<ItemTemplate>
<asp:TextBox ID="txtDateOriginallyPrescribed" runat="server" Style="min-width: 110px; width: 100%;" BorderWidth="0" OnTextChanged="txtDateOriginallyPrescribed_TextChanged" />
<asp:MaskedEditExtender ID="meetxtDateOriginallyPrescribed" runat="server" MaskType="date" UserDateFormat="MonthDayYear" Mask="99/99/9999" TargetControlID="txtDateOriginallyPrescribed" ClearMaskOnLostFocus="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Frequency and Dosage" ItemStyle-Width="25%">
<ItemTemplate>
<asp:TextBox ID="txtFrequencyAndDosage" runat="server" Width="100%" BorderWidth="0" OnTextChanged="txtFrequencyAndDosage_TextChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Condition" ItemStyle-Width="25%">
<ItemTemplate>
<asp:TextBox ID="txtCondition" runat="server" Width="100%" BorderWidth="0" OnTextChanged="txtCondition_TextChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Onset Date" ItemStyle-Width="10%">
<ItemTemplate>
<asp:TextBox ID="txtConditionOnsetDate" runat="server" style="min-width:110px;width:100%" BorderWidth="0" OnTextChanged="txtConditionOnsetDate_TextChanged" />
<asp:MaskedEditExtender ID="meeConditionOnsetDate" runat="server" MaskType="date" UserDateFormat="MonthDayYear" Mask="99/99/9999" TargetControlID="txtConditionOnsetDate" ClearMaskOnLostFocus="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Code Behind
Protected Sub gvQ15_RowUpdating(sender As Object, e As GridViewUpdateEventArgs)
Session("Prescriptions") = gvQ15.DataSource
End Sub
Add the CausesValidation="False" attribute to your CommandField.
<asp:commandfield ShowEditButton="True" CausesValidation="False" HeaderText="Edit"/>
Or,
Add the EnableViewState="True" attribute to your GridView.
For TemplateField use this:
<asp:TemplateField HeaderText="Command">
<ItemTemplate>
<asp:Button CommandName="Edit" Text="Edit" ID="btnEdit" Runat="server"></asp:Button>
<asp:Button CommandName="Delete" Text="Delete" ID="btnDel" Runat="server"></asp:Button>
</ItemTemplate>
<EditItemTemplate>
<asp:Button CommandName="Update" Text="Update" ID="btnUpdate" Runat="server"></asp:Button>
<asp:Button CommandName="Cancel" Text="Delete" ID="btnCancel" Runat="server"></asp:Button>
</EditItemTemplate>
</asp:TemplateField>

ajaxToolKit:CalendarExtender not working on row 2 of gridview

My page has two approaches to adding a date to a text box inside the gridview. The user can set a date for all the rows by choosing a date and clicking a button. The code behind updates each row. This is working fine. Now I want to add the calendar to each row.
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajaxToolkit" %>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
This is outside the gridview and working fine.
<asp:TextBox ID="SetDateTextBox" runat="server"></asp:TextBox>
<ajaxToolkit:PopupControlExtender ID="SetDateTextBox_PopupControlExtender" runat="server" BehaviorID="SetDateTextBox_PopupControlExtender"
DynamicServicePath="" ExtenderControlID="" TargetControlID="SetDateTextBox" PopupControlID="Panel1" Position="Bottom">
</ajaxToolkit:PopupControlExtender>
<asp:Panel ID="Panel1" runat="server" Width="200px">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="Black" BorderStyle="Solid" CellSpacing="1" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth" Width="330px">
<DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" Height="8pt" />
<DayStyle BackColor="#CCCCCC" />
<NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#333399" ForeColor="White" />
<TitleStyle BackColor="#333399" BorderStyle="Solid" Font-Bold="True" Font-Size="12pt" ForeColor="White" Height="12pt" />
<TodayDayStyle BackColor="#999999" ForeColor="White" />
</asp:Calendar>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
Now the problem. I added the calendarExtender to each row inside the templatefield.
<asp:TemplateField HeaderText="FINISH DATE" SortExpression="SCHED_FINISH_DATE">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("SCHED_FINISH_DATE", "{0:d}") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="FinishDateTextBox" runat="server" Text='<%# Bind("SCHED_FINISH_DATE", "{0:d}") %>' ClientIDMode="AutoID"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="FinishDateTextBox_CalendarExtender" runat="server" BehaviorID="FinishDateTextBox_CalendarExtender"
TargetControlID="FinishDateTextBox"/>
</ItemTemplate>
</asp:TemplateField>
I set the textbox ClientIDMode to AutoID. The page loads without error. I click the textbox on row 1 and the calendar works great. Click row 2 and beyond and the calendar does not appear.
I removed the popupcontrolextender along with the asp:panel and asp:UpdatePanel and replaced with the following code. This calendar will set a global change to all rows. So much cleaner.
<asp:TextBox ID="SetDateTextBox" runat="server"></asp:TextBox>
<ajaxtoolkit:calendarextender ID="CalendarEntender2" runat="server" TargetControlID="SetDateTextBox" />
Then inside the gridview.
<asp:TemplateField HeaderText="FINISH DATE" SortExpression="SCHED_FINISH_DATE" ItemStyle-Width="100">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("SCHED_FINISH_DATE", "{0:d}") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="FinishDateTextBox" ClientIDMode="AutoID" runat="server" Text='<%# Bind("SCHED_FINISH_DATE", "{0:d}") %>'></asp:TextBox>
<ajaxtoolkit:calendarextender ID="CalendarEntender1" runat="server" TargetControlID="FinishDateTextBox" />
</ItemTemplate>
<ItemStyle Width="100px"></ItemStyle>
</asp:TemplateField>
I still don't understand why the popupextender was causing an issue.

focus a div on link button click

In my page, I have a gridview with link buttons in a column.
By clicking the link button should show a div below the gridview.
I gave href in onClientClick event of the link button as follows.
function showDiv() {
location.href = '#div1';
}
When I click the link button the div is showing, but after the page load the page goes up.
aspx code
<asp:GridView ID="gridDate" runat="server" CssClass="gridview_Order"
HeaderStyle-BackColor="#09182F" HeaderStyle-ForeColor="#ffffff"
AutoGenerateColumns="false" Visible="False">
<Columns>
<asp:TemplateField ItemStyle-Width="20%" HeaderText="Sl No." ItemStyle-CssClass="paddng">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="25%" HeaderText="DATE" ItemStyle-CssClass="paddng">
<ItemTemplate>
<asp:LinkButton ID="lbtnDate" runat="server" CommandArgument='<%#Eval("tblName") %>' Text='<%# Eval("dtvar") %>' OnClientClick="showDiv()" OnCommand="lbtnDate_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="25%" HeaderText="" ItemStyle-CssClass="paddng">
<ItemTemplate>
<asp:LinkButton ID="lbtnDownload" runat="server" Text="Download Excel" CommandArgument='<%# Eval("tblName") %>' OnCommand="lbtnDownload_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br /><hr /><br />
<div id="div1">
<asp:GridView ID="gridOrderByUser" runat="server" CssClass="gridview"
HeaderStyle-BackColor="#09182F" HeaderStyle-ForeColor="#ffffff"
AutoGenerateColumns="false" Visible="False" >
<Columns>
<asp:TemplateField ItemStyle-Width="2%" HeaderText="Sl No.">
<ItemTemplate>
<asp:Label ID="lblSlNo1" runat="server" Text='<%#Container.DataItemIndex+1 %>' style="color:#000;"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="cod" HeaderText="CODE" InsertVisible="False" ReadOnly="True" SortExpression="cod" ItemStyle-Width="16%" />
<asp:TemplateField HeaderText="IMAGE" ItemStyle-Width="18%">
<ItemTemplate>
<asp:Image ID="img1" runat="server" Height="100px" Width="54px" ImageUrl='<%#"~/images/"+Eval("Image") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
So what should I do for staying the page in the div position.
Thanks
If you dont need the server side event of the link button you could do this:
OnClientClick="location.href = '#div1'; return false;"

How do i get asp:Panel Default Button to fire button click event?

I have three asp net text boxes that will contain search criteria for searching a table. I would like the search to work like Google. When the enter key is pressed to have the click event on the "Enter" button fire. The click event never fires. What can I do to get it to fire?
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebCategoryGenerateEdit.ascx.cs"
Inherits="EPPA.Controls.WebCategoryGenerateEdit" ClientIDMode="Static" %>
<script src="/Scripts/jquery-1.8.3.js" type="text/javascript"></script>
<script type="text/javascript">
// debugger;
function pageLoad() {
var gvCategoryMessage = $("#<%=GVCategoryMessage.ClientID %>").html
if (gvCategoryMessage.length != 0) {
$("#<%=GVParentCategoryLinkTitle.ClientID %>").keydown(function () {
$("#<%=GVCategoryMessage.ClientID %>").html("");
})
$("#<%=GVCategoryLinkTitle.ClientID %>").keydown(function () {
$("#<%=GVCategoryMessage.ClientID %>").html("");
})
}
}
</script>
<asp:ScriptManager runat="server" />
<asp:MultiView ID="Multiview1" runat="server" ActiveViewIndex="0">
<asp:View ID="SearchView" runat="server">
<asp:Table ID="TableSV1" runat="server">
<asp:TableRow ID="TableRowSV1" runat="server">
<asp:TableCell ID="TableCellSV1" runat="server">
<asp:Label ID="LabelSV1" runat="server" SkinID="SearchTextLabel"
Text="CB or CJ" CssClass="searchTextLabel_Division"/>
</asp:TableCell>
<asp:TableCell ID="TableCellSV2" runat="server">
<asp:Label ID="LabelSV2" runat="server"
SkinID="SearchTextLabel" Text="Parent Category Link Title"
CssClass="searchTextLabel_ParentCategoryLink" />
</asp:TableCell>
<asp:TableCell ID="TableCellSV3" runat="server">
<asp:Label ID="LabelSV3" runat="server"
SkinID="SearchTextLabel"
Text="Category Link Title" CssClass="searchTextLabel_CategoryLink" />
</asp:TableCell>
<asp:TableCell ID="TableCellSV4" runat="server">
<asp:Label ID="Label1" runat="server"
SkinID="SearchTextLabel"
Text="Category ID" CssClass="searchTextLabel_CategoryID" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="SVTableRowSV2" runat="server">
<asp:TableCell ID="TableCellSV5" runat="server">
<asp:DropDownList ID="SVDivisionDDL" runat="server"
OnSelectedIndexChanged="SVDivisionDDL_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem Value="CB">CB</asp:ListItem>
<asp:ListItem Value="CJ">CJ</asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
<asp:TableCell ID="TableCellSV6" runat="server" >
<asp:panel ID="SVPCLTContainer" runat="server"
DefaultButton="SV6EnterButton">
<asp:TextBox ID="SVParentCategoryLinkTitle" runat="server"
SkinID="SearchTextBox"
CssClass="searchTextBox_ParentCategoryLink" />
<asp:Button ID="SV6EnterButton" runat="server" Visible="false"
Text="Enter" OnClick="EnterKeyPressed_Click" />
</asp:panel>
</asp:TableCell>
<asp:TableCell ID="TableCellSV7" runat="server" >
<asp:TextBox ID="SVCategoryLinkTitle"
runat="server" SkinID="SearchTextBox"
CssClass="searchTextBox_CategoryLink" />
</asp:TableCell>
<asp:TableCell ID="TableCellSV8" runat="server" >
<asp:TextBox ID="SVCategoryID" runat="server"
SkinID="SearchTextBox"
CssClass="searchTextBox_CategoryID" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:Button ID="SVGenNewButton" runat="server" Text="Generate New Category ID"
OnClick="SVGenerateNewButton_Click" />
<asp:Button ID="SVDeleteButton" runat="server" Text="Delete Checked items"
OnClick="SVDeleteButton_Click" />
<div style="width:618px; overflow-x:no-display; overflow-y:auto; max-height:392px;
padding-top:2px; ">
<asp:GridView ID="gvWebCategoryID" runat="server" AutoGenerateColumns="False"
SkinID="gridViewSkin" OnRowDeleting="gvWebCategoryID_RowDeleting" >
<Columns>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:Button ID="SVgridViewEditButton" runat="server"
OnClick="gvWeCategoryIDEditButton_Click" Text="Edit" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:CheckBox ID="Checkbox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Division" HeaderText="CB or CJ"
Visible="true" />
<asp:BoundField DataField="ParentCategoryLinkTitle" HeaderText="Parent
Category Link Title" />
<asp:BoundField DataField="CategoryLinkTitle" HeaderText="Category
Link Title" />
<asp:BoundField DataField="CategoryID" HeaderText="Category ID" />
<asp:TemplateField HeaderText="Error Message" Visible="false" >
<ItemTemplate>
<asp:Label ID="ErrorMessage" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</asp:View>
</asp:MultiView>
and here is the behind code method:
protected void EnterKeyPressed_Click(object sender, EventArgs e)
{
ReloadData();
this.Multiview1.ActiveViewIndex = 0;
}
At a quick glance, have you tried removing the return false here:
$("#<%=SVParentCategoryLinkTitle.ClientID %>").keydown(function (e) {
if (e.which == 13) {
__doPostBack("#<%=EnterKeyPressed.UniqueID %>", "");
return false;
}
})
check out this question and answer, if it helps: Default button not working in asp.net panel
the DefaultButton is used to capture the Enter key press if the focus is already inside the panel, for example you must have moved the focus to an input field like the text boxes inside the panel. if the focus is not there it won't work.

How to use a buttonfield in a gridview

I am using this gridview:
<asp:GridView ID="gvMessages" runat="server" AutoGenerateColumns = "false"
CaptionAlign="NotSet" CellPadding="5" onrowcommand="gvMessages_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Avändare">
<ItemTemplate>
<%# GetSender((int)Eval("Sender"))%>
<br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ämne">
<ItemTemplate>
<%# Eval("Head")%>
<br />
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField Text="Öppna" CommandName="Open" />
</Columns>
</asp:GridView>
I want a textbox to show the message member of the bound object (Eval("Message")) of the row that has been clicked.
from the comments, and I would suggest to have the show/hide in the client, so you can save a round trip to the server
<asp:GridView ID="gvMessages" runat="server" AutoGenerateColumns = "false"
CaptionAlign="NotSet" CellPadding="5">
<Columns>
<asp:TemplateField HeaderText="Avändare">
<ItemTemplate>
<%# GetSender((int)Eval("Sender"))%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Ämne" DataField="Head" />
<asp:TemplateField HeaderText="Avändare">
<ItemTemplate>
<button class="btn-showmsg">Öppna</button>
<div class="message hide">
<asp:TextBox runat="server"
TextMode="MultiLine" Text="<%= Eval("Message") %>" />
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and in javascript
$(function() {
$(".btn-showmsg").click(function() {
var tr = $(this).closest("tr"), // the <tr>
msg = tr.find(".message"); // the div wraping the message
msg.show(); // show it
});
});
Now, the position and the placement of the message, it's all up to you, but I would suggest something like Bootstrap Modal to show it.
also, remember to add a style of .hide { display: none; }

Resources