title: c# send post data with javascript field
body: <p>I have such code binded on my button</p>
  
  <pre><code>private String readHtmlPage2(string url)
          {
  
              //setup some variables
  
              String country = "6";
              String city = "95";
              String lang = "17";
              String wtf = "ctl00$tresc$upPlacowka|ctl00$tresc$cbListaPlacowek";
  
              //setup some variables end
  
              String result = "";
              String strPost = "ctl00$tresc$cbListaKrajow=" + country + "&amp;ctl00$tresc$cbListaPlacowek=" + city + "&amp;ctl00$ddlWersjeJezykowe=" + lang + "&amp;ctl00$tresc$ScriptManager1" + wtf;
              StreamWriter myWriter = null;
  
              HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
              objRequest.Method = "POST";
              objRequest.ContentLength = strPost.Length;
              objRequest.ContentType = "application/x-www-form-urlencoded";
  
              try
              {
                  myWriter = new StreamWriter(objRequest.GetRequestStream());
                  myWriter.Write(strPost);
              }
              catch (Exception e)
              {
                  return e.Message;
              }
              finally
              {
                  myWriter.Close();
              }
  
              HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
              using (StreamReader sr =
                 new StreamReader(objResponse.GetResponseStream()))
              {
                  result = sr.ReadToEnd();
  
                  // Close and clean up the StreamReader
                  sr.Close();
              }
              return result;
          }
  
          public static string PostData(string file, string data)
          {
              HttpWebRequest request = (HttpWebRequest)WebRequest.Create(file);
              request.Method = "POST";
              request.AllowAutoRedirect = true;
              request.ContentType = "application/x-www-form-urlencoded";
              byte[] EncodedPostParams = Encoding.UTF8.GetBytes(data);
              request.ContentLength = EncodedPostParams.Length;
              request.GetRequestStream().Write(EncodedPostParams,
                                               0,
                                               EncodedPostParams.Length);
              request.GetRequestStream().Close();
              HttpWebResponse response = (HttpWebResponse)request.GetResponse();
              string html = new StreamReader(response.GetResponseStream(),
                                             Encoding.UTF8).ReadToEnd();
              return html;
          }
  </code></pre>
  
  <p>I need to send post data on our page, but main trouble is that form is dynamic, some field look's like this:</p>
  
  <pre><code>&lt;select name="ctl00$tresc$cbListaKrajow" onchange="javascript:setTimeout('__doPostBack(\'ctl00$tresc$cbListaKrajow\',\'\')', 0)" id="ctl00_tresc_cbListaKrajow" style="width:400px;"&gt;
      &lt;option value="-1"&gt;&lt;/option&gt;
      &lt;option selected="selected" value="6"&gt;Białoruś&lt;/option&gt;
  
  &lt;/select&gt;
  </code></pre>
  
  <p>I need to tell my code that it must select this field, that it gives all values... All form you can see on our page: <a href="https://by.e-konsulat.gov.pl/default.aspx" rel="nofollow">https://by.e-konsulat.gov.pl/default.aspx</a></p>
  
  <p>I send my data, but nothing happens... how to submit this form? (then i will be redirected)</p>