What is causing text box with a MaskedEditExtender to duplicate characters? - asp.net

I have a text box with a MaskedEditExtender. When I type in text, the output I get is jumbled with some numbers duplicated and others missing. If I remove the MaskedEditExtender, the textbox performs normally, but, of course, doesn't allow me to use an input mask for the text box. I've tried various combination of options for the MaskedEditExtender, but nothing short of removing the MaskedEditExtender fixes the problem. What could be causing this? Is there some option I can add or remove to fix this?
Here's an example: One of the fields I have is a phone field with the mask (999) 999-9999. When the form is displayed, before anything is entered, it looks like this:
(___) ___-____
This is the desired behavior. However, when I enter a number, say 1234567890 it displays as this:
112_)233455660987_-____
The 1, 2, 3, 5, and 6 are duplicated and 7, 8, 9, 0 appear in reverse order. Not to mention the mask seems to be ignored.
Please let me know if you need anymore information. I would really like to learn what the problem is and how to fix it. I can't do that if my question is summarily downgraded. Thank you!
Adding the full code:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="CtlCheckOutAddressConfirm.ascx.cs" Inherits="App_Controls_CtlCheckOutAddressConfirm" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<script language="javascript" type="text/javascript">
function checkClearZip()
{
var bx = document.getElementById('<%=TxtZip.ClientID %>').value
if (bx == "_____")
{
document.getElementById('<%=TxtZip.ClientID %>').value = "";
}
}
function checkClearPhone()
{
var bx = document.getElementById('<%=TxtPhone.ClientID %>').value
if (bx == "(___) ___-____")
{
document.getElementById('<%=TxtPhone.ClientID %>').value = "";
}
}
script>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="updCart" UpdateMode="Always">
<ContentTemplate>
<div>
<table>
<tr><td align="right">
<font style=" font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height:20px; color: #575a61;">*Phone</font>
</td><td align="left">
<asp:TextBox ID="TxtPhone" MaxLength="15" onblur="checkClearPhone();" runat="server" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Height="28px" Width="300px" Font-Size="X-Large"></asp:TextBox><br />
<ajaxToolkit:MaskedEditExtender ID="MskPhone" runat="server"
TargetControlID="TxtPhone"
Mask="(999) 999-9999"
MessageValidatorTip="true"
OnFocusCssClass="MaskedEditFocus"
OnInvalidCssClass="MaskedEditError"
MaskType="None"
DisplayMoney="None"
AcceptNegative="None"
ClearMaskOnLostFocus="false" />
</td></tr>
<tr><td align="right">
<font style=" font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height:20px; color: #575a61;">*E-mail</font>
</td><td align="left">
<asp:TextBox ID="TxtEmail" MaxLength="50" runat="server" BorderColor="#CCCCCC" BorderStyle="Solid" BorderWidth="1px" Height="28px" Width="300px" Font-Size="X-Large"></asp:TextBox><br />
</td></tr>
</table>
<div class="spacer"></div>
<center><asp:ImageButton runat="server" ID="BtnContinue" ImageUrl="~/images/Buttons/bebtn-save.gif" OnClick="BtnContinue_Click" /></center>
<asp:HiddenField ID="HdnMerch" runat="server" />
<asp:HiddenField ID="HdnAdd" runat="server" />
</div> </ContentTemplate>
</asp:UpdatePanel>

I've experienced this issue myself.
Replication:
Add two MaskedEditExtenders pointed to a single textbox.
Launch your browser and enter data in the textbox. Each character will be doubled/duplicated.
Solution (at least for me):
It appears your ASPX file is clean - no duplicates that I can see. Try the following items:
Look in the CodeBehind for a dynamically-built MaskedEditExtender whose TargetControlID is pointed to the textbox in question.
Note: this could be done directly in the MasterPage, the same page's CodeBehind, or one of these pages calling an obscurely-defined function in another area that performs this function (as was the case with my issue).
Happy coding!

This is one year later, but well, for the ones that can benefit.
A reason can be a partial post-back of the page. Be aware of the ScriptManager you are using. Try to isolate the code and see if it happen.

Related

ASP.NET Repeater FindControl not working for Label, but works for Textbox

I'm facing issues trying to get controls from my repeater. I have one label and one textbox. The label is giving me a null reference error, however the textbox is working.
Markup:
<asp:Repeater ID="PalletsRepeater" runat="server" OnItemDataBound="PalletsRepeater_ItemDataBound">
<ItemTemplate>
<div style="margin-left: 20px; margin-top: 5px;">
<asp:Label lbl="lblPalletId" Text='<%#"Pallet "+Eval("PALLETID")%>' runat="server" />
<asp:Label Text=", Qty = " CssClass="field-label-blue" runat="server" />
<asp:TextBox ID="txtPalletItemQty" runat="server" Text='<%# Eval("ITEMQTY") %>' step="1" type="number" />
</div>
</ItemTemplate>
</asp:Repeater>
Code Behind:
foreach (RepeaterItem repeaterRow in PalletsRepeater.Items)
{
// This fails.
string palletId = ((System.Web.UI.WebControls.Label)repeaterRow.FindControl("lblPalletId")).Text;
// This works.
string palletItemQty = ((System.Web.UI.WebControls.TextBox)repeaterRow.FindControl("txtPalletItemQty")).Text;
}
I have researched this on Stack Overflow and most answers involve using the OnItemDatabound event, but when I tried to implement those answers, it still comes back null for the label. Personally I don't understand the suggestions as far as using the OnItemDatabound event.
Change
<asp:Label lbl="lblPalletId" Text='<%#"Pallet "+Eval("PALLETID")%>' runat="server" />
Into
<asp:Label id="lblPalletId" Text='<%#"Pallet "+Eval("PALLETID")%>' runat="server" />
You cannot find it because it has no ID

How to do a count on table's <tr> and make some andother background-color in vb.net

In ASP.net I'm having this in the frontend, and in the backend(vb) I want to do a count on all <tr>'s on this page and every other (so the 2nd, 4th, 6th,...) has to have another background color.
How do I count all <tr>'s on a page and how can tell them to give every other one another background-color?
This is the frontend:
<p class="title"><asp:Label ID="Label1" runat="server" Text="Title 1"></asp:Label></p>
<table class="table">
<tr><td>Person 1</td><td>Bestuurder</td></tr>
<tr><td>Person 2</td><td>Zaakvoerder</td></tr>
</table>
<p class="title"><asp:Label ID="Label3" runat="server" Text="Title 2"></asp:Label></p>
<asp:Button ID="btn_add_beheerder" runat="server" Text="BEHEERDER TOEVOEGEN" class="btn_add"/>
<table class="table">
<tr><td>Person 3</td><td>Beheerder</td></tr>
<tr><td>Person 4</td><td>Beheerder</td></tr>
</table>
The backend is just going to be on a page_load.
I think the best way to do this is putting every <tr> in an array and then every array[i] that's dividable by 2 give another background-color?
Is this the best way to work?
you could of course do this in a gazillion different ways.
Here just one suggestion.
<asp:GridView id="gv" runat="server" DataSourceID="ds">
<Columns>
<asp:BoundField DataField="Person" />
<asp:BoundField DataField="Something else"/>
</Columns>
<AlternatingRowStyle BackColor="Blue" />
</asp:GridView>
<asp:SqlDataSource runat="server" ID="ds"
ConnectionString="your connectionString"
SelectCommand="--select stuff">
</asp:SqlDataSource>
note the "AlternatingRowStyle"
Modifying your css class should be enough
.table tr:nth-child(odd) {
background: silver;
}
if you are working with dynamically generated table then add the css class attribute
HtmlTable myTable = new HtmlTable();
// initialization
myTable.Attributes.Add("Class", "table");

Using FindControl to target a Literal

I have a ListView called "orderReceiptTable" which I am able to properly access from the Code Behind. Within it is a literal called "orgName" which I obviously would like to populate with an organization's name.
After much searching it was determined that FindControl was the right course of action. Perhaps I am using FindControl improperly but I am unable to actually have it "find" my Literal control.
The code block is being called in the Page Load.
My code looks as such:
Dim orgNameString As String = getOrganizationName.getOrgName(organizationID).ToString()
Dim myOrgName As Literal = FindControl("orgName")
myOrgName = CType(orderReceiptTable.FindControl("orgName"), Literal)
If Not (myOrgName Is Nothing) Then
Response.Write("I found the control!")
myOrgName.Text = orgNameString
End If
Here is the mark-up in the .aspx file:
<asp:ListView ID="orderReceiptTable" runat="server">
<LayoutTemplate>
<div runat="server" id="itemPlaceholder" />
</LayoutTemplate>
<EmptyDataTemplate>
<tr id="noDataDiv" runat="server">
<td class="sub" ID="itemPlaceholder" runat="server">
No order data was returned.
</td>
</tr>
</EmptyDataTemplate>
<ItemTemplate>
<div id="itemPlaceholder" runat="server" style="border:solid 1px #000000; width:250px; float:left; padding:10px; border:solid 2px #1664B1;">
<div>Organization Name: <asp:Literal runat="server" ID="orgName"></asp:Literal></div>
</div>
</ItemTemplate>
</asp:ListView>
The controls inside the template will only be created after binding some data to it. You will then be able to access it via the ListView.Controls property.
This previous answer might help: Find control in ListView EmptyDataTemplate

Radiobutton Text alignment Issue

I am working in asp.net and have radiobutton list and I want to align their text as I require.
Here is what I have currently:
I want to make them like this:
EDIT:
Secondly, when I click Ages From radiobutton, I display a div against this like:
and when I click back to All Ages radio button, I want to hide that div. But SelectedIndexChanged doesn't work second time and onwards. It only works first time.
Code of aspx:
<table>
<tr>
<td>
<asp:RadioButtonList ID="rdoAge" runat="server" RepeatDirection="Horizontal"
onselectedindexchanged="rdoAge_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem Text="All Ages" Value="All Ages" Selected="True"></asp:ListItem>
<asp:ListItem Text="Ages From" Value="Ages From"></asp:ListItem>
</asp:RadioButtonList>
</td>
<div id="divAge" runat="server" visible="false">
<td>
<asp:TextBox ID="txtAgeFrom" runat="server" CssClass="textEntry2" MaxLength="3" Width="65"></asp:TextBox>
</td>
<td>
<asp:Label ID="lblTo" runat="server" Text="To"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtAgeTo" runat="server" CssClass="textEntry2" MaxLength="3" Width="65"></asp:TextBox>
</td>
</div>
</tr>
</table>
Code of cs file:
protected void rdoAge_SelectedIndexChanged(object sender, EventArgs e)
{
switch (rdoAge.SelectedValue)
{
case "All Ages":
divAge.Visible = false;
break;
case "Ages From":
divAge.Visible = true;
break;
}
}
I'll be grateful if anyone suggests something useful for this issue.
Thanks in advance.
That was the problem of missing closing tag. I must have missed a closing tag of some control. I re-added all controls with taking care of closing tags. Now it is working fine.
Thanks all for helping.
try using css sytel
<style type="text/css">
table.radioWithProperWrap input
{
float: left;
}
table.radioWithProperWrap label
{
word-wrap: break-word;
}
</style>
<asp:RadioButtonList runat="server" CssClass="radioWithProperWrap" ....>
switch (rdoAge.SelectedItem.Text)
In the Source Code, Define the Update Panel like this:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
and then in the OnSelectedIndexChanged event, add
UpdatePanel1.Update();

Label not becoming visible inside of repeater inside an updatepanel

I have an UpdatePanel that contains a Repeater. in the ItemTemplate of the repeater there is a button and a label.
When the button gets pressed, it performs some functionality, and then sets the label to visible and disables the button.
However none of the UI changes are being made to the webpage.
Here is the code, which when stepping through in debugger appears to work fine:
protected void CommentRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "report")
{
(e.Item.FindControl("btnReportComment") as ImageButton).Enabled = false;
Label thanksLabel = (Label)e.Item.FindControl("lblReportedComment");
thanksLabel.Visible = true;
}
pnlCommentsUpdater.Update();
}
and the page's code (excluding code outside of the repeater)
<asp:UpdatePanel UpdateMode="Conditional" ID="pnlCommentsUpdater" runat="server">
<ContentTemplate>
<asp:LinkButton ID="lnkPhoto1Comments" runat="server" Text="0 Comments" OnClick="lnkPhoto1Comments_Click" CssClass="dark-gray regular bold"></asp:LinkButton>
<asp:Panel ID="pnlPhoto1Comments" runat="server" Visible="False">
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="CommentRepeater_ItemCommand">
<ItemTemplate>
<br />
<hr width="100%" size="1" color="#CCCCCC" />
<table width="534" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="150" align="left" valign="top">
<span class="blue small bold"><%# Eval("PostedBy") %>,</span><br />
<span class="light-gray small bold"><%# Eval("DateCreated", "{0:g}") %></span>
</td>
<td width="20"></td>
<td width="252" align="left" valign="top">
<div STYLE="word-wrap:break-word;width:252px;left:0">
<span class="dark-gray small bold"><%# Eval("CommentText") %></span>
</div>
</td>
<td width="20"></td>
<td width="92" valign="bottom">
<asp:ImageButton ID="btnReportComment" runat="server" ImageUrl="../images/inappropriate_off.png" CssClass="domclickroll images/inappropriate_on.png images/inappropriate_on.png" AlternateText="Inappropriate" CommandName="report" CommandArgument='<%#Eval("CommentId") %>' /><br />
<asp:Label ID="lblReportedComment" runat="server" Visible="false" CssClass="Regular bold blue" Text="Thanks. We'll check it out!"></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
As I said, the debugger shows it to be working fine, however it simply doesn ot show the label in the browser after clicking the button.
Anyone know what I'm doing wrong?
The error is: "Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled."
And I am calling
ScriptManager.GetCurrent(Page).RegisterPostBackControl(Repeater1);
in the page load, which I read in some sites is the solution, but it did not help.
Check out this blog post...
http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx
It contains a number of approaches to fixing this. With respect to your call...
ScriptManager.GetCurrent(Page).RegisterPostBackControl(Repeater1);
... I think you're supposed to pass the button to RegisterPostBackControl, and not the repeater. i.e pass it btnReportComment instead. From the reference above...
3.Call ScriptManager.RegisterPostBackControl()
and pass in the button in question.
This is the best solution for controls
that are added dynamically, such as
those inside a repeating template.
First step is to narrow down your problem. If you take out the UpdatePanel altogether, does it work OK?
Also, right off the bat I see that pnlPhoto1Comments.Visible is set to false... ? This is getting set correctly somewhere I suppose, otherwise you wouldn't even get the ItemCommand event. So probably not a problem.

Resources