[英]How to execute code when webpage navigate from one page to another in C#
private void button1_Click(object sender, EventArgs e)
{
HtmlDocument doc = webBrowser1.Document;
HtmlElement from = doc.GetElementById("fromStation");
HtmlElement to = doc.GetElementById("toStation");
HtmlElement d = doc.GetElementById("journeyDateInputDate");
HtmlElement s = doc.GetElementById("ticketType");
HtmlElement ticket = doc.GetElementById("ticketType");
HtmlElement submit = doc.GetElementById("jpsubmit");
HtmlElement hcab = doc.GetElementById("handicapPassengers");
from.SetAttribute("value", textBox3.Text);
to.SetAttribute("value", textBox4.Text);
d.SetAttribute("value", textBox5.Text);
ticket.SetAttribute("value", Properties.Settings.Default["ticket"].ToString());
string com = "true";
if (Properties.Settings.Default["check"].ToString() == com)
hcab.InvokeMember("click");
submit.InvokeMember("click");
}
I am making project on c# where i have to execute code when webpage navigate from one page to another and when web load completely. 我在c#上制作项目,当网页从一个页面导航到另一页面并且完全加载网页时,我必须执行代码。 I have used button to execute a code when webpage completely loads....but now i what it to execute without using button
我已使用按钮在网页完全加载时执行代码。...但是现在我不使用按钮即可执行的代码
To provide a substantial and correct answer, you might want to provide more specifics on the environment. 要提供实质性和正确的答案,您可能需要提供有关环境的更多详细信息。 But assuming a whole bunch of details, I'm making an (un)educated guess here.
但是假设有很多细节,我在这里做一个(未受过教育的)猜测。
If it's MVC project, you can execute the code as you're presenting the next view. 如果是MVC项目,则可以在呈现下一个视图时执行代码。 If the page is navigated to from JS (which is on the client) or simply navigated away from your site, it might be much more tricky.
如果页面是从JS(位于客户端)上导航到的,或者只是从您的站点导航而来,则可能会更加棘手。
In any case, since it's an operation on the client, you'll need to manage that from JS on the client . 无论如何,由于它是在客户端上执行的操作,因此您需要通过client上的 JS管理该操作。 The server has let the contents go and the page is viewed in the browser even of the server goes down.
服务器放走了内容,即使服务器掉线了,也可以在浏览器中查看页面。
$(function(){
alert("Page loaded.");
// do other stuff
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.