This question is an exact duplicate of:

protected void Page_Load(object sender, EventArgs e)
{
    TextBox1.Text = Request.Form["tbContractNo"];  
    TextBox2.Text = (TextBox1.Text).Length.ToString();
}
    protected void Button1_Click(object sender, EventArgs e)
{        
    string result = "";
    result = (TextBox1.Text).Substring(4, 1);

try
    {

    }
    catch
    {
    }
    finally
    {

        if (result == "H")
        {
            HiddenField2.Value = TextBox1.Text ; 
            Server.Transfer("~/LtssEnrollment-HCS.aspx", true);
        }
        else
        {
            if (result == "I")
            {
                Server.Transfer("~/LtssEnrollment-ICF.aspx", true);
            }
        }
    }
}

Textbox1 shows "0000H07C7". Textbox2 show 9 - the number of digits. Get startIndex cannot be larger than length of string.

  Parameter name: startIndex

 Source Error: 


Line 43:         //string alpha2 = alpha.ToString();
Line 44:         string result = "";  
Line 45:         result = (TextBox1.Text).Substring(4, 1);  
Line 46: 
Line 47:     try

Stack Trace: 

What is going on? Is the value of TextBox1 losing its value on button click??

I am new to the .net framework and web technologies in general!

I have an aspx page that when I call from the network with a browser does something, and I'm modifying that page and adding some additional features.

I want my button in my .aspx file to call a function in my .cs file (NOT USING Visual Studio just Notepad++). I know using

<@ Page codeFile="myCode.cs" inherits="myClass"> 

works! I have tried it.

But the problem is that I have different classes whose instances are declared in myCode.cs and I know using:

<@ Assembly src="myfile1.cs">
<@ Assembly src="myfile2.cs">
<@ Assembly src="myfile3.cs">
<@ Assembly src="myfile4.cs">

Works!!!!

THE PROBLEM IS THAT! The code behind file ("myCode.cs") sees the classes and namespace in myfile1.cs, myfile2.cs, myfile3.cs, myfile4.cs

BUT

myfile1.cs DOES NOT SEE the namespace and classes in myfile2.cs, myfile3.cs, myfile4.cs

myfile2.cs DOES NOT SEE the namespace and classes in myfile1.cs, myfile3.cs, myfile4.cs

And so on, I'm sure you get the idea! The codefile, ("myCode.cs") sees all the classes and namespace it needs but the other files do not see the namespaces and files they need!

So the question is how do I make myfile1.cs, see myfiles2.cs, myfile3.cs etc! or how do I build and link the libraries of each .cs file

If the answer is compilation how do I compile and link the files from the aspx page, I know there is a compileOption attribute. I do not have the visual studio structure no App_Code, no build->add references, none of that! Just some textFiles made into a (.cs and .aspx) extension.

I do have a solution but I do not want to use it! Anytime the user clicks any button, it opens a new .aspx file and runs the code in the "<% %>" brackets. I really do not want to do it that way. Please Help!!!

What I want to do, is give the user the ability to choose a local file, and then read its contents in a C# class that will edit them in a certain way and return back the new content.

I tried using ng-file-upload that has an example of this here. For that I added in my template the upload form

<div ngf-drop ngf-select ng-model="tempFile" class="drop-box"
   ngf-drag-over-class="'dragover'" ngf-multiple="false" ngf-allow-dir="false" accept="image/*,application/pdf" ngf-pattern="'image/*,application/pdf'">
 <i class="fa fa-upload"></i> Drop or click to upload a pdf or image file.</br><img ngf-src="tempFile" ngf-background="tempFile" ngf-resize="{width: 40, height: 40, quality: 0.9}" ngf-no-object-url="true">{{tempFile.name}}
 </div>

and a button that will start the upload using

data-ng-click="onFileSelect(tempFile)"

My onFileSelect looks like this

$scope.onFileSelect = function($files, user) {
    console.log("UPLOAD: ", $files, $scope.tempFile);
    for (var i = 0; i < $files.length; i++) {
        var file = $files[i];
        $scope.upload = Upload.upload({
            url: 'MyWebApplication/UploadHandler.aspx',
            data: {
                name: user.Name
            },
            file: file, 
        }).progress(function(evt) {
            //console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total));
        }).success(function(data, status, headers, config) {
            alert('Uploaded successfully ' + file.name);
        }).error(function(err) {
            alert('Error occured during upload');
        });
    }
};

The serverside code is as can be seen in the demo, only located at UploadHandler.aspx, UploadHandler.aspx.cs

If I click the button I can see the result of console.log but nothing else happens, and the file does not get uploaded.

How can I achieve what I want, or if this is not a good way of doing it at all, then how should I go on about correctly implementing this?

Update: If I simply try

Upload.upload({
  url: 'http://' + location.host + '/UploadHandler.aspx',
   method: "POST",
   file: file,
   data: args
})

Then I can reach the server, but I get an Internal Server Error response, So I believe my main issue is in the way I am trying to save the file.

The error in particular complains that The directive 'webhandler' is unknown. and it has to do with UploadHandler.aspx that contains

<%@ WebHandler Language="C#" CodeBehind="UploadHandler.aspx.cs" Class="MyWebApplication.Uploads.UploadHandler" %>

I am trying to create a aspx page dynamically but I am getting errors. So far I have tried this:-

    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Directory.CreateDirectory(Server.MapPath("~/videos/") + "abcd");
            File.Create(Server.MapPath("~/videos/") + "abcd/aa.aspx");
            TextWriter tw = new StreamWriter(Server.MapPath("~/videos/") + "abcd/aa.aspx");
            tw.WriteLine(@"<%@ Page Language=""C#"" AutoEventWireup=""true"" CodeFile=""aa.aspx.cs"" Inherits=""_Default"" %>

    <!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>
            <asp:Button ID=""Button1"" runat=""server"" Text=""This will do nothing"" onclick=""Button1_Click"" />
        </div>
        </form>
    </body>
    </html>");
            tw = new StreamWriter(Server.MapPath("~/videos/") + "abcd/aa.aspx.cs");
            tw.WriteLine(@"using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.IO;

    public partial class _aa : System.Web.UI.Page
    {
    }");
            tw.Close();
            Response.Redirect("~/videos/abcd");
        }
    }

But I am getting error: The process cannot access the file 'E:\personal\create_aspx\videos\abcd\aa.aspx' because it is being used by another process. Why am I getting this error. Can anyone help me to resolve it?

This is my Page1.aspx code:

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
    <asp:Panel ID="Panel1" runat="server">
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    </asp:Panel>    
</asp:Content>

This is my Page1.aspx.cs code

public partial class Page1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == true)
        {
            btn_Click(sender, e);
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Button btn = new Button();
        btn.Text = "Dynamic button";
        btn.Click += btn_Click;
        Panel1.Controls.Add(btn);
    }

    void btn_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Page2");
    }
}

From this code, when "Button1" is clicked it should create a new button "btn" and when "btn" is clicked, it should go to the url in its click function (i.e. btn_Click()). But when I click "Button1" it does not execute "Button1_Click()" but "btn_Click()". What should I do??

I need to get return value from a Used defined function (in a aspx.cs page) and a field (TextBox value) from a form .aspx inside a .js file and compare this two variables in a jquery function. I'm facing problem to get the values (one from a public function and another from the aspx form) inside the .js file.

I've this problem for 3 days and I couldn't find the real answer. I want that if I click a button the code will run and not to refresh all the page. For example:

ASPX code

<dx:ASPxButton ID="ASPxButton1" runat="server" Text="New" OnClick="ASPxButton1_Click"></dx:ASPxButton>
<dx:ASPxButton ID="ASPxButton2" runat="server" Text="Delete"></dx:ASPxButton>

CS code

protected void ASPxButton1_Click(object sender, EventArgs e) //new button
{
    ASPxButton2.Enabled = false;
}

That's basicly what I want to do. Click the new button and make the delete button enabled false without refreshing all the page.

What I tried:

<dx:ASPxButton ID="ASPxButton1" runat="server" Text="New" OnClick="ASPxButton1_Click" onclientClick=" return false;"></dx:ASPxButton>
<asp:button ID="Button1" runat="server" Text="New" OnClick="Button1_Click" onclientClick=" return false;"></asp:button>
<asp:button ID="Button1" runat="server" Text="New" OnClick="Button1_Click"></asp:button>
<asp:button ID="Button1" runat="server" Text="New" OnClientClick="DisableButton(); return false; "></asp:button>

function DisableButton() {
  document.getElementById("<%= ASPxButton2.ClientID %>").click();
}

Tried UpdatePanel too but I use MasterPage and that's why it doesn't work.

When I run my project I have an error. This is what I find Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

[No relevant source lines]

Source File: c:\Users\DELL\AppData\Local\Temp\Temporary ASP.NET Files\root\7b316ac0\74a3eae4\App_Web_default.aspx.cdcab7d2.dyxvfbuu.0.cs Line: 0 ASP.default_aspx..ctor() in c:\Users\DELL\AppData\Local\Temp\Temporary ASP.NET Files\root\7b316ac0\74a3eae4\App_Web_default.aspx.cdcab7d2.dyxvfbuu.0.cs:0 __ASP.FastObjectFactory_app_web_default_aspx_cdcab7d2_dyxvfbuu.Create_ASP_default_aspx() in c:\Users\DELL\AppData\Local\Temp\Temporary ASP.NET Files\root\7b316ac0\74a3eae4\App_Web_default.aspx.cdcab7d2.dyxvfbuu.1.cs:0 System.Web.Compilation.BuildResultCompiledType.CreateInstance() +30
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +100

I have a project with this folder hierarchy:

Solution
 App_Code
  library.cs
 Application
  page.aspx
   page.aspx.cs

The problem is that page.aspx.cs cannot reference a public function in library.cs. I've checked all relevant access modifiers and even tried recreating the App_Code folder and its contents.

I also tried putting library.cs under the same folder as page.aspx.cs, but it still couldn't see into the App_Code namespace.

default.aspx.cs

int sum;

sum= txt.Text + txt2.Text;

I have a simple aspx and aspx.cs file in which i am calculate sum of two numbers but now i want make a dll of aspx.cs .

now i want only dll of default.aspx.cs file

i dont wont aspx.cs file in my site.

i have visited many solutios but i didnt find the proper way to implement it.

and what is the diiference if i make dll instead of aspx.cs file.?

Give me the solution in step by step manner..

Thank you

This is my .aspx page

<asp:Panel ID="Panel1" runat="server">
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    <asp:Label ID="Label1" runat="server"></asp:Label>
</asp:Panel>    

This is my aspx.cs page

public partial class Test : System.Web.UI.Page
{
    protected void Button1_Click(object sender, EventArgs e)
    {
        Button button2 = new Button();
        button2.Text = "Dynamic Button";
        button2.Click += new EventHandler(button2_Click);
        Panel1.Controls.Add(button2);
    }

    void button2_Click(object sender, EventArgs e)
    {
        Label1.Text = "working";
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

"button2"'s click even does not work. I also tried:

button2.Click += button2_Click;

But that does not seem to work either. If I place the code in the "Page_Load" function, it works. But I want the dynamic button to be added to the page on clicking the first button (i.e. Button1).

How do I make this work??