Radiobutton Text alignment Issue - asp.net

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();

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

Hide EmptyDataTemplate but leave header visible

I have an EmptyDataTemplate on my ASP.NET webform which allows users to add a record to the database. Depending on the permissions of the user, this EmptyDataTemplate needs to be visible and hidden if no data is found (I have this working!)
For example, my user has Read Access only. When they search a specific criteria, no results are displayed they cannot see the EmptyDataTemplate. However, if they search a criteria, and there is data, data is displayed WITHOUT the headers.
Can someone please help explain why this is happening and if there's a way around it?
The headers are HeaderText on TemplateFields.
I'm hoping it's a general trick.
Thank you in advance for your help!
Please note, it's the HeaderText in the TemplateFields I want to display- not the in the emptyDataTemplate as they'll head up the columns of data that match the search criteria.
edit: code added as requested
For hiding the EmptyDataTemplate:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Control control = null;
control = GridView1.Controls[0].Controls[0];
if (userManagement.getMIFReadWriteAccess() == "Read")
{
control.Visible = false;
Export_All.Visible = true;
}
else if (userManagement.getMIFReadWriteAccess() == "Write")
{
control.Visible = true;
Export_All.Visible = true;
}
}
in markup for the header text (i've only shown one column but the markup is the same for all of them)
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lbl_Index" runat="server" Text='<%#Eval("id") %>'></asp:Label>
<asp:Label ID="lbl_ID" runat="server" Text="" Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
EmptyDataTemplate:
<EmptyDataTemplate>
<div id="emptyData" runat="server">
<tr>
<th></th>
<th>Serial Number</th>
<th>Comments</th>
<th>Review Date</th>
<th>Approved By</th>
</tr>
<tr>
<td>
<asp:Button runat="server" ID="btInsert" Text="In" OnClick="Add" CommandName="EmptyDataTemplate" Class="Button" OnClientClick="return confirm('You are about to confirm this action. Please confirm this action by clicking OK. If you do not wish to do this, please select Cancel.');" />
<br />
<asp:Button runat="server" ID="btInsertOut" Text="Out" OnClick="AddOut" CommandName="EmptyDataTemplate" Class="Button" OnClientClick="return confirm('You are about to confirm this action. Please confirm this action by clicking OK. If you do not wish to do this, please select Cancel.');" />
</td>
<td>
<asp:TextBox runat="server" ID="tb_Serial_Number" CssClass="text"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="tb_comments" Width="100%" MaxLength="50" runat="server" placeholder="max 50 characters"/>
</td>
<td>
<asp:TextBox ID="tb_reviewDate" runat="server" DataFormatString="{0:dd/mm/yyyy}" Text='<%#Eval("review_by") %>'></asp:TextBox>
</td>
<td><asp:DropDownList ID="tb_approved_by" runat="server">
</asp:DropDownList> </td>
</tr>
</div>
</EmptyDataTemplate>
After trial and error, I found that programatically adding a header row in C# did the trick. Probably not the best way of doing it, but it worked.
Code is as follows:
#region show the emptyDataTemplate depending on user rights
Control control = null;
control = GridView1.Controls[0].Controls[0];
if (userManagement.getMIFReadWriteAccess() == "Read")
{
control.Visible = false;
GridViewRow HeaderRow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell HeaderCell2 = new TableCell();
HeaderCell2.Text = "Country";
HeaderCell2.ColumnSpan = 1;
HeaderRow.Cells.Add(HeaderCell2);
//Repeat the above for every column of data you have!
GridView1.Controls[0].Controls.AddAt(0, HeaderRow);

What is causing text box with a MaskedEditExtender to duplicate characters?

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.

Shading every other row in a VB.net Listview?

I have been Googling this for about a day now, and every post I find is too old and Visual Studio doesn't recognize some pieces of code that people have posted. I have a dynamically populated Listview. I would really like every other line to be shaded for readability purposes, and just can't figure it out.
Everything I try to do messes with the Modal PopupExtender that I have inside of the Listview. It trys to shade the lines inside the PopUpBox too. This is one of the Listviews that I would like shaded.
<!-- Descriptions -->
<asp:TabPanel ID="tab2" runat="server" HeaderText="Descriptions">
<HeaderTemplate>Descriptions</HeaderTemplate>
<ContentTemplate>
<ul class="info">
<asp:ListView ID="lvDescriptions" runat="server" DataSourceID="dsMarketingDescriptions" DataKeyNames="MarketingID">
<ItemTemplate>
<li>
<asp:LinkButton ID="ViewDescriptionButton" runat="server"><%#Eval("MarketingTitle")%></asp:LinkButton>
<asp:Panel ID="ViewDescriptionPanel" runat="server" CssClass="DescModalPopup"> <div class="PopupHeader" id="PopupHeader">View Description
<asp:ImageButton ID="CancelDescriptionButton" runat="server" ImageUrl="../../images/exit.png" AlternateText="" Style="float:right;"/>
</div>
<asp:Label ID="Description" runat="server" style="padding:5px;"><%# Eval("MarketingData") %></asp:Label>
</asp:Panel>
<asp:ModalPopupExtender ID="ViewDescriptionModal" runat="server" BackgroundCssClass="modalBackground" DropShadow="false" DynamicServicePath="" Enabled="true" PopupControlID="ViewDescriptionPanel" TargetControlID="ViewDescriptionButton" CancelControlID="CancelDescriptionButton"></asp:ModalPopupExtender>
</li>
</ItemTemplate>
</asp:ListView>
</ul>
</ContentTemplate>
</asp:TabPanel>
Try using the AlternatingItemTemplate to specify a different background color for alternating items.
Are you trying to do something like this with the ModalPopupExtender?:
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
Panel pnl = e.Item.FindControl("Panel1") as Panel;
if (pnl != null)
{
pnl.BackColor = ListView1.Items.IndexOf(e.Item) % 2 == 1 ? Color.PeachPuff : Color.White;
}
}

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