Home > Enterprise >  how do I make an ajax request to an asp net webform?
how do I make an ajax request to an asp net webform?

Time:12-28

I am on a website and it has this when getting the data it uses a find button:

<input type="submit" name="ctl00$MainContent$btnSearch" value="Find" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$MainContent$btnSearch&quot;, &quot;&quot;, true, &quot;chkNumbers&quot;, &quot;&quot;, false, false))" id="ctl00_MainContent_btnSearch" >

is there anyway I can send a ajax request using python?

Currently I am using selenium to complete the task but it is very slow.

CodePudding user response:

No,you can't. If that web page has some so called webmethods, then yes you can.

However, we can't see the orginal butotn code, you only seeing the result of the button click that is pre-procssed by the .net frame work and spits out that button.

A ajax call to a asp.net web page will ONLY work if the web page has a API and web methods setup. And when you have such a web form with web methods, then standard button clicks for code behind to run can't work. Remember, code behind is either c#, or vb.net, along with code values, session, and USE OF ALL controls on the web page.

When you make a ajax call to the server, such methods are (in general) to be considered "static" page methods. That means the code behind variables, and use of controls will not work, since the WHOLE web page will not have been posted back to the server.

on a button click, the WHOLE page travels back up to the server, the page class is created, and THEN the code behind for that button click runs. That button click will often (if not near always) want to use controls on the web page. If that web page NOT been posted back to the server, then use of those controls, and even just "in general" code behind variables etc. will not exist.

So, unless that web page has specific web methods setup (often pages do), then you can certainly call/use/consume such web methods with a ajax call to the server.

however, any plane jane button click on a page? No, they will not work, since that button code going to assume that the WHOLE page been posted back to the server, and thus the code behind can directly operate on the controls and their values (and in most cases update controls on the page). once all that code behind runs, then the WHOLE page is sent back to the browser, and re-loaded. This even means any js code on that page will re-load, and re-start running.

Looking at some button click on a aspx page, without the context of the c#/vb.net code behind is of little use, and such button click events requires the WHOLE page to be sent to the server, thus allowing that button code to operate against the copy of the "dom" that is now up on the server.

  • Related