asp.net dropdown listbox not holding viewstate - vb.net

I am using VS 2008, VB and using a dorpdown listbox in my asp.net webpage. I select a value from the dropdown, click the submit button, when the page comes back from the server, the value in the dropdown is blank (default). The dropdown controls viewstate is enabled.
The code for the submit button is:
<asp:Button ID="ButtonSubmit" runat="server" Text="Submit" CssClass="Button" />
The dropdownlist code is:
What am I missing here?

are you binding dropdown in page_load event? If yes move that code in
if(!page.isPostback)
{
binddropdown();
}

Related

Clicking button with selenium doesn't throw exception but the button isn't actually clicking?

I am trying to click a button, which once clicked some text should appear. Selenium is not throwing any errors which means the buttons should have been clicked however the text is not appearing (it works manually).
<button class = "redButton one">
<img src = "images/name.png" class = redImage">
"Name"
</button>
I tried to click the button with the xpath: "//button[contains(text(), 'Name')]". I don't understand why the text is not appearing.
What is the expected text to be displayed after button click event? In order to help with this request, provide the HTML snippet of <button> before & after click event. Since this is working fine manually, did you try adding adequate wait time for the text to display?

Selenium VBA Unable to Click Checkbox

Using Selenium and Chrome, I'm attempting to check a box located within a table. The table contains 2 checkboxes but they act as radio buttons, in that if I click one, the other will uncheck.
I've tried a variety of methods, which include the following:
Const CHECKED_STATE As String = "Ag-icon ag-icon-checkbox-checked"
findElementByClassName("ag-selection-checkbox").fireEvent("CHECKED_STATE")
findElementbyXPath("//span[#class=ag-icon ag-icon-checkbox-checked'])[1]").Click
findElementbyXPath(".//div[#class='ag-body-container']").Click
I'm not sure how to click the checkbox when the HTML code doesn't even have a checkbox type or an Id.
The HTML reads:
<span class="ag-icon-checkbox">
<span class = "ag-icon ag-icon checkbox-checked ag-hidden">
<span class = "ag-icon ag-icon checkbox-unchecked">
<span class = "ag-icon ag-icon checkbox-undeterminate ag-hidden"></span>
When I click on the checkbox, the unchecked and hidden lines of HTML will flip. So I'm guessing it's some sort of event that I have to trigger.
The following, depending on the rest of the html, should work to select the unchecked item and thereby toggle off the other item. It targets the class checkbox-unchecked:
driver.FindElementByCss(".ag-icon-checkbox .checkbox-unchecked").click

VB.net webbrowser control click radio button

how to click the radio button for
<input name="years_option" value="all_years" type="radio">
the following code does not work. please help.
WebBrowser1.Document.GetElementById("years_option").SetAttribute("all_years", "radio")
at last got the answer from another source.
WebBrowser1.Document.GetElementById("years_option").SetAttribute("checked", True)

ASP.net VB Listbox

I've seen many questions around this one, but none hitting it directly.
I put a listbox on a page and populate it with three items from an Access database. I have a button on that page that will extract several values including the selected item from the listbox. Or I want to anyway.
I can see the item selected in windows (highlighted) when I click the button, but when I try to select it no item is available as selected in the listbox. The ListBox1.SelectedIndex is alway -1.
Here is the code from the page:
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem Text="List1" />
<asp:ListItem Text="List2" />
<asp:ListItem Text="List3" />
</asp:ListBox>
Is there a property missing?
Here is the code from the code behind page:
Public Function getDept() As String
Dim dept As String
If ListBox1.SelectedIndex > -1 Then
dept = ListBox1.SelectedItem.Text
Else
dept = "CMS"
End If
Return dept
End Function
Please help, I have until about noon to figure this out.
There may some reasons:
1- Check if your page's viewstate is true.
2- Call your method after Page_Load event.
Where do you call the function?
Consider that you should call it after Page_Load event. Also your viewstate

ASP.NET MVC 4 Passing data to the controller

I have a form, with a textbox and some radio buttons (Only 1 radio button can be selected at once) so I want to submit to the controller, the person name and the radio button select, that is value 1, 2 or 3 depending on the selection (1:Programmer, 2:Project Manager, 3:Analyst) but I do not know how to pass only the value of the radio button selected instead of the value of all them. how to get rid of this?
for example, it person name is David and the selected radio button is Programmer, I want to pass (David,1), if selected radio button is Project Manager (David, 2) and if selected radio button is Analyst (David, 3) to the controller.
#using (Html.BeginForm("AddPerson", "AddToDatabase", FormMethod.Get))
{
<div id="Radio">
#Html.TextBox("PersonName")
#Html.RadioButton("Programmer")
#Html.RadioButton("Project Manager")
#Html.RadioButton("Analyst")
</div>
<input type="submit" value="#Resource.ButtonTitleAddPerson" />
}
The controller signature is:
public bool AddPerson(string name, int charge)
Try to use #Html.RadioButton in other way:
#Html.RadioButton("Profession", "1") Programmer
#Html.RadioButton("Profession", "2") Project Manager
#Html.RadioButton("Profession", "3") Analyst
In your approach you receive three unconnected radio buttons with different id. And form thinks that they are different inputs and sends them all.