Pass string from C# Code Behind Winforms application to a webpage textbox

274 Views Asked by At

I am trying to pass a string from a C# Winforms application to a webpage text box.

The Webpage textbox looks like this:

 <input id ="sometext" class = "form-control-sometext clearable"
        placholder = "Enter Infor Here" type = "text" name = "moreText">

I have tried several methods such as the following:

//string v = textBoxAutoV.Text;
//string getPage = "http://www.TheWebsite.com?moreText = v;

The information is needed to process an information request and return a string value. I would like to see a code sample if possible. Thank you.

3

There are 3 best solutions below

0
On

First, let me thank you all. I do not think that I explained it properly, which happens when you are trying not to reveal private information. First, the page that is 'sending' the data is not mypage.ascx ... it is mypage.cs (Winforms, not a web page). Second, the website is not mine. It is a resource. But because it is public, let me lift the veil off it. I am trying to use a site called (www.decodethis.com). It is totally legitimate to use it, but many of my customers that use the site by reference make mistakes when transferring the 17 digit VIN number to the site manually. My idea was to have them enter the information inside the application that I wrote and have it passed to the 'decodthis' page to have it processed and get a result. I am not sure that it is even possible to do this, but since it should not matter to the site owner whether the number to be decoded was entered manually or automatically, it seemed to make sense to do it this way. If it would help. I could make a webpage on my end and then use aspx.cscode to accomplish the same thing if that would work. But I prefer to use the actual application if possible. With that said, all the information about the web text box is visible using the element examination feature. SO ... perhaps using the real-life naming ... could you please suggest a way to accomplish this task (if it can be done at all?). All I want to do is pass the information from the desktop application (main.cs) to the webpage (www.decodethis.com) automatically. Thank you (ALL) again!

0
On

You should try the following way:

protected void Page_Load(object sender, EventArgs e)
{
        // Store a value in the Session
        Session["moreText"] = "This is an example";
}



<input id ="sometext" class = "form-control-sometext clearable"
    placholder = "Enter Infor Here" type = "text" name = "moreText" value=@(Session["moreText"])>
0
On

First off, you will need to use an ASP.NET WebForms text box control, if you want to do it the proper way. Here's an example with that:

Here's my code (in mypage.ascx):

<asp:TextBox id ="sometext" class = "form-control-sometext clearable"
       placeholder = "Enter Infor Here" type = "text" name = "moreText" runat="server"></asp:TextBox>

And in the code behind (in mypage.ascx.cs):

/// <inheritdoc cref="UserControl.OnInit" />
protected override void OnInit(EventArgs e) {
    base.OnInit(e);

    sometext.Text = "mytext";