Modal Popup Error - asp.net

I have a DataList that has a link button and I want this link button envoke a modal popup. I've copied the mpe code from another application where it works in a gridview. The error is thrown as soon as page is openned and each time the link button is clicked. The error is thrown in the ScriptResource file: "Microsoft JScript runtime error: Sys.ArgumentNullException: Value cannot be null.
Parameter name: elements". I understand something has null value but not sure what. Page has over a thousand lines so I'll just paste the part I'm working on.
<ItemTemplate>
<tr class="AssetMngnt-trHeaderRow_bgColor">
<td valign="top">
<asp:Label ID="lblIdent" runat="server" Text='<%# Eval("Printer_Ident") %>' Visible="false"></asp:Label>
</td>
<td>
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="False" CommandName="Select" Text="Edit" />
</td>
<td valign="top" nowrap>
<asp:Label ID="lblName" Text='<%# Eval("Network_Name") %>' runat="server" />
</td>
<td valign="top">
<asp:LinkButton ID="lbPrinterModel"
runat="server" CausesValidation="False" CommandName="Select" CommandArgument="ShowAsset"
Text='<%# Eval("Printer_Mfg") + " " + (string)Eval("Printer_Model") %>' />
</td>
<td valign="top">
<asp:Label ID="lblLocation" Text='<%# Eval("Location") %>' runat="server" />
</td>
<td>
<asp:LinkButton ID="LinkButton1"
runat="server" CausesValidation="False" CommandName="Select" CommandArgument="IssueToners"
Text="Issue Toners" />
<asp:Button runat="server" ID="btnShowPopup" style="display:none" />
<ajaxToolkit:ModalPopupExtender runat="server" id="mpeIssueToners"
TargetControlID="btnShowPopup"
PopupControlID="pnlFvIssueTonersModal"
CancelControlID="UpdateCancelButton"
BackgroundCssClass="modalBackground" >
</ajaxToolkit:ModalPopupExtender>
</td>
</tr>
</ItemTemplate>
<asp:Panel runat="server" ID="pnlFvIssueTonersModal" Visible="true" style="display:none">
<asp:Panel runat="server" ID="pnlFvIssueToners" Visible="true">
<div id="AssetMngnt-FloatLeft_alt"">
<!-- ISSUE TONERS FORM VIEW ******************************************************************************** -->
<asp:FormView ID="fvIssueCartridges" runat="server" DataSourceID="ODSIssueCartridges"
OnItemUpdating="fvIssueCartridges_OnItemUpdating" OnItemUpdated="FormView1_Display_Update_Msg"
EnableViewState="False"
EmptyDataRowStyle-CssClass="AssetMngnt-panelRO" >
<EditItemTemplate>
</EditItemTemplate>
</asp:FormView>
<!-- END ISSUE TONERS FORM VIEW **************************************************************************** -->
</div>
</asp:Panel>
<ajaxToolKit:ModalPopupExtender ID="ModalPopupExtender1" BehaviorID="mdlPopup" runat="server"
TargetControlID="div" PopupControlID="div" CancelControlID="btnNo"
OnCancelScript="cancelClick();" BackgroundCssClass="modalBackground" />
<div id="div" runat="server" align="center" class="confirm" style="display:none">
<asp:Label Text="Form is empty - empty records are not allowed."
ForeColor="#000000" runat="server" ID="Label3" /><br />
<asp:Button ID="btnNo" runat="server" Text="Ok" Width="50px" />
</div>
</asp:Panel>
The ModalPopupExtender1 takes care of things inside the FormView.
Thanks,
Risho

Related

ASP.net Listview Hide Edit Button when Session Value equals a variable

I want to hide the edit button in the listview when a session variable is not equal to 2. When session is equal to 2 then I want the edit button to be visible.
My code is below.
<asp:ListView ID="ListView1" runat="server" DataKeyNames="UserStoryID" DataSourceID="ShowProjectsTest">
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Label ID="StoryLabel" runat="server" Text='<%# Eval("Story") %>' />
</td>
<td>
<asp:Label ID="EstimatedTimeLabel" runat="server" Text='<%# Eval("EstimatedTime") %>' />
</td>
<td>
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" Font-Size="Small" />
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" Font-Size="Small" />
</td>
<asp:Label ID="UserStoryIDLabel" runat="server" Text='<%# Eval("UserStoryID") %>' Visible="false" />
<asp:Label ID="ProjectIDLabel" runat="server" Text='<%# Eval("ProjectID") %>' Visible="false" />
<asp:Label ID="SprintIDLabel" runat="server" Text='<%# Eval("SprintID") %>' Visible="false" />
</tr>
</AlternatingItemTemplate>
</asp:ListView>
Add Visible attribute to the edit button and then toggle it in the code behind.
Mark Up:
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" Font-Size="Small" Visible="false" />
Code Behind:
this.EditButton.Visible = (Session["Key"] as int) == 2;

trouble in getting dynamic id`s for datepicker

i want to generate a dynamic id of my datepicker. below jquery function shows the datetimepicker as the id is defined as static.
$(function () {
var dates = $("#ContentPlaceHolder1_gvdLCStatus_txtInvoiceDate_0").datepicker(
{
dateFormat: 'dd/mm/yy',
defaultDate: '+1w',
changeMonth: false,
numberOfMonths: 1,
showOn: 'both',
buttonImage: 'Images/calendar_month.png',
buttonImageOnly: true,
onSelect: function (selectedDate) {
var option = this.id == "ContentPlaceHolder1_gvdLCStatus_txtInvoiceDate_0" ? "minDate" : "maxDate",
instance = $(this).data("datepicker");
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings);
dates.not(this).datepicker("option", option, date);
}
});
});
I want to generate a dynamic ID for the DatePicker. and How that ive tried various time but couldnt find the actual way of doing.Thanks.
<asp:GridView ID="gvdLCStatus" runat="server" DataKeyNames="LCID" AutoGenerateColumns="false"
AllowPaging="True" PageSize="4" EmptyDataText="No Record Found" CssClass="mGrid"
OnPageIndexChanging="gvdLCStatus_PageIndexChanging" OnRowCommand="gvdLCStatus_RowCommand"
OnSelectedIndexChanged="gvdLCStatus_SelectedIndexChanged" OnRowDataBound="gvdLCStatus_RowDataBound"
OnRowCreated="gvdLCStatus_RowCreated">
<AlternatingRowStyle CssClass="test" />
<Columns>
<asp:TemplateField HeaderText="LC Number">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("LCID") %>' Visible="false"></asp:Label>
<a href="#" onclick="linkbtnTest('<%# "#"+Eval("LCNumber") %>')">
<%# Eval("LCNumber") %></a>
<%-- <div id='<%# Eval("ShipmentID") %>' style="display: none;">
</div>--%>
<div id='<%# Eval("LCNumber") %>' style="display: none;">
<asp:GridView ID="gvShipmentStatus" runat="server" AutoGenerateColumns="false" DataKeyNames="ShipmentID"
OnRowCommand="gvShipmentStatus_RowCommand" OnRowDataBound="gvShipmentStatus_RowDataBound"
CssClass="mGrid">
<Columns>
<asp:BoundField DataField="InvoiceNumber" HeaderText="Invoice Number" />
<asp:BoundField DataField="InvoiceDate" HeaderText="Invoice Date" />
<asp:BoundField DataField="BLNumber" HeaderText="B/L Number" />
<asp:BoundField DataField="BLDate" HeaderText="B/L Date" />
<asp:BoundField DataField="VesselName" HeaderText="Vessel Name" />
<asp:BoundField DataField="VoyageNumber" HeaderText="Voyage Number" />
<asp:BoundField DataField="DueDate" HeaderText="Due Date" />
<asp:BoundField DataField="ContractedShipmentSchedule" HeaderText="Shipment Schedule" />
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:ImageButton ID="ImgShipmentDelete" runat="server" ImageUrl='<%# isDelete_img(Session["isAdmin"].ToString()) %>'
Enabled='<%# isDelete(Session["isAdmin"].ToString()) %>' CommandName="DeleteShipmentRecord"
CommandArgument='<%# Eval("ShipmentID") %>' AlternateText="DeleteShipmentRecord"
OnClientClick="return confirm_delete();" Style='<%# delete_style(Session["isAdmin"].ToString()) %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<%-- <asp:ImageButton ID="ImgShipmentEdit" runat="server" ImageUrl="~/Images/edit.png"
CommandName="EditShipmentRecord" ImageAlign="Middle" CommandArgument='<%# Eval("ShipmentID") %>'
AlternateText="EditShipmentRecord" OnClientClick='linkbtnTest(<%# Eval("ShipmentID) %>)' />
--%>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="EditShipmentRecord"
CommandArgument='<%# Eval("ShipmentID")+":"+Eval("LCStatusID")%>'>
<%--<asp:Label ID="Label2" runat="server" Text='<%# Eval("ShipmentID") %>' Visible="true"></asp:Label>--%> <img src="Images/edit.png" alt="Edit" />
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<%--</div>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ContractNumber" HeaderText="Contract Number" />
<asp:BoundField DataField="Amount" HeaderText="Amount" />
<asp:BoundField DataField="Qty" HeaderText="Quantity" />
<asp:TemplateField>
<ItemTemplate>
Add Shipment Status
<div id='<%# Eval("LCID") %>' style="display: none;">
<table>
<tr>
<td class="td_records" style="padding-top: 5px;">
Invoice Number
</td>
<td class="td_records" style="padding-top: 5px;">
Invoice Date (dd/mm/yyyy)
</td>
<td class="td_records" style="padding-top: 5px;">
B/L Number
</td>
<td class="td_records" style="padding-top: 5px;">
B/L Date (dd/mm/yyyy)
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtInvoiceNumber" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtInvoiceDate" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtBLNumber" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtBLDate" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="td_records" style="padding-top: 5px;">
VesselName
</td>
<td class="td_records" style="padding-top: 5px;">
VoyageNumber
</td>
<td class="td_records" style="padding-top: 5px;">
DueDate (dd/mm/yyyy)
</td>
<td class="td_records" style="padding-top: 5px;">
ShipmntSchedule (dd/mm/yyyy)
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtVesselName" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtVoyageNumber" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtDueDate" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtShipmntSchedule" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="padding-top: 10px;">
<asp:Button ID="btnSubmitShipment" runat="server" Text="Submit" CommandName="Select"
OnCommand="btnSubmitShipment_Command" CssClass="btnSubmitCSS" />
<asp:Button ID="btnResetShipmentRecord" runat="server" Text="Reset" CssClass="btnSubmitCSS" />
</td>
</tr>
</table>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgDelete" runat="server" ImageUrl='<%# isDelete_img(Session["isAdmin"].ToString()) %>'
Enabled='<%# isDelete(Session["isAdmin"].ToString()) %>' CommandName="DeleteRecord"
CommandArgument='<%# Eval("LCID") %>' AlternateText="DeleteRecord" OnClientClick="return confirm_delete();"
Style='<%# delete_style(Session["isAdmin"].ToString()) %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgEdit" runat="server" ImageUrl="~/Images/edit.png" CommandName="EditRecord"
CommandArgument='<%# Eval("LCID") %>' AlternateText="EditRecord" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="pgr" />
</asp:GridView>
As an option you may use such selector:
var dates = $("[id*='txtInvoiceDate']", "#<%= gvdLCStatus.ClientID %>")​
But better consider to set CssClass property on textboxes and use class selector
Why do you select by id? Why don't you go with class name? $('.datebox').dateTimepicker(...
i found an alternate of validating it with asp.net required field validators. No other option was there and had to maintain the time constraint.
Thanks Guys.

update gridview field without dataBind

i have a gridview that show comments. i want that if a person likes a comment, press a like button and i increse the sum of likes , but i do not want to connect to database and bind. i want do that using ajax. how can i do that?
here is my code:
<asp:UpdatePanel runat="server" id="UpdatePanel" >
<ContentTemplate>
<asp:GridView ID="grdCommentsForLoginnedUser"
runat="server"
AutoGenerateColumns="False"
Width="100%"
OnRowCommand="grdCommentsForLoginnedUser_RowCommand"
ViewStateMode="Inherit">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:HiddenField ID="hdnCommentID" runat="server"
Value='<%# Bind("CommentID") %>'/>
<table border="2" dir="rtl">
<tr>
<td rowspan="2" style="background-color: #6699FF" width="200px">
<asp:HyperLink ID="lnkCommenterName"
runat="server"
NavigateUrl='<%# Bind("CommenterProfile") %>'
Text='<%# Bind("CommenterName") %>' />
</td>
<td width="700px">
<br />
<asp:Label ID="lblCommentText" runat="server"
Text='<%# Bind("CommentText") %>' />
<br />
</td>
</tr>
<tr>
<td width="700px">
<asp:Label ID="lblPreviousAcceptOrNonAccept" runat="server"
Text='<%# Bind("PersonPreviousAcceptOrNonAccept") %>' />
<asp:LinkButton ID="lnkBtnRemovePreviousAcceptOrNonAccept"
runat="server"
Text='<%# Bind("RemovePersonPreviousAcceptOrNonAccept") %>'
CommandName="RemovePreviousAcceptOrNonAccept"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
<br />
<asp:LinkButton ID="lnkBtnUpRate" runat="server" Text="Like"
Visible='<%# Bind("isLikeAndUnlikeButtonVisible") %>'
CommandName="LikeComment"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
<br />sum of likes
<asp:Label ID="lblCommentLikes" runat="server"
Text='<%# Bind("CommentLikes") %>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Add a client side onClick javascript to each button. When clicked get the parent td tag and then getElementById("lblCommentLikes") to set the .innerText property of the "lblCommentLikes" span.
+(theTD.getElementById("lblCommentLikes").innerText)+=1;
or
+(theTD.getElementById("lblCommentLikes").innerText)-=1;
Tip: If you are using IE then press F12 to inspect the DOM of a running page

ListView with InsertItemTemplate doesnt work

<asp:ListView ID="lvWallPosts" runat="server"
onitemcommand="lvWallPosts_ItemCommand" InsertItemPosition="LastItem">
<LayoutTemplate>
<table cellpadding="2" runat="server" id="tblWallPosts"
style="width:460px">
<tr runat="server" id="itemPlaceholder">
</tr>
</table>
</LayoutTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtMessage" runat="server"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<tr id="Tr2" style="height:72px" runat="server">
<td valign="top" class="EmployeeInfo">
<p>
<div class="wallmark"><asp:Image ID="imgFile" runat="server" CssClass="friendsImage" ImageUrl='<%# "HttpImageHandler.jpg?username=" + DataBinder.Eval(Container.DataItem,"ByUsername").ToString() %>' />
<asp:Label ID="lblFrom" runat="server" Text='<%#Eval("ByUsername") %>' Font-Size="0.9em" Font-Underline="false" /><br />
<asp:Label ID="lblMessage" runat="server" Text='<%#Eval("Message") %>' Font-Size="0.9em" Font-Underline="false"/></div>
<asp:LinkButton CssClass="shareText" runat="server" ID="lblComment" CommandArgument='<%# Eval("Id") %>' CommandName="Insert" Font-Size="0.9em" Font-Underline="false">Comment</asp:LinkButton>
<asp:LinkButton CssClass="shareText" runat="server" ID="lbShare" CommandArgument='<%# Eval("Id") %>' CommandName="Share" Font-Size="0.9em" Font-Underline="false">Share</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
I cant see the txtMessage control when I click on linkbutton comment.
try setting the linkbutton's commandname to "InitInsert" instead of "Insert"

RegularExpressionValidator won't let me get to the next page

I have two datalists. One works like a menu where you click on a link to fill the othe datalist.
I also have added a next and previous linkbutton to move between the different "pages" so that you do not have to change using the menu datalist.
Now in code behind depending on which values I get from the database I add a RegularExpressionValidator.
This works great until I want to use the next button (or previous for that matter). Even if all the controls that are checked are valid when compared with the RegularExpressionValidator I never get to load the new values.
The next and previous buttons fires the datalist selected index change event and then I check if it is the previous or next button that was clicked.
But the previous and next buttons are numb. They don't even fire the event.
It is like clicking on the background. Nothing happens.
I have chcked the PageIs.Valid and it is true.
Does anyone have a clue what it could be that is causing this behavior?
Thanks in advance!
Some of the texts down there is in Swedish but it shouldn't matter for the code.
rev_checkfieldvalue.ControlToValidate = "tb_detailValue";
switch (iDataTypeId)
{
case 2:
rev_checkfieldvalue.ValidationExpression = #"^\d*[0-9 ]+$";
rev_checkfieldvalue.Text = "Fältet får endast innehålla siffror och mellanslag.";
break;
case 3:
break;
case 4:
break;
case 5:
rev_checkfieldvalue.ValidationExpression = #"\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*";
rev_checkfieldvalue.Text = "Fältet får endast innehålla en e-postadress.";
break;
}
e.Item.Controls.AddAt(32, rev_checkfieldvalue);
<asp:DataList ID="dl_componentInfo" DataKeyField="ComponentId" runat="server" OnItemDataBound="dl_componentInfo_OnItemDataBound" OnItemCommand="dl_componentInfo_OnItemCommand">
<ItemTemplate>
<table>
<tr>
<td colspan="2"><asp:Label ID="lb_componentName" SkinID="lblHeader" runat="server" Text='<%# Eval("ComponentName") %>' /></td>
</tr>
<tr>
<td colspan="2">Fält markerade med * är obligatoriska</td>
</tr>
<tr>
<td> </td>
<td>
<asp:DataList ID="dl_details" OnItemDataBound="dl_details_OnItemDataBound" runat="server">
<ItemTemplate>
<table>
<tr>
<td colspan="2">
<asp:Label ID="lbl_detailName" Text='<%# Eval("DetailName") %>' runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl_custDetName" runat="server" />
</td>
<td align="left">
<%--Always hidden values--%>
<asp:Label ID="lbl_detailTypeId" Visible="false" Text='<%# Eval("DetailTypeId") %>' runat="server" />
<asp:Label ID="lbl_detailId" Visible="false" Text='<%# Eval("DetailId") %>' runat="server" />
<asp:Label ID="lbl_dataTypeId" Visible="false" Text='<%# Eval("DataTypeId") %>' runat="server" />
<asp:Label ID="lbl_customerEventValueId" Visible="false" Text='<%# Eval("CustomerEventValueId") %>' runat="server" />
<asp:Label ID="lbl_reqFld" Visible="false" Text='<%# Eval("ReqFld") %>' runat="server" />
<%--Sometimes visible values--%>
<asp:Label ID="lbt_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:Label ID="lbtb_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:Label ID="lbth_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:Label ID="lbc_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:DropDownList ID="dd_detailValue" Visible="false" runat="server"></asp:DropDownList>
<%--Om det ska gå att markera/avmarkera alla så använd AJAX--%>
<asp:CheckBoxList ID="cbl_detailValue" RepeatDirection="Horizontal" RepeatLayout="flow" Visible="false" runat="server" />
<asp:CheckBox ID="cb_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:TextBox ID="tb_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server" />
<asp:TextBox ID="ta_detailValue" Visible="false" Text='<%# Eval("PresetDetailValue") %>' runat="server"></asp:TextBox>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table>
</ItemTemplate>
<FooterTemplate>
<table width="600">
<tr>
<td>
<asp:LinkButton id="lb_previous" Text="Föregående" CommandName="Previous" runat="server"/>
</td>
<td>
<asp:LinkButton id="lb_next" Text="Nästa" CommandName="Next" runat="server"/>
</td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>
I thought I solved the issue but it just stopped checking.
So for case two you accept any non-empty string of digits and spaces.
Is that your intent?

Resources