I have an ASP.NET web application. I have one TextBox (txtProductName) and one DropDownList(ddlChanges) visible at the time of page load. Also there is a TextBox(txtDeliveryStatus) and a Label (lblDeliveryStatus) invisible at page load.
<asp:TextBox ID="txtProductName" runat="server" CssClass="selectstyle" MaxLength="8" Width="60" />
<asp:Label ID="lblDeliveryStatus" runat="server" Style="visibility: hidden;">Delivery Status : </asp:Label>
<asp:TextBox ID="txtDeliveryStatus" runat="server" CssClass="selectstyle" Style="visibility: hidden;"/>
<asp:DropDownList runat="server" ID="ddlChanges" CssClass="selectstyle" onchange="javascript:ddlChangesChanged();">
<asp:ListItem Text="-- Select -- " Value="-1"></asp:ListItem>
<asp:ListItem Text="Status Change" Value="1"></asp:ListItem>
<asp:ListItem Text="Product Name Change" Value="2"></asp:ListItem>
<asp:ListItem Text="Category Change" Value="3"></asp:ListItem>
</asp:DropDownList>
I will make the Label and TextBoxfor delivery status visible when user selects Status Change from the DropDownList. But the problem is that the Label and TextBox for delivery status are invisible and still they take up some space on the page between visible controls.
How to remove that space of invisible controls?
the reason the white space is still showing after you control.Visible = false is because the "br" newLine tags are remaining. Wrap them with your button tag and hide both to truly remove the white space.
You should use the display attribute:
<asp:Label ID="lblDeliveryStatus" runat="server" Style="display: none;">Delivery Status : </asp:Label>
<asp:TextBox ID="txtDeliveryStatus" runat="server" CssClass="selectstyle" Style="display: none;"/>
For completeness you can check this link.
You can use visible attribute of control.
To hide:
Control.Visibile=false;
Whenever you want to display
Control.Visible=true;
Related
Every time I include a dropdown menu, my css layout mess up. Can someone explain to me why and how to fix it?
Here is my code:
<asp:Label ID="projnamelbl" runat="server" CssClass="editlabels" Text="Project Name"></asp:Label>
<asp:TextBox ID="projnametxt" runat="server"></asp:TextBox><br />
<asp:Label ID="paymentlbl" runat="server" CssClass="editlabels" Text="Payment Type:"></asp:Label>
<asp:DropDownList ID="paymentype" runat="server">
<asp:ListItem Text="Cash" Value="cash"></asp:ListItem>
<asp:ListItem Text="Intallments" Value="installments"></asp:ListItem>
</asp:DropDownList><br />
<asp:Label ID="projsumlbl" CssClass="editlabels" runat="server" Text="Project Sum:"></asp:Label>
<asp:TextBox ID="projsumtxt" runat="server"></asp:TextBox><br />
CSS:
.editlabels {
float:left;
width:150px;
margin-right:0.2em;
padding-top:0.4em;
padding-left:20px;
text-align:left;
font-weight:bold;
}
Anything that goes after the dropdown menu goes to the right for some reason.
Only if you remove your margin and padding things would automatically fall in place.
You need to put position: relative on the main container then on any sub ones use position: absolute
I have a page having multiple buttons and search functionality.I have placed one button and textbox in a panel.After writing seach text if I hit Enter,it works well for all the browsers on local, but for live application this is not working in IE.
The html is:
<asp:Panel ID="pnlSearch" runat="server" CssClass="search" DefaultButton="btnSearch">
<h2>
Explore QualityStocks without logging in</h2>
<asp:TextBox ID="txtSearch" CssClass="txt" runat="server" ToolTip="Stock Ticker" ></asp:TextBox>
<asp:Button TabIndex="0" ID="btnSearch" runat="server" ClientIDMode="Static" CssClass="btn" OnClick="btnSearch_Click" />
</asp:Panel>
What am I missing to do?
Thanks in advance,
Priya
I have two questions that are in the form of radio button lists in C# web application. These questions have required field validators associated to them and I also have a ValidationSummary at the end of my web control. When I click on my "Submit" button, the two required field validations appear for each of the questions right next to it and the validationsummary works correctly by stating "Answer the following questions:" and then listing each of the questions that were not selected. The problem I'm having is when I select one of the two questions, the "Required Field" message disappears next to the question, but not in the ValidationSummary. How can I get the ValidationSummary to update or refresh when one of the questions in the error messages are selected? Please let me know if I need to be more specific. Thanks for your help!
<asp:RadioButtonList ID="Question1" RepeatLayout="Flow" runat="server">
<asp:ListItem Text="Yes" Value="Yes"></asp:ListItem>
<asp:ListItem Text="No" Value="No"></asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
Text="Required" ErrorMessage="Question 1"
Display="Dynamic" ControlToValidate="Question1"
EnableClientScript="true">
</asp:RequiredFieldValidator>
<asp:RadioButtonList ID="Question2" RepeatLayout="Flow" runat="server">
<asp:ListItem Text="Yes" Value="Yes"></asp:ListItem>
<asp:ListItem Text="No" Value="No"></asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
Text="Required" ErrorMessage="Question 2"
Display="Dynamic" ControlToValidate="Question2"
EnableClientScript="true">
</asp:RequiredFieldValidator>
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
HeaderText="Answer the following questions:"
DisplayMode="BulletList"
EnableClientScript="true"/>
<asp:Button ID="buttonSubmit" runat="server" Text="Submit"
OnClick="btnSubmit_OnClick"/>
//Code behind for button
protected void btnSubmit_OnClick(object sender, EventArgs e)
{
Response.BufferOutput = true;
Response.Redirect("~/Page.aspx");
}
I'm pretty sure the summary doesn't dynamically update by default, but rather only on form submit.
Ordinarily, you could get around this by hooking the client-side onblur event and calling ValidationSummaryOnSubmit(), but it looks like the RadioButtonList doesn't trigger this event when the selected radio button changes.
The next candidate would be the client-side onClick event, but the RadioButtonList control doesn't have an OnClientClick event.
So, the solution which worked for me when I tested it was to hook the client-side onClick event for each ListItem in the RadioButtonList. Like this:
<asp:RadioButtonList ID="Question1" RepeatLayout="Flow" runat="server">
<asp:ListItem Text="Yes" Value="Yes" onClick="ValidationSummaryOnSubmit()"></asp:ListItem>
<asp:ListItem Text="No" Value="No" onClick="ValidationSummaryOnSubmit()"></asp:ListItem>
</asp:RadioButtonList>
However, this will get rapidly ugly if you've got a bunch of these that you're going to want to do. Might consider subclassing RadioButtonList and adding a server-side addition of the ListItem onclick hook to each of the child listitems before sending it to the client, and then using your custom version of RadioButtonList instead of the stock version.
I have textbox and listbox inside an update panel. My textbox is enabled with dropdownlistextender that its values is in some currencies like USD,MYR,Yen etc. But when I select value from this list, it doesnt show up in textbox. What should I do? When it display in textbox, it should be inserted into my created database. Thanks in forward.
<asp:TextBox ID="txtCurrency" runat="server"></asp:TextBox>
<asp:DropDownExtender ID="txtCurrency_DropDownExtender" runat="server"
DropDownControlID="ListBox1" DynamicServicePath="" Enabled="True"
TargetControlID="txtCurrency">
</asp:DropDownExtender>
<asp:ListBox ID="ListBox1" runat="server"
onselectedindexchanged="ListBox1_SelectedIndexChanged">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem>MYR</asp:ListItem>
<asp:ListItem>USD</asp:ListItem>
<asp:ListItem>EURO</asp:ListItem>
<asp:ListItem>POUND</asp:ListItem>
<asp:ListItem>Singapore Dollar</asp:ListItem>
<asp:ListItem>Yuan/Renmibi</asp:ListItem>
<asp:ListItem>Japan Yen</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:ListBox>
I have two radio buttons for metric and US measurements. I load the page so the metric radio button is clicked. How do I set the two buttons so when US is clicked metric unclicks and vise versa?
In order to make it work, you have to set property GroupName of both radio buttons to the same value:
<asp:RadioButton id="rbMetric" runat="server" GroupName="measurementSystem"></asp:RadioButton>
<asp:RadioButton id="rbUS" runat="server" GroupName="measurementSystem"></asp:RadioButton>
Personally, I prefer to use a RadioButtonList:
<asp:RadioButtonList ID="rblMeasurementSystem" runat="server">
<asp:ListItem Text="Metric" Value="metric" />
<asp:ListItem Text="US" Value="us" />
</asp:RadioButtonList>
Make sure their GroupName properties are set to the same name:
<asp:RadioButton GroupName="MeasurementSystem" runat="server" Text="US" />
<asp:RadioButton GroupName="MeasurementSystem" runat="server" Text="Metric" />
I can see it's an old question, if you want to put other HTML inside could use the radiobutton with GroupName propery same in all radiobuttons and in the Text property set something like an image or the html you need.
<asp:RadioButton GroupName="group1" runat="server" ID="paypalrb" Text="<img src='https://www.paypalobjects.com/webstatic/mktg/logo/bdg_secured_by_pp_2line.png' border='0' alt='Secured by PayPal' style='width: 103px; height: 61px; padding:10px;'>" />
<asp:RadioButtonList id="RadioButtonList1" runat="server">
<asp:ListItem Selected="True">Metric</asp:ListItem>
<asp:ListItem>US</asp:ListItem>
</asp:RadioButtonList>
Set the GroupName property of both radio buttons to the same value. You could also try using a RadioButtonGroup, which does this for you automatically.