I am working on a simple web forms application with C# (Microsoft Visual C# 2010 Express).
I have two text boxes (textBox1, richTextBox1) a button (button1) and a web browser (webBrowser1) on the form. The web browser goes to a web page when I run the program. On that page there are two input fields that I want to autofill with the click of the button1 using the text in textBox1 and richTextBox1.
You can see the code of the input fields on that web page:
<input type="text" id="subject" tabindex="4" name="subject" value="">
<textarea class="composebody" tabindex="6" name="message" id="message" rows="20" cols="80"></textarea>
I know this is very simple, but I don't have much knowledge about C#. Any ideas how I can code that?
Thanks.
You need to write this code
webBrowser1.Document.GetElementById("subject").SetAttribute("value", subject.text);
webBrowser1.Document.GetElementById("msg").SetAttribute("value",message.text );
and need to call those two lines in
DocumentCompleted event of webbrowser.
Hope it helps.
I believe you are looking for the following:
subject.value = "Your info here";
This will solve the issue for your first item but the text area is a bit more tricky. You will probably need to include some HTML item inside the text area that you can write to. I was not able to find a good way to write to the textarea item easily. If possible, I would suggest using a different control.
Related
I have a form and cannot figure out how to automate the selection of a radio button.
The ID for the one which I need to click is "c100"
html code for the option I need to click:
<input id="cl00" type="radio" name="MYN" value="cl00">
c# code as follows:
driver.FindElement(By.Id("//input[#value='c100']")).Click();
Ive also tried:
IWebElement radio = driver.FindElement(By.Id("c100"));
radio.Click();
I have tried all the different ways including javascript. Can someone plase tell me what I am doing wrong?!
Change:
By.Id("//input[#value='c100']")
To:
By.Xpath("//input[#value='c100']")
Xpaths are useful for finding elements without displayed text or hidden elements.
Use http://www.w3schools.com/XPath/ for future reference.
Hope it helps!
I want to show up an OpenFileDialog box in my ASP .NET web application. I am writing in c#. I want to create a user account with an image so I need to select image from my computer and save it into a database. How can I implement it.
You can do that using
<input type="file" id="fileLoader" name="files" title="Load File" ...
The usual trick is to make it invisible, and on clicking some visible artifact (styled link, image, button... whatever) simulate a click on fileLoader:
$("#fileLoader").click();
You cannot. OpenFileDialog is something for desktop applications.
you cannot use that Windows Forms class in ASP.NET, you should use the FileUpload class/control.
Or see other alternatives: Uploading Files in ASP.net without using the FileUpload server control
Almost the same as Tigran's above but I found I needed to change the JavaScript slightly to use getElementById("...") to identify the button to click(). If I just did this in HTML/CSS Tigran's code worked fine but when I used it within an .aspx file I required the change.
.aspx
<input type="file" id="fileLoader" name="files" title="Load File" />
<asp:Button ID="LoginButton" runat="server" Text="ASP click Me" onclientclick="openfileDialog()" />
JavaScript
function openfileDialog() {
document.getElementById("fileLoader").click();
}
css
#fileLoader{
display:none;}
Imagine a web site, where there are 2 drop down controls like min age and max age. After I choose min age and max age, I would like to hit the search button. How do I get the search results into an output stream and then I could navigate the DOM HTML. I already know how to naviate through dom html via htmlagilitypack. I just do not know how to invoke the drop down make selections and invoke search button. I want to do all this from console application. Is it even possible? I am using C# visual studio 2010.
Thanks..
If the html looks like this:
<form action="someurl">
<select name="SomeOption">
<option value="val1">val1</option>
<option value="val2">val2</option>
</select>
</form>
And you want to submit the form with "val1", then you need to execute an HTTP POST operation to "someurl" including the argument SomeOption=val1. That is essentially what the browser is doing. Of course the form you are trying to simulate will be a bit more complicated.
Is that what you were asking?
BTW, if you want to see exactly what is going on when the browser submits the form, check out Fiddler, an excellent tool made by a colleague at Microsoft.
I dont know whether this simple task or not, but I tried to search in google but couldn't find anything.
I've a asp.net form and user enters some data in the text boxes provided. Whenever user submits the form, browser will save that form data. I don't want this form data to be saved in browser. How can I restrict the browser saving this form data without touching the browser settings?
Application is developed using asp.net and normal text boxes are used here.
I'm guessing you mean you want the browser to stop remembering values entered, i.e. the browser's autocomplete?
<input type="text" name="text1" autocomplete="off">
Or this will work in FF and IE, but it's not XHTML standard:
<form name="form1" id="form1" autocomplete="off" />
Note that autocomplete is only defined in the HTML 5 standards, so it will break any validations you run against HTML 4.
If not, on PostBack, just clear the inputs:
TextBox.Text = string.Empty;
If you're meaning an asp:TextBox with "[...]normal text boxes[...]", then the control's ControlState is responsible for saving the entered value. Unfortunately, you can't disable the ControlState (MSDN).
I have a textbox as follows:
<asp:TextBox runat="server" ID="txtOtherApps" Height="400" Width="400"
TextMode="MultiLine" ontextchanged="txtOtherApps_TextChanged" ></asp:TextBox>
How to display link in this textbox?
The TextBox allows you to display text which the user can edit. It does not allow you to display anything but plain text. To display a URL in the TextBox, simply set its Text property:
txtOtherApps.Text = "http://www.example.com/";
It wont, however, be a "link". Clicking the URL will cause a text cursor to be placed, allowing for the user to edit the URL.
It is possible if you use JavaScript
Use JavaScript on your text element - such that:
<input type="text" name="t1" id="t1" value="http://www.google.com" onmouseover="this.style.cursor='pointer' ;" onClick="window.open(this.value);"/>
Only Java script can do what you are asking for.
You won't be able to click on the link, but you can just set the Text property of the TextBox to the URL.
ASP.NET will render TextBoxes as textareas (in your case, because it's multiline) or inputs. These are standard HTML fragments which are just plain text containers. You can style them, but you can't really linkify the contents of them.
If you really just want to put the text of a link into a box, do this:
// either from the server:
txtOtherApps.Text = YourLinkString;
// or from the client:
<script>
document.getElementById('<%=txtOtherApps.ClientID%>').value = YourJsLinkValue;
</script>
If you want something to happen with the user clicks on the text area, you can add an onclick handler to it...but this would be weird.
You will need a RichTextBox. The .NET one is not available for web applications, but there are a few third party solutions available.
http://www.richtextbox.com/ is one of them, you will have to see for yourself if there is any available that suits your needs better.