How can i connecting two different web forms in C#? - c#

I'm working on my school project in which I need to build up one original web application. But I got an error when I tried to connect two web forms in my project. I have no idea what's wrong about it, and I have looked at many video instruction sources showing how to do it, and still I have the same error.
Here is what I have done.
First, I created a web from and named it MainForm
and also I made another one and named TestForm1.
Then, I put a button on TestForm1 aspx file, double-clicked the button to call the cs file, and there I coded
protected void Button1_Click(object sender, EventArgs e)
{
MainForm newWindow = new MainForm();
newWindow.Show();
}
Here, an error comes up and I see a red line under "Show"
The error says
MainFor1 does not contain a definition for "Show," and no extension
method accepting a first argument of type "MainForm" could be found.
What is wrong about my code? I just simply made two forms and am trying to connect them.
Please tell me how I can handle this problem.
Sorry for my bad English, since I'm not a native speaker.
And Thank you in advance.

According to my Understating you want to navigate to another page, you can add a link button to take you to the other page like so:
<asp:Button ID="Button3" runat="server" Text="Button" PostBackUrl="anotherpage.aspx" />

To show a new Page (not a Form!) means that you want the Web Browser to open a new URL. This can be done in many ways, and the way closest to your orignal code is this:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("MainForm.aspx");
}
A Redirect literally tells the browser: please go to another URL. The browser then makes a new http request with the new URL, and the server then shows that page.

You need to use Server.Transfer(), method Show() can't be used in WebForms. Probably You are wrong WinFroms with WebForms.
Server.Transfer("TestForm1.aspx", true);
Here you find introduction to ASP.NET and Web Forms
Summary: This article explains how Web Forms are fundamental to Microsoft ASP.NET, shows how to build a Web form, and discusses the controls essential for building a Web Form. (16 printed pages)
Objectives
Learn about Web Forms
Learn the Web controls that are built into Web Forms
Build a Web Form

Related

Write values to text boxes on web page with CefSharp

I integrated CefSharp into my project. I was able to work out some points. However, I couldn't figure out how to check Inputboxes for example on a given site. So how can I write data into that InputBox. I request your help in this matter.
Thanks in advance.
You won't be able to modify the content of your web page running inside CefSharp from the C# code directly. What you can do however is to pass javascript code that will run on the page and will change content.
For example, something similar to this:
var browser = new ChromiumWebBrowser("https://www.example.com");
await browser.ExecuteScriptAsync("document.getElementById('myTextBoxId').value='the value'");

It is possible to pass a code from a web form to a view? (c#)

I have a web application with a contact page that is a web form. Since I can't use the _layout.cshtml as a layout in the Web Form, I was wondering if it is possible to pass the code the web form to a view. I looked over the internet about this but I couldn't find any suitable answer.
I think that, passing the asp.net code to pure html is "possible" but how do I pass the "btnSend_Click" event?
It is impossible. You have to generate new codes for View.

Windows 10 Cordova/Ionic link makes phone open store link

I'm using the default template and generated code from the template (Cordova Multiplatform Template 1.0.2). However when I tap a list item this messagebox shows up instead of navigating:
Found the answer here
Partial pages don't load?
When you are using the AngularJS routing module (Ionic starter templates often use this module), you may need to include a call to aHrefSanitizationWhitelist.
If you see the dialog box shown here, you have likely run into this
issue.
Typically, you include the code fix in app.js or wherever you are
calling your module configuration code:
.config(function ($stateProvider, $urlRouterProvider, $compileProvider) {
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|ghttps?|ms-appx|ms-appx-web|x-wmapp0):/);
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|ms-appx|ms-appx-web|x-wmapp0):|data:image\//);

how to execute C#.net code in html file?

This will probably sound dumb, but I need to execute a C# code from my html file. For example I just want to execute this
System.Diagnostics.Process.Start(#"D:\Movies\HurtLocker.avi");
Not any server side code.
I can't create aspx page, because to open an aspx page in a browser it needs to be hosted in IIS.
You can't execute server side code from a client side page. If your page is aspx you can use a webservice or click a serverside button from javascript.
Edit: If you want to embed a video player please check this link. You don't need server side code for this. You'll be able to do it with javascript.
Where do you want the c# code to run?
If you want it to run in the browser that is being used to render the html then I'd say that was basically not possible. Something, presumably javascript code in the html page, would have to somehow instantiate a .net clr and pass the c# code to it for execution. The clr does have a COM-based hosting interface that would allow instantiation, but even if you could call this from javascript I think that any sensible browser security settings would prevent it.
If you want the c# to run on the server supplying the html page then you should use asp.net.
EDIT
Ok, you want to run it in the browser. I'm not aware of any examples for hosting a clr in the browser process, sorry.
You can create activex/com objects in js using something like var obj=new ActiveXObject("<comclassname>");, and you might be able to create a CLR that way by instantiating one of the COM classes (maybe CLRRuntimeHost) listed on this page. You could then pass your c# code to your clr for execution. More info here and here. I'm really not sure if that would work, though. I've never used the hosting api, I just know it exists!
Seems like an interesting project to try if you are curious, but deploying this in a real environment would likely present lots of problems. Good luck!
Not C#, but how about .NET dynamic language in the browser with Gestalt? http://gestalt.codeplex.com/
You can create a code block in your ASP file but if this is simple HTML file this is not possible.
At least you will have some application that will read the content of the page compile it and execute.
ASP code block
As Pabuc mentioned you can't execute server side code on the client machine in HTML. If you were to use Silverlight you could execute the code client side, but then the client need to have Silverlight installed and it is not strictly HTML anymore.
Silverlight could be used to play movies client side with C#.
The only way to have C# on client side is Silverlight application [update] or any other browser plugin as #kenny mentioned.
I have tried to find a software for this some time. I have software, which has needs, that are hard to make with traditional Web programming.
Now I have made simple demo, how to create HTML5 online application with C# or VB.NET.
It is Scot library which translates C# to Javascript on time when executing .NET application. It also supports events on Browsers, which is executed in c# code.
To original question:
On the Html page you will need to add single line after :
<script src="myclass.cs"> </script>`
to connect .Net class:
using Scot;
//..
public myclass:Document
{
protected override OnConnect()
{
Elements["mybutton"].OnClick+=new JsInputEventHandler(click);
//your initialization //....
}
private void click(object sender, JsInputEventArgs e)
{
Window.Alert("Click()");
}
}
Demos are quite simple, but actually I needed this library for another project.
It would be nice to have any feedback.

ASP 2.0 and partial classes

One of our contractors gave us an ASP.NET 2.0 web site and I'm having a little trouble integrating it into our process. He gave us the project as a zipped directory, no solution file or anything. I can open it in Visual Studio using the Open -> Website option, and the website runs. However, I wanted to set it up as a web application project so that I could add project references to our shared libraries instead of them being linked into the 'bin' directory, and just because I'd prefer to have a regular project really.
I'm running into a weird issue. Let me extract a little code:
HeaderControl.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeFile="HeaderControl.ascx.cs" Inherits="Controls_WebUserControl" %>
HeaderControl.ascx.cs
public partial class Controls_WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
Ok, this is a little strange but it seems to be legal at least. The base class has a partial definition in the code-behind (code file?). But then many other controls are defined in the same way, eg
SomeControl.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeFile="SomeControl.ascx.cs" Inherits="Controls_WebUserControl" %>
SomeControl.ascx.cs
public partial class Controls_WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
Expectedly, when I try to build my new web application project that I've transferred the files into I get a bunch of errors about the same method being defined in several places. I don't understand why it's not set up with a code behind defining a partial definition of the control class and overriding methods of the base class, but that's sort of beside the point.
What really gets me is this: How does the original work? It runs and it works, so the compiler must be doing something that I don't understand. What happens to the Controls_WebUserControl class?
WHen you change from a web site to a web app, you need to right-click on the project and choose "Convert to Web Application". This should update all the pages.
This is an old link, but I think it's still relevant:
http://webproject.scottgu.com/CSharp/migration2/migration2.aspx
I would say that while the provided site works, it is incorrect.
It works because it is a Web Site project (as opposed to a Web Application Project). Web Site projects do not have a namespace for the web pages; instead it compiles each page separately. In other words, you could say that the class name for the pages is ignored.
It fails when you bring it into a Web Application project because that tries to build a namespace and that fails because of the common class names across the web pages and controls.
I'd right click, select Convert to Web Application, and then fix the class names on the pages & controls. That should get you to where you want to be.
Actually you need to replace CodeFile="SomeControl.ascx.cs" with CodeBehind="SomeControl.ascx.cs"
CodeBehind vs CodeFile

Categories

Resources