I used to write winforms and now I am trying to port some of my apps to web interface, but my apps seems to be not working, althought the code in my class did not change.
I have never done web development, so I am wondering if this is something what I am not doing right?
I use this code in my runEbay.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="runEbay.aspx.cs" Inherits="eBay_Item_Scanner.runEbay" %>
<div>
Home | <a href="runEbay.aspx">Run Full eBay Scan WARNING!!!!!!!
</a>
</div>
<%
string MAINPN = Request["MAINPN"] != null ? Request["MAINPN"] : "";
string EBAYCATEGORYTOSCAN = Request["EBAYCATEGORYTOSCAN"] != null ? Request["EBAYCATEGORYTOSCAN"] : "";
Response.Write("<br>MAINPN: " + MAINPN);
Response.Write("<br>EBAYCATEGORYTOSCAN: " + EBAYCATEGORYTOSCAN);
//create instance of class Program
eBay_Item_Scanner.Program eb = new eBay_Item_Scanner.Program();
if (SUBPN.Length > 0)
{
String query = #"my query using some request parameters";
//call functions from another class
eb.getEbay_com_API(query, EBAYCATEGORYTOSCAN);
}
Response.Write("<br><br>Scanning is done");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
OK; the problem was that my functions were too big and they timed out the IIS. I removed the timeout and that solved the problem.
Related
I am trying to add a Javascript to all my pages in the Site. So, I created a base Page and Most of the Pages on the site are inherited from this Page using the <#Reference tag. Here's a Sample of my Base Page
<%# Page Language="C#" CodeBehind="BasePage.aspx.cs" Inherits="MyProj.BasePage" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body ID="BasePage_Body" runat="server">
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
In basepage.aspx.cs I am using this as follows..
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
//Adding this Client Side script for my Page
if (<someCondition>)
{
BasePage_Body.Attributes.Add("onunload", "HandleClose()");
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "MWGBrowserhandlingClose",
"<script language=\"JavaScript\">" +
"function HandleClose() {" +
"alert(\"Killing the session on the server!!\");" +
"PageMethods.AbandonSession();" +
"} </script>");
}
}
But I get Nullreference Exception for BasePage_Body Any inputs on why is this and how to resolve.
Thanks in advance
I want use variables from inherits in asp code
My code looks like that
namespace WebApplication2
{
public class Global : System.Web.HttpApplication
{
public bool abcdef = true; // my variable that i want to use in my asp code
...
}
}
ASP part looks like below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<%
if(webapplication1.main.abcdef) //this is incorrect, i want to correct that
{%>
my first web page
<%}
else
{%>
my second web page
<%} %>
</html>
How can I use my variable abcdef in my asp code?
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" MasterPageFile="MasterPage.Master"
Inherits="Namespace.YouClass" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script>
if(<%#this.abcdef%>)
{
//do your work
}
</script>
i'm using asp.net web form fx3.5 and i'm trying to get my server-side string array into my javascript. i found a simple example that claims to work but it doesn't for me. temp variable is not recognized in ().Serialize(temp);
Here's the reference article
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ShelterExpress.UserInterface.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="c#">
string[] temp;
int lengthOfTemp;
public string tempJSON = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(temp);
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
<script runat="server" language="c#">
string[] temp;
int lengthOfTemp;
public string tempJSON;
protected override void OnLoad(EventArgs e)//you have to initialize your temp and tempJSON in a method
{
base.OnLoad(e);
temp = new string[] { "Hi", ",", "ojlovecd" };//Initialize your temp here
tempJSON = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(temp);
}
</script>
How to trigger onclick event after received return value from popup aspx which using add attribute a javascript?
After adding
.Attributes.Add("onClick", "return popWin('" + NewBatchNo_TextBox.Text + "');");
Original onclick event do not fire?
if this method can not work, any other method to get value from pop up message box and return value and run click event
Thanks.
try this
Main.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Main.aspx.cs" Inherits="Main" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type='text/javascript'>
function DoStuff() {
document.getElementById('Button1').click();
}
function popWin() {
var popy = window.open('popup.aspx', 'popup_form', 'menubar=no,status=no,top=100%,left=100;')
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtPopupValue" runat="server" Width="327px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Show List" />
</div>
</form>
</body>
</html>
Main.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Main : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.Button1.Attributes.Add("onclick", "return popWin()");
}
}
}
popup.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFile="popup.aspx.cs" Inherits="popup" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type='text/javascript'>
function validepopupform() {
window.opener.document.getElementById('txtPopupValue').value = document.getElementById('txtPop').value
self.close();
}
window.onbeforeunload = CloseEvent;
function CloseEvent() {
if (window.opener && !window.opener.closed) {
window.opener.DoStuff();
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtPop" runat="server"></asp:TextBox>
<input type='button' value='go' onclick='validepopupform()' />
</div>
</form>
</body>
</html>
The same problem I faced several times the cause is that java script cannot call code behind(c#/vb function/events).
An alternate way I used is to use hidden fields that is accessible by both java script and code behind. But then you want to call events not read values modified by java script.
For this we refreshed the page through java script when we want to trigger that code behind event and let the page load to monitor the scenario(value that java script set) and triggers the required event.
The code at the end would be real mess and unmanageable, would take lots of efforts to debug.
Technology Used:- Asp.Net 2.0
Code:- See Below
Description:- hello code given below is working fine in i.e. and other but not working in all mozila version.javascript is simple to devide two textbox's value. you can easily understand.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="javascript_test.aspx.cs" Inherits="javascript_test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<script type ="text/jscript">
var _txtamount;
var _txtins;
var _txtinsamount;
function test()
{
var temp;
_txtamount = document.getElementById("txtamount");
_txtins = document.getElementById("txtins");
_txtinsamount = document.getElementById("txtinsamount");
if (_txtinsamount.value !='')
{
temp = parseFloat(_txtamount.value) / parseFloat(_txtinsamount.value);
}
else
{
temp = 0
}
_txtins.value = temp;
}
</script>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="myform" runat="server" name="myform">
<div>
<asp:TextBox ID="txtamount" runat="server" ></asp:TextBox>
<asp:TextBox ID="txtinsamount" runat="server" onblur="test();"></asp:TextBox>
<asp:TextBox ID="txtins" runat="server"></asp:TextBox></div>
</form>
</body>
</html>
You're using text/jscript as the <script> type. Use text/javascript instead:
<script type ="text/javascript">
JScript is Microsoft's own version of ECMAScript -- no wonder it works on IE.
Your <script> tag needs to be wrapped in the <head> element or in the <body> element; it can't just be a direct child of <html>.
[edit]more important is your "type" value, as the other answer here mentions.