Pasting text into web browser C# - c#

I would like to paste some text into a web browser element. For example:
private void pasteBtn_Click(object sender, EventArgs e){
WebBrowser1.PasteString("some text");
}
PasteString() Clearly doesnt exist but you get what i mean.
I have just tried pasting the string outright with a button, but the browser loses focues before it pastes.
I have tried many thing but none of them work.
Anything would help, i just wanna paste a string into a textbox on a website with a button, or something alike.

I think you need something like this:
N.B. not tested
private void pasteBtn_Click(object sender, EventArgs e){
var elemWithFocus = WebBrowser1.Document.ActiveElement;
elemWithFocus.SetAttribute("value", theStringToPaste);
}

Related

How to load string in textbox when form loads?

I'm trying to load a string in my textbox when my form loads. Somehow nothing appears. Can somebody explain to me why this is so?
private void Form1_Load(object sender, EventArgs e)
{
string TestText = "hello";
FolderLocation.Text = TestText;
}
I followed pstrjds 's prompt to create a Minimal, Complete and Verifiable example. Turns out I had an error in another part of the code that somehow led to the textbox unable to load any texts. Thanks a lot.

How to add an event on a menu in C# project?

I have a C# Windows Forms App that contain a menu bar.
I want to display a Help Message when I press on the "HELP" menu button.
All that I can see when I press view code is this:
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
}
I think that I need to create inside the function a MessageBox or an event that will display the desired message.
Do you have any idea how should I do this, please?
Below should work for what your asking. If you are on your form you can double click the button you want to interact with, and Visual Studio should take you to the empty method.
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("This is supposed to be helpful");
}

ASP.NET Change the current webform

I am working at a problem in ASP.NET.
I have to create 2 windows (i think that I need to make web forms, i don't know why they said windows) one is the login form, when i press ok and the username and password is ok, I need to
show my second window (webform)
How can I do that?
I tried to do
protected void Button1_Click(object sender, EventArgs e)
{
Form2 form = new Form2();
form.SetFocus("id");
}
But it gives me error
A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.
What should I do?
Am i right, I have to do separate webforms for thoose windows?
This is the picture from the problem that they provided
If you use webforms you can just use the following code to redirect to second form:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Webform2.aspx");
}

How to get the text value of PhoneTextBox control

I am asking for a user to type in what he or she would like to search for, and then I would like to pass this value to another page where the search will be performed and the results will be given. I am using a PhoneTextBox control from the WP Toolkit. On the KeyUp or ActionIconTapped event I would like to get the value entered in the PhonTextBox and pass that to my search page, although I cannot figure out how to get the text value entered?
MainPage.xaml
<toolkit:PhoneTextBox x:Name="publicSearchTextBox" HorizontalAlignment="Stretch" Margin="-10,0,12,0"
Hint="search for topic or name"
ActionIcon="/Resources/Images/search.png"
ActionIconTapped="publicSearchTextBox_ActionIconTapped"
KeyUp="publicSearchTextBox_KeyUp"/>
MainPage.xaml.cs
..get publicSearchTextBox text value and pass this to the search page?
For some reason, I cannot reference the PhoneTextBox in my code behind from setting x:Name="publicSearchTextBox" in my xaml? How is this possible?
Perhaps you have a typo because i made some handlers for the XAML you have above and it works fine for me. Copy paste the following in the code behind and try?
private void PrintTextboxValue()
{
Debug.WriteLine("Value: {0}", publicSearchTextBox.Text);
}
private void publicSearchTextBox_ActionIconTapped(object sender, EventArgs e)
{
PrintTextboxValue();
}
private void publicSearchTextBox_KeyUp(object sender, KeyEventArgs e)
{
PrintTextboxValue();
}
If it does not work then please update your question with more information such as, where you are referencing the PhoneTextBox.

I TRIED but InvokeMember Click is NOT working on the INPUT BUTTON, it's very different from the others

I wanted button9 to automatically click an input button in the html page using webbrowser1.
This is the code of the input button below. I got this from the page source.
<input type="image" name="phmiddle_0$ShoppingCartOrderSummary1$btnCheckout"
id="phmiddle_0_ShoppingCartOrderSummary1_btnCheckout" title="Checkout"
src="/content/images/global/buttons/checkout.gif" onclick="return
GMCR.CheckoutValidation();" style="border-width:0px;">
So this is the code I used below to click it.
private void button9_Click(object sender, EventArgs e)
{
webBrowser1.Document.GetElementById("phmiddle_0$ShoppingCartOrderSummary1$btnCheckout").InvokeMember("Click");
}
And I also tried this
private void button9_Click(object sender, EventArgs e)
{
webBrowser1.Document.GetElementById("phmiddle_0_ShoppingCartOrderSummary1_btnCheckout").InvokeMember("Click");
}
None of those two worked.
I also tried some other very long codes out there that contain var and htmlelement tags but none of them worked.
Please help me, what am I doing wrong here.
I clicked button9, but it does not automatically click the input button.
I FOUND THE ANSWER ALL I HAVE TO DO IS ADD THIS webBrowser1.Document.GetElementById("phmiddle_0_ShoppingCartOrderSummary1_btnChe‌​ckout").RaiseEvent("onclick");

Categories

Resources