ByulTaeng
ByulTaeng

Reputation: 1269

Simulate form submit with VB.NET

I wonder if I can simulate the action of the button

alt text
(source: xonefm.com)

in this website by VB.NET code ?

http://www2.xonefm.com/hot10/index_in.aspx

Upvotes: 0

Views: 1857

Answers (2)

Joel Coehoorn
Joel Coehoorn

Reputation: 415735

Is this your web site? If so, you can probably just call the click event for the button directly (assuming it causes a postback).

Are you scraping someone else's site? In that case, use a System.Net.WebClient or System.Net.HttpWebRequest object to send a similar request to the server that the browser would send if you click the button. There are two ways to find out what the request will be:

  • Study the source of the page in question until you understand what http request is sent when you click the button. This can be especially tricky for asp.net sites because of the hidden ViewState field.
  • Use something like WireShark to sniff the packet sent and work backwards from that.

Upvotes: 1

almog.ori
almog.ori

Reputation: 7889

From server code you could use ClientScriptManager.GetPostBackEventReference which renders out a postback event reference heres a link on msdn http://msdn.microsoft.com/en-us/library/system.web.ui.page.getpostbackeventreference.aspx

heres a sample

Allows selecting gridview row without select column.

protected override void Render(HtmlTextWriter writer)
{
GridView g = GridView1;
foreach (GridViewRow r in g.Rows)
{

if(DataControlRowType.DataRow == r.RowType)
{
r.Attributes["onMouseOver"] = "this.style.cursor='pointer';this.style.cursor='hand'";
r.Attributes["OnClick"] = ClientScript.GetPostBackEventReference(g, "Select$" + r.RowIndex, true);
}
}

base.Render(writer);
}

Upvotes: 1

Related Questions