RegularExpressionValidator won't let me get to the next page - asp.net

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?

Related

Validate CheckBox inside listview in asp.net not working if listview have more than one record

I want to validate at least one checkbox select when edit the listview
when the list view have more than one record the validation is not working but its work if the listview have one record.
I think my code not detect the edited record, when its more than one.
what is the problem with this code can some one help with it?
Protected Sub UpdateButton_Click(sender As Object, e As EventArgs)
'get data from chekced checkbox
Dim ChkValue As New List(Of String)()
For Each item As ListViewItem In ListView1.Items
Dim ck1 As CheckBox = DirectCast(item.FindControl("CheckBox1"), CheckBox)
Dim ck2 As CheckBox = DirectCast(item.FindControl("CheckBox2"), CheckBox)
Dim ck3 As CheckBox = DirectCast(item.FindControl("CheckBox3"), CheckBox)
Dim vl As RequiredFieldValidator = DirectCast(item.FindControl("RequiredFieldValidator1"), RequiredFieldValidator)
If ck1.Checked Or ck2.Checked Or ck3.Checked Then
vl.Enabled = False
sdstt.Update()
Else
vl.Enabled = True
End If
Next
End Sub
<asp:ListView ID="ListView1" runat="server" DataSourceID="sdstt" DataKeyNames="ID" >
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" CausesValidation="true" ValidationGroup="vgrpSaveContact" CommandName="Update" OnClick="UpdateButton_Click" runat="server" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
<asp:RequiredFieldValidator Font-Size="6pt" ID="RequiredFieldValidator3" runat="server" ControlToValidate="nameTextBox"
ErrorMessage="first name" SetFocusOnError="true" ValidationGroup="vgrpSaveContact"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revOnlyAlphabetical" runat="server" Font-Size="6pt" ValidationGroup="vgrpSaveContact"
ValidationExpression="^([^0-9]+)$" ControlToValidate="nameTextBox"
ErrorMessage="Invalid Name" Font-Bold="true" ForeColor="Red"></asp:RegularExpressionValidator>
</td>
<td>
<asp:TextBox ID="ageTextBox" runat="server" Text='<%# Bind("age") %>' />
</td>
<td>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("chk1") %>' />
</td>
<td>
<asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("chk2") %>' />
</td>
<td>
<asp:CheckBox ID="chkCheckBox3" runat="server" Checked='<%# Bind("chk3") %>' />
<asp:TextBox ID="txtchk" runat="server" Visible="false" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ValidationGroup="vgrpSaveContact" Enabled="false" runat="server"
ControlToValidate="txtchk" ErrorMessage="RequiredFieldValidator">
</asp:RequiredFieldValidator>
</td>
</tr>
</EditItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
</td>
<td>
<asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' />
</td>
<td>
<asp:Label ID="ageLabel" runat="server" Text='<%# Eval("age") %>' />
</td>
<td>
<asp:CheckBox ID="chkCheckBox" runat="server" Checked='<%# Eval("chk") %>' Enabled="false" />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server"></th>
<th runat="server">ID</th>
<th runat="server">name</th>
<th runat="server">age</th>
<th runat="server">chk</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>

How to disable edit button for a row in listview

Here is my html code
<ItemTemplate>
<td>
<asp:Label ID="LabelID" runat="server" Text='<%# Eval("sysID")%>'></asp:Label>
</td>
<td>
<asp:Label ID="Labelpar" runat="server" Text='<%# Eval("parameters")%>'></asp:Label>
</td>
<td>
<asp:Label ID="LabelValue" runat="server" Text='<%# Eval("value")%>'></asp:Label>
</td>
<td>
<asp:Button ID="btnEdit" runat="server" Text='Edit' CommandName="Edit" />
</td>
</ItemTemplate>
I have 3 rows (a,b,c) in my column. How can I disable "Edit" button for row a?
by "disable" I mean user should not be able to click
Not sure but definitely something like this
<asp:Button ID="btnEdit" runat="server" Text='Edit' Enabled='<%# (Eval("sysID")=="a")?False:True %>' CommandName="Edit" />

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

Get row/column of 3 deep nested Listivew on textbox OnTextChanged

I am attempting to get the row and column location of a text boxes OntextChanged.
I can get the column location if I do this:
TextBox txtScore = sender;
ListViewItem item = (ListViewItem)txtScore.NamingContainer;
int col = ((ListView)item.NamingContainer).DataKeys(item.DataItemIndex).Values(0);
which works until I convert the snippet below to a user control.
Code Snippet
<asp:ListView ID="techs" runat="server" ItemPlaceholderID="lvItemPlaceholder" DataKeyNames="Number"
OnItemDataBound="techs_ItemDataBound">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="lvItemPlaceholder" />
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
Tech
<%# Eval("Number")%>
</td>
<td>
<asp:TextBox ID="tech" runat="server" Text='<%# Eval("Name") %>' />
</td>
<asp:ListView ID="scorePatterns" runat="server" ItemPlaceholderID="lvScorePatternsItemPlaceholder"
OnItemDataBound="scorePatterns_ItemDataBound" DataKeyNames="Ref">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="lvScorePatternsItemPlaceholder" />
</LayoutTemplate>
<ItemTemplate>
<td>
<table>
<asp:ListView ID="scores" runat="server" ItemPlaceholderID="lvScoresItemPlaceholder"
OnItemDataBound="scores_ItemDataBound" DataKeyNames="Ref,Instance">
<LayoutTemplate>
<asp:PlaceHolder runat="server" ID="lvScoresItemPlaceholder" />
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:TextBox runat="server" ID="txtScore" Width="50" AutoPostBack="true" OnTextChanged="txtScore_TextChanged" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</table>
</td>
</ItemTemplate>
</asp:ListView>
<td>
<asp:Label runat="server" ID="lblDate" Text='<%# Eval("Date") %>' />
</td>
</tr>
</ItemTemplate>

Modal Popup Error

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

Resources