Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My task: In a website(my university website) when results are generated using my c#(windows or web application) code automatically the roll number's will be incremented and results will be stored in my database.i need to supply values for a textbox in the university website from my code.,im ABLE to find the html input tag name(regno) for the textbox.,the problem is,the HTML page is using onSubmit event with return valuesonSubmit="return checkregno();"(to validate the roll no entered in the textbox) and it is redirected to another page(the output results page).How to do i supply values to the onSubmit method (from my C# code)such that it returns "true"and i should be able to retireve the values from the output page also.pls help,i dont know where to start,or how to start.
JavaScript
<SCRIPT language=JavaScript>
  <!--
    function checkregno()
       {
        if (window.RegExp)
        {
          strval=document.forms["result"]["regno"].value;
          reExp=new RegExp("^\\d{14}$");
        }
     function dele()
        {
          document.result.action="http://www.annauniv.edu";
          document.result.submit();
        }
       //-->
     </SCRIPT>

HTML
          <META content="MSHTML 6.00.2800.1491" name=GENERATOR></HEAD>
          <BODY text=#000000 bgColor=gray 
           önload="javascript:document.forms['result']['regno'].focus()">
          <FORM name=result  önSubmit="return checkregno();" action=/cgi-bin/result/resgrbarchpg.pl method=post>
          <INPUT maxLength=14 size=14 name=regno>
           <INPUT  önClick="return checkregno();" type=submit value=Submit> 
<INPUT type=reset value=Clear name=clear>


now how do i send data to the onSubmit function from my code,im not an expert in .net.

the code i use to retrieve the page source is:
C#
static string GetHtmlPage(string strURL)
{

    String strResult;
    WebResponse objResponse;
    WebRequest objRequest = HttpWebRequest.Create(strURL);
    objResponse = objRequest.GetResponse();
    using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
    {
        strResult = sr.ReadToEnd();
        sr.Close();
    }
    return strResult;
}
protected void Button1_Click(object sender, EventArgs e)
{
    string tablecode = null;
    String TheUrl = "http://www.annauniv.edu/1234566789/grbarchpg.html?regno=23010205001";
    string response = GetHtmlPage(TheUrl);
    tablecode = response;

    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
    doc.LoadHtml(@tablecode);
   // http://www.annauniv.edu/1234566789/grbarchpg.html
    TextBox1.Text = tablecode;
}
Posted
v7
Comments
Mahesh Bailwal 19-Aug-13 7:54am    
Can you post your code snippet you are using for accessing this web page.
sundaram meenakshi 19-Aug-13 8:02am    
@Mahesh Bailwal,i have updated the question :)

1 solution

When sending data to a website that uses an HTML form, you need to do an HTTP POST to the URL in the action attribute of the HTML form element. You are using the HTTP GET in your current code that calls the page initially, now you need to do the POST to send the form data.


HttpWebRequest/Response in a Nutshell - Part 1[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900