I have got problem with FileUpload control. I have this one, two drop down list, text box and button. If I select in first dropDownList "Yes" second one become disable and set value on NO (In second ddl I have two option YES or NO and in first one as well) however if I select NO in first dropDownList I posible to choose both option in second dropDownList. First ddl change second one on postBack using selectedIndexChanged evet and when it happends I loose file name in UploadFile control which I set before.
Code sample:
<asp:FileUpload ID="fuUploadGeometry" runat="server" Width="100%" />
<asp:DropDownListID="ddlSymmetry"runat="server" AutoPostBack="true"
onselectedindexchanged="ddlSymmetry_SelectedIndexChanged">
<asp:ListItem Value="0">-- Select --</asp:ListItem>
<asp:ListItem Value="true">Yes</asp:ListItem>
<asp:ListItem Value="false">No</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlModule" runat="server" Enabled="True">
<asp:ListItem Text="-- Select --" Value="0"/>
<asp:ListItem Text="Yes" Value="1" />
<asp:ListItem Text="No" Value="2"/>
</asp:DropDownList>
<asp:TextBox ID="txtTopic" runat="server"></asp:TextBox>
What should I do to keep file name in UploadFile control during changes selected options in drop down lists?
Try this, I added the label so you can see that the postback of the onselectedindexchange only affects the dropdown and not the file upload control, hope this helps.
<asp:FileUpload ID="fuUploadGeometry" runat="server" Width="100%" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlSymmetry" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlSymmetry_SelectedIndexChanged">
<asp:ListItem Value="0">-- Select --</asp:ListItem>
<asp:ListItem Value="true">Yes</asp:ListItem>
<asp:ListItem Value="false">No</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlModule" runat="server" Enabled="True">
<asp:ListItem Text="-- Select --" Value="0" />
<asp:ListItem Text="Yes" Value="1" />
<asp:ListItem Text="No" Value="2" />
</asp:DropDownList>
<asp:TextBox ID="txtTopic" runat="server"></asp:TextBox>
<asp:Label runat="server" ID="msgFromList" />
</ContentTemplate>
</asp:UpdatePanel>
protected void ddlSymmetry_SelectedIndexChanged(Object sender, EventArgs e)
{
msgFromList.Text = ddlSymmetry.SelectedItem.Value.ToString();
}
First thing keep in ur mind that is FileUpload Control Will became empty if any post back event occur on ur web page. So best solution is to put ur file upload control after all controll that can cause a post back like drop down list.
Related
To provide consistency, I cannot use an alert box to display a message in my code when someone chooses a specific item in a dropdownlist. It needs to display a red message below the dropdown field only if someone has chosen a specific item.
So in this case if someone chooses Alabama from a state dropdownlist for example, a red message needs to display below the dropdownlist box immediately after the choice is made. The old version of this form works accurately, but the new version of the form with many changes in it is not displaying this message.
In the code behind file (the aspx.vb file) I have these code snippets:
Protected Sub StateDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles StateDropDownList.SelectedIndexChanged
If StateDropDownList.Text = "AK" Then
AlabamaPanel.Visible = True
Session("Alabama") = "Yes"
Else
AlabamaPanel.Visible = False
Session("Alabama") = "No"
End If
StateDropDownList.Focus()
End Sub
I'm using previous code with certain edits and another part of the problem is that I don't understand the Session("Alabama") part - I don't find anywhere else in the code where Session("Alabama") is listed or rather to understand what Session() is and how it even would know what an Alabama Session is... So if you know something about Session() that might be helpful - I see this (https://msdn.microsoft.com/en-us/library/ms178581%28v=vs.140%29.aspx) but that's not helping me understand. The only place in the code that Alabama by itself exists is in the items of the dropdownlist. And maybe that is part of the problem since in the old code the Alabama was specifically noted in a long list like (in the aspx file, not the aspx.vb file) such:
<asp:DropDownList class="DropDowns" ID="StateDropDownList" runat="server" AutoPostBack="True">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="AL">Alabama</asp:ListItem>
<asp:ListItem Value="AK">Alaska</asp:ListItem>
<asp:ListItem Value="AZ">Arizona</asp:ListItem>
<asp:ListItem Value="AR">Arkansas</asp:ListItem>
<asp:ListItem Value="CA">California</asp:ListItem>
<asp:ListItem Value="CO">Colorado</asp:ListItem>
<asp:ListItem Value="CT">Connecticut</asp:ListItem>
<asp:ListItem Value="DE">Delaware</asp:ListItem>
<asp:ListItem Value="DC">District of Columbia</asp:ListItem>
<asp:ListItem Value="FL">Florida</asp:ListItem>
<asp:ListItem Value="GA">Georgia</asp:ListItem>
<asp:ListItem Value="HI">Hawai'i</asp:ListItem>
<asp:ListItem Value="ID">Idaho</asp:ListItem>
<asp:ListItem Value="IL">Illinois</asp:ListItem>
<asp:ListItem Value="IN">Indiana</asp:ListItem>
<asp:ListItem Value="IA">Iowa</asp:ListItem>
<asp:ListItem Value="KS">Kansas</asp:ListItem>
<asp:ListItem Value="KY">Kentucky</asp:ListItem>
<asp:ListItem Value="LA">Louisiana</asp:ListItem>
<asp:ListItem Value="ME">Maine</asp:ListItem>
<asp:ListItem Value="MD">Maryland</asp:ListItem>
<asp:ListItem Value="MA">Massachusetts</asp:ListItem>
<asp:ListItem Value="MI">Michigan</asp:ListItem>
<asp:ListItem Value="MN">Minnesota</asp:ListItem>
<asp:ListItem Value="MS">Mississippi</asp:ListItem>
<asp:ListItem Value="MO">Missouri</asp:ListItem>
<asp:ListItem Value="MT">Montana</asp:ListItem>
<asp:ListItem Value="NE">Nebraska</asp:ListItem>
<asp:ListItem Value="NV">Nevada</asp:ListItem>
<asp:ListItem Value="NH">New Hampshire</asp:ListItem>
<asp:ListItem Value="NJ">New Jersey</asp:ListItem>
<asp:ListItem Value="NM">New Mexico</asp:ListItem>
<asp:ListItem Value="NY">New York</asp:ListItem>
<asp:ListItem Value="NC">North Carolina</asp:ListItem>
<asp:ListItem Value="ND">North Dakota</asp:ListItem>
<asp:ListItem Value="OH">Ohio</asp:ListItem>
<asp:ListItem Value="OK">Oklahoma</asp:ListItem>
<asp:ListItem Value="OR">Oregon</asp:ListItem>
<asp:ListItem Value="PA">Pennsylvania</asp:ListItem>
<asp:ListItem Value="RI">Rhode Island</asp:ListItem>
<asp:ListItem Value="SC">South Carolina</asp:ListItem>
<asp:ListItem Value="SD">South Dakota</asp:ListItem>
<asp:ListItem Value="TN">Tennessee</asp:ListItem>
<asp:ListItem Value="TX">Texas</asp:ListItem>
<asp:ListItem Value="UT">Utah</asp:ListItem>
<asp:ListItem Value="VT">Vermont</asp:ListItem>
<asp:ListItem Value="VA">Virgina</asp:ListItem>
<asp:ListItem Value="WA">Washington</asp:ListItem>
<asp:ListItem Value="WV">West Virgina</asp:ListItem>
<asp:ListItem Value="WI">Wisconsin</asp:ListItem>
<asp:ListItem Value="WY">Wyoming</asp:ListItem>
</asp:DropDownList>
But now we are calling to another VB file to grab the state dropdown list and the full set as shown above is no longer in the code.
Since there is nowhere besides this list that no longer exists or this list that does exist in the separate vb file we are calling to which is successfully populating the dropdownlist, then that could perhaps be blocking the Session() from working?
In the new code (in the aspx file, not the aspx.vb file), all of the above is replaced with:
<label for="StateDropDownList">State <span class="Required">*</span></label>
<asp:DropDownList class="form-control" ID="StateDropDownList" runat="server">
</asp:DropDownList>
I'm trying to use (in the aspx file) :
<asp:Panel ID="AlabamaPanel" runat="server" Visible="false">
<tr>
<td align="center" colspan="3">
<br />
<asp:Label ID="AlabamaLabel" runat="server" visibile="false" Text="Alabama Text that I want to appear right below the statedropdownlist field if they choose alabama."
Font-Bold="True" ForeColor="#e00022" />
</td>
</tr>
</asp:Panel>
to get the text to show up on the page below the dropdown field if the user chooses Alabama and it's simply not displaying. I have also tried putting the long list of states back in instead of calling out to the separate dropdowns vb file.
I'm also trying to use Update Panel, wrapping the dropdown list with an
<asp:UpdatePanel ID="UpdatePanel1"
UpdateMode="Conditional"
runat="server">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
And that has benefited me because before that I wasn't able to include the autopostback="true" without it taking me to a blank screen whenever someone chose Alabama from the dropdown list. Now at least the entire screen isn't blanking out... But still I'm not getting the message to show on the screen.
Also I've tried this, but still no message appearing:
<asp:DropDownList class="form-control" ID="StateDropDownList" runat="server" AutoPostBack="True" CausesValidation="False" OnSelectedIndexChanged="StateDropDownList_SelectedIndexChanged">
Any ideas or is anything glaringly obvious as to why my message isn't showing up when someone chooses Alabama?
Try this:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="updtPnl">
<ContentTemplate>
<asp:DropDownList class="form-control" ID="StateDropDownList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="StateDropDownList_SelectedIndexChanged">
<asp:ListItem Value="Al">Alabama</asp:ListItem>
<asp:ListItem>Other value</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="AlabamaLabel" runat="server" visibile="false" Text=""
Font-Bold="True" ForeColor="#e00022" />
</ContentTemplate>
</asp:UpdatePanel>
And change the code-behind as:
Protected Sub StateDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles StateDropDownList.SelectedIndexChanged
If StateDropDownList.SelectedValue = "Al" Then
AlabamaLabel.Text = StateDropDownList.SelectedItem.Text + " is selected!"
AlabamaLabel.Visible = True
Else
AlabamaLabel.Visible = False
End If
End Sub
In the original code that you provided you have the following issues:
1) you are looking at the text of the Dropdown for an abbreviation, which is not the text in the dropdown that is the value so you would need to use something like StateDropDownList.SelectedValue = "AK"
2) The AlabamaPanel gets set to visible however; you do not set the visibility of the label to true, so the panel is visible, but has no controls in it that are visible.
Basically I have a aspx page function that will not seem to activate. I've created a function that's supposed to run on selectedindexchange of a dropdownmenu.
<asp:TableCell>Credit Card Type: <asp:DropDownList
id="DropDownCredit"
OnSelectedIndexChanged="creditType"
Runat="server">
<asp:ListItem Text="Select" Value="Empty" />
<asp:ListItem Text="Visa" Value="Visa" />
<asp:ListItem Text="Mastercard" Value="Mastercard" />
<asp:ListItem Text="Discover" Value="Discover" />
<asp:ListItem Text="American Express" Value="American Express" />
</asp:DropDownList>
There as you can see I added my function name to run when they select something. Now my function itself is extremely simple.
Protected Sub creditType()
If DropDownCredit.SelectedIndex.ToString.StartsWith("A") Then
TextBoxCardNumberAmerican.Enabled = True
Else
TextBoxCardNumberOthers.Enabled = True
End If
End Sub
By the way I have set the two textboxes mentioned in the above function to disabled inititally, so only if one is correct then it is enabled. I am going to guess that the string isn't being interpreted properly. Any help would be great thankyou.
Two things: Your creditYpe method has the wrong signature it should be:
Protected Sub creditType(Object o, EventArgs e)
..and add the AutoPostBack="true" property to your asp control
Credit Card Type: <asp:DropDownList
id="DropDownCredit"
OnSelectedIndexChanged="creditType"
AutoPostBack="true"
Runat="server">
<asp:ListItem Text="Select" Value="Empty" />
<asp:ListItem Text="Visa" Value="Visa" />
<asp:ListItem Text="Mastercard" Value="Mastercard" />
<asp:ListItem Text="Discover" Value="Discover" />
<asp:ListItem Text="American Express" Value="American Express" />
</asp:DropDownList>
you should add the AutoPostBack="True" property to the dropdown
only then the server side sub will be executed
Please set the
AutoPostBack="True"
On the dropdown. Like this:
<asp:DropDownList id="DropDownCredit"
OnSelectedIndexChanged="creditType" AutoPostBack="True" Runat="server">
The the event will fire
I have the following code
<div>
<asp:DropDownList ID="testDropDownList" runat="server" ValidationGroup="testValidationGroup">
<asp:ListItem Value="Choose">[ Select Item ... ]</asp:ListItem>
<asp:ListItem Value="True">Yes</asp:ListItem>
<asp:ListItem Value="False">No</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="testRequiredFieldValidator" runat="server" ValidationGroup="testValidationGroup"
ErrorMessage="*" InitialValue="Choose" ControlToValidate="testDropDownList"></asp:RequiredFieldValidator>
<br />
<asp:Button ID="testButton" runat="server" OnClick="testButton_Click" Text="Button"
ValidationGroup="testValidationGroup" />
<br />
</div>
in which i validate Dropdownlist by RequiredFieldValidator
If changed the value of initialvalue property to read from static property in stactic classs .. but it always give me emtpy string in runtime unless this property have the value "Choose" ...
<asp:DropDownList ID="testDropDownList" runat="server" ValidationGroup="testValidationGroup">
<asp:ListItem Value="Choose">[ Select Item ... ]</asp:ListItem>
<asp:ListItem Value="True">Yes</asp:ListItem>
<asp:ListItem Value="False">No</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="testRequiredFieldValidator" runat="server" ValidationGroup="testValidationGroup"
ErrorMessage="*" InitialValue='<%# Util.ChooseValue %>' ControlToValidate="testDropDownList">
</asp:RequiredFieldValidator>
<br />
<asp:Button ID="testButton" runat="server" OnClick="testButton_Click" Text="Button"
ValidationGroup="testValidationGroup" />
Could Any one help me to know what's the issue in my code ??
Please call
testRequiredFieldValidator.databind()
in page load event and let me know if this is still an issue.
Set InitialValue of RequiredFieldValidator on page_load event in aspx.cs page.
<asp:DropDownList ID="ddTitle" runat="server" DataTextField="TitleName" DataValueField="TitleId"ValidationGroup="t1">
</asp:DropDownList>
<asp:RequiredFieldValidator runat="server" ID="ReqDropDnw" ControlToValidate="ddTitle" Display="Dynamic" ValidationGroup="t1" InitialValue="<-- Select Title-->" ErrorMessage="Please Select Title">
</asp:RequiredFieldValidator>
I have used this but it's not working, can I have a proper solution for it
My dropdown list is a dynamic.
Use like this way...
<asp:DropDownList ID="ddl" runat="server">
<asp:ListItem Text="Select One" Value=""></asp:ListItem>
<asp:ListItem Text="abc" Value="1"></asp:ListItem>
<asp:ListItem Text="xyz" Value="2"></asp:ListItem>
</asp:DropDownList>
Now you can use required field validator for this dropdownlist.....
After binding data from DB you can use add one empty item to list like:
ddTitle.Items.Insert(0, "");
And now Required field validatior will work for this dropdown.
I am databinding a GridView to an object datasource. The gridview contains a TemplateField which contains a RadioButtonList with ListItems defined inline.
I want to be able to databind the SelectedValue of the RadioButtonList to the same underlying table as the other grid columns, but it doesn't work!
Do I have my syntax wrong, or is this impossible and requires looping code to individually select the proper item in each row?
<llblgenpro:LLBLGenProDataSource ID="llbComputerApplication" DataContainerType="EntityCollection" runat="server"></llblgenpro:LLBLGenProDataSource>
<asp:GridView ID="gridComputerApps" DataSourceID="llbComputerApplication" runat="server" AutoGenerateColumns="False"
EmptyDataText ="NO APPLICATIONS FOUND FOR THIS COMPUTER."
DataKeyNames="ComputerID, ApplicationID" EnableViewState="False"
style="border-style:dotted;border-width:thin"
>
<Columns>
<asp:BoundField DataField="ApplicationID" HeaderText="Application ID" SortExpression="ApplicationID" Visible="True" />
<asp:TemplateField HeaderText="Application Name"><ItemTemplate><%#Eval("Application.ApplicationName")%></ItemTemplate></asp:TemplateField>
<asp:TemplateField HeaderText="Normalized Name"><ItemTemplate><%#Eval("Application.NormalizedAppName")%></ItemTemplate></asp:TemplateField>
<asp:TemplateField HeaderText="Notes"><ItemTemplate><%#Eval("Application.NormalizedNotes")%></ItemTemplate></asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:RadioButtonList SelectedValue='<%#Eval("RequirementOption")%>' ID="rblRequirementOption" RepeatDirection="Horizontal" runat="server">
<asp:ListItem Value="Need Now" Text="Need Now"></asp:ListItem>
<asp:ListItem Value="Need Someday" Text="Need Someday"></asp:ListItem>
<asp:ListItem Value="Do Not Need" Text="Do Not Need"></asp:ListItem>
</asp:RadioButtonList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NormalizedNotes" HeaderText="Notes" Visible="False" />
</Columns>
</asp:GridView>
What you have should work. Are you getting an error? Here's a working example copied from my current project. I'm binding to a nullable bit field - so have a hidden list item to accept the nulls.
<asp:RadioButtonList runat="server" ID="MyRbl" SelectedValue='<%# Bind("MyRblField") %>'
CssClass="NormalTextBox" RepeatDirection="Horizontal">
<asp:ListItem Value="false" Text="No" />
<asp:ListItem Value="true" Text="Yes" />
<asp:ListItem Value="" Text="" style="display: none" />
</asp:RadioButtonList>
I also experienced this problem (nothing selected in radiobuttonlist) when binding against boolean values in MS SQL:
radDefault.Items.Add(new ListItem("Yes", "true"));
radDefault.Items.Add(new ListItem("No", "false"));
In my case, the solution was to capitalize the first letter of the true/false values, then the radiobuttonlistworked as expected:
radDefault.Items.Add(new ListItem("Yes", "True"));
radDefault.Items.Add(new ListItem("No", "False"));
Or, declaratively:
<asp:RadioButtonList runat="server" ID="radDefault" SelectedValue='<%# Bind("DB_FIELD") %>'>
<asp:ListItem Value="False" Text="No" />
<asp:ListItem Value="True" Text="Yes" />
</asp:RadioButtonList>
I didn't like the idea of using css to hide an item. Instead, I found this solution to add a blank item but remove it in the code behind.
<asp:RadioButtonList ID="MyRadioButtonList" runat="server"
SelectedValue='<%# Bind("Blah") %>'
OnDataBound="MyRadioButtonList_DataBound">
<asp:ListItem Value=""></asp:ListItem>
<asp:ListItem Value="A"></asp:ListItem>
<asp:ListItem Value="B"></asp:ListItem>
<asp:ListItem Value="C"></asp:ListItem>
</asp:RadioButtonList>
protected void MyRadioButtonList_DataBound(object sender, EventArgs e)
{
RadioButtonList list = (RadioButtonList)sender;
ListItem blank = list.Items.FindByValue("");
if (blank != null)
list.Items.Remove(blank);
}
<asp:RadioButtonList runat="server" ID="MyRbl" SelectedValue='<%# Bind("MyRblField") %>'
CssClass="NormalTextBox" RepeatDirection="Horizontal">
<asp:ListItem Value="false" Text="No" />
<asp:ListItem Value="true" Text="Yes" />
<asp:ListItem Value="" Text="" selected="true" style="display: none" />
</asp:RadioButtonList>
It work me .....
gnanasekar.s vilangulathur