使用c#为网页的onSubmit()函数提供值 [英] supply values to onSubmit() function of a webpage using c#

查看:63
本文介绍了使用c#为网页的onSubmit()函数提供值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务:在网站(我的大学网站)中,当使用我的c#(windows或web应用程序)代码自动生成结果时,滚动编号将增加,结果将存储在我的数据库中。我需要提供值我的代码在大学网站上的一个文本框。我可以找到文本框的html输入标记名称(regno)。问题是,HTML页面正在使用onSubmit事件,返回值为@Submit =return checkregno(); (以验证在文本框中输入的滚动没有)并将其重定向到另一个页面(输出结果页面)。如何为onSubmit方法(来自我的C#代码)提供值,使其返回true并且我应该能够从输出页面中退出值。也可以帮助,我不知道从哪里开始,或者如何开始。

< SCRIPT language = JavaScript> ; 
<! -
function checkregno()
{
if window RegExp
{
strval = < span class =code-sdkkeyword> document .forms [ result] [ regno]。value;
reExp = new RegExp ^ \\d {14} $);
}
function dele()
{
document .result.action = http://www.annauniv.edu;
document .result.submit();
}
// - >
< / SCRIPT >



 <   META     content   =  MSHTML 6.00.2800.1491    name   =   GENERATOR  >  <   / HEAD  >  
< BODY text = #000000 bgColor = 灰色

önload = javascript:document.forms ['result'] ['regno']。focus() >
< FORM name = 结果 önSubmit = return checkregno(); action = / cgi-bin / result / resgrbarchpg.pl 方法 = 发布 >
< INPUT maxLength = 14 size = 14 名称 = regno >
< < span class =code-leadattribute> INPUT önClick = return checkregno(); 类型 = 提交 value = 提交 >
< INPUT type = reset value = 清除 名称 = clear >





现在如何从我的代码发送数据到onSubmit函数,我不是.net的专家。



我用来检索页面源的代码是:

  static   string  GetHtmlPage(< span class =code-keyword> string  strURL)
{

String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
使用(StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}
受保护 void Button1_Click( object sender,EventArgs e)
{
string tablecode = null ;
字符串 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;
}

解决方案

);
}
function dele()
{
document .result.action = http://www.annauniv.edu;
document .result.submit();
}
// - >
< / SCRIPT >



 <   META     content   =  MSHTML 6.00.2800.1491   名称  =   GENERATOR  >  <   / HEAD  >  
< BODY text = #000000 bgColor = 灰色

< span class =code-attribute>önload = javascript:document.forms ['result'] ['regno']。focus() >
< FORM name = 结果 önSubmit = return checkregno(); action = / cgi-bin / result / resgrbarchpg.pl 方法 = 发布 >
< INPUT maxLength = 14 size = 14 name = regno >
< INPUT önClick = return checkregno(); type = 提交 value = 提交 >
< INPUT type = 重置 = 清除 名称 = 清除 >





现在如何从我的代码发送数据到onSubmit函数,我不是.net的专家。



我用来检索页面源的代码是:

  static   string  GetHtmlPage( string  strURL)
{

String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
使用(StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}
受保护 void Button1_Click( object sender,EventArgs e)
{
string tablecode = null ;
字符串 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;
}


将数据发送到使用HTML表单的网站时,需要在action属性中对URL进行HTTP POST。 HTML表单元素。您在最初调用页面的当前代码中使用HTTP GET,现在需要执行POST以发送表单数据。





HutspWebRequest / Nutshell中的响应 - 第1部分 [ ^

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.

<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>


          <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:

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;
}

解决方案

"); } function dele() { document.result.action="http://www.annauniv.edu"; document.result.submit(); } //--> </SCRIPT>


          <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:

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;
}


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[^]


这篇关于使用c#为网页的onSubmit()函数提供值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆