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);



        if (result == "H")
            HiddenField2.Value = TextBox1.Text ; 
            Server.Transfer("~/LtssEnrollment-HCS.aspx", true);
            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 developing website project with aspx and aspx.cs file. in aspx.cs file, i have 1 class and work perfectly. However, when I add new class in the aspx.cs, the error occurs (cs 1061) and says

"Severity Code Description Project File Line Suppression State Error 'translator2_aspx' does not contain a definition for 'Switch' and no extension method 'Switch' accepting a first argument of type 'translator2_aspx' could be found (are you missing a using directive or an assembly reference?) C:\Users\Erwin Surya\Documents\Visual Studio 2017\WebSites\WebSite2\Translator2.aspx 33 "

do you have any idea why is this happened? and what the solution?

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">{{}}

and a button that will start the upload using


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 /;
        }).success(function(data, status, headers, config) {
            alert('Uploaded successfully ' +;
        }).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

  url: 'http://' + + '/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 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">


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


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!!!

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"" """">

    <html xmlns="""">
    <head runat=""server"">
        <form id=""form1"" runat=""server"">
            <asp:Button ID=""Button1"" runat=""server"" Text=""This will do nothing"" onclick=""Button1_Click"" />
            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

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?

I am fetching data from DB and assign to repeater but when I click on button event it only go to page load function but not going to required on click event, I am confusing why this happening. but when i comment repeater its working fine. but I don't why it's not working with repeater in page load

aspx code

<form runat="server">    
           <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
           <asp:UpdatePanel runat="server"  pdateMode="Conditional"  ChildrenAsTriggers="true" >     

<asp:Label ID="Label2" runat="server" Text=""><%# Eval("Time") %></asp:Label>          

                    <asp:AsyncPostBackTrigger ControlID ="Button3" EventName ="Click" />
                    <asp:AsyncPostBackTrigger ControlID ="Button2" EventName ="Click" />


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.

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" />

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;

    void btn_Click(object sender, EventArgs e)

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'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 am creating an ASP.NET website. As it is a website not a web application i am stuck at few problems. One of them is as the title says the update ****** panel. I placed a Textbox in an update panel and the code in .aspx looks as following:

<asp:ScriptManager ID="SCManager" runat="server" AsyncPostBackTimeout="0" />
<asp:UpdatePanel ID="SCPanel" runat="server" >
    <asp:TextBox ID="MsgTB" runat="server" ForeColor="#FF4C4C" 
    OnTextChanged="MsgTB_TextChanged" AutoPostBack="True"></asp:TextBox>
    <asp:AsyncPostBackTrigger ControlID="MsgTB" EventName="TextChanged" />

Then I prepared .aspx.cs file where another button calls a function Run(....,TextBox _console, UpdatePanel _Upanel) from another myclass.cs file (i used using static namespace myclass.cs), and this function Run() changes the _console (passed as the MsgTB) value of _console.Text attribute (works fine). Then it calls _Upanel (passed as SCPanel) .Update() (does not work fine). Like this:

_console.Text = "Password?";//fine
_UPanel.Update();//not fine` 

And so there is no effect visble on my site. To be precise one more thing when i called the SCPanel.Update() in websites direct .aspx.cs file everything went fine and after calling some button (i mean ContinueBTN) onclick_event

protected void ContinueBTN_Click(object sender, EventArgs e)
    GlobalContinue = true;
    MsgTB.Text = "i love";

i saw "i love" in the TextBox on the website. And so i beg for help.

PS What i found out till now: Proper refresh of TextBox occurs only when a function ends, same for function called from faraway myclass.cs and same for functions from page.aspx.cs. Calling another thread did not help.