Note that there are some explanatory texts on larger screens.

plurals
  1. POusing functions in code behind on webpage
    primarykey
    data
    text
    <p>Disclaimer: I'm pretty new to ASP.NET, so I'm figuring it out as I go along.</p> <p>I'm trying to output the results of a function in my code behind page on the webpage itself.</p> <p>Example:</p> <p>Code Behind:</p> <pre><code>public string POSTResult(string e) { ... return TheResult; } </code></pre> <p>ASPX Page:</p> <pre><code>Output is: &lt;%=POSTResult("argument")%&gt; </code></pre> <p>However, loading the page errors, saying "The name 'POSTResult' does not exist in the current context."</p> <p>I'm apparently doing something a bit off with how I'm getting to the code behind page from the ASPX page. My ASPX page has this at the top:</p> <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/master/default.Master" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="Bitfork.login" %&gt; </code></pre> <p>The listed CodeBehind value is the name of the code behind page.</p> <p>ETA:</p> <p>Contents of my code behind (login.aspx.cs):</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; using System.IO; namespace Bitfork.master { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } public string POSTResult(string e) { // variables to store parameter values string url = "https://accounts.google.com/o/oauth2/token"; // creates the post data for the POST request string postData = (e); // create the POST request HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.ContentLength = postData.Length; // POST the data using (StreamWriter requestWriter2 = new StreamWriter(webRequest.GetRequestStream())) { requestWriter2.Write(postData); } // This actually does the request and gets the response back HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse(); string responseData = string.Empty; using (StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream())) { // dumps the HTML from the response into a string variable responseData = responseReader.ReadToEnd(); } return responseData; } } } </code></pre> <p>Example of argument being passed, with API secret keys redacted:</p> <pre><code>code=[redacted]&amp;client_id=[redacted]&amp;client_secret=[redacted]&amp;redirect_uri=http://localhost:60284/login.aspx&amp;grant_type=authorization_code </code></pre> <p>ETA2:</p> <p>I don't know if it's related, but it seems like my code behind page and my webpage are not communicating with each other at all. For instance, I can't access DIVs by ID in my code behind page to change their contents.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload