Launch a website through button click in excel - c#

I have an mvc app which is integrated to excel workbook. I have a "Launch" button in excel which on click should launch the following website:
http://students/SubmitComments/
Here is my controller action:
public ActionResult StudentComment(string sid)
{
SubmitCommentViewModel model = new SubmitCommentViewModel ();
model.sid = sid;
TempData["model"] = model;
return View(model);
}
Here is my view:
<%# Page
Language="C#"
MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<STU.Models.StudentCommentViewModel>"
%>
<asp:Content ID="Content4" ContentPlaceHolderID="TitleContent" runat="server">
Student Comments
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="PageName" runat="server">
Student Comments</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<form id="Form1" method="post" action="/Student/StudentCommentEmail/">
<label>
Run Number: <%= Html.DisplayFor(x => x.Id) %>
</label>
<br />
<br />
<textarea name="comment" cols="40" rows="5">
Enter comments here...
</textarea><br/><br/>
<input type="submit" value="Submit Comments" /><br />
</form>
</asp:Content>

You need to host your website somewhere. http://students/SubmitComments/ is not a valid url. You can't link your excel workbook to your Visual Studio hosted site. That only works within Visual Studio. Unless you setup Visual Studio to work with IIS Express.
If you want others to use this Excel workbook then you will have to host your mvc site somewhere that is publically, or at least internally accessible.

Related

ASPX File only Shows Code

I've been trying to upload my site to my Hostinger domain for a few days now, however for some reason the .aspx file shows the raw code and doesn't show any of the GUI present when run through the browser.
How would you advise?
<%# Page Title="" Language="C#" MasterPageFile="~/Mater Pages/Primary.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.auto-style1 {
width: 873px;
height: 455px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<h2 style="text-align: center">
Hello and welcome to my personal website. I hope that you enjoy your visit.</h2>
<h3 style="text-align: center">
If for any reason you can't find exactly what you are looking for then please use the contact form here and you'll get a response within 2-3 working days</h3>
<h3 style="text-align: center">
<img alt="" class="auto-style1" src="Images/Default/image%20for%20hompage.png" /></h3>
<p style="text-align: center">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Website Ad Test -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-8284273019831171"
data-ad-slot="7241345648"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</p>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>
Looking at Hostinger's website it looks to me that they do not support .net framework.
it seems that your server does not execute the code in your .aspx web page, it just returns the content (the source code) of it.
Contact your web server provider and make sure they are serving .NET pages.

Error Creating Control on asp.net video

I was trying to embed an asp.net video control using my visual web developer 2008 express ed. which originally doesn't have a built-in asp.net video control on its toolbox. I added the asp.net video control on the toolbox after I extracted the zip compressed folder that I downloaded. I was able to add the three asp.net video controls(WindowsMedia,Realplayer,Quicktime) from the downloaded files on the toolbox. At first, it was working when I tried to drag the WindowsMedia control from the toolbox onto the page but suddenly when I changed it using Realplayer it will now display an Error Creating Control on the control after dragging into the page. The error says:
The server tag 'ASPNetVideo:RealPlayer' is ambiguous. Please modify
the associated registration that is causing ambiguity and pick a new
tag prefix.
So, I keep on changing the control from WindowsMedia to Quicktime and still giving the same error. Here's my source code below for more reference:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%# Register assembly="ASPNetVideo.NET2.AJAX" namespace="ASPNetVideo" tagprefix="ASPNetVideo" %>
<%# Register assembly="ASPNetVideo.NET3" namespace="ASPNetVideo" tagprefix="ASPNetVideo" %>
<%# Register assembly="System.Web.Extensions" namespace="System.Web.UI" tagprefix="asp" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div id = "mydiv" runat="server">
<br />
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<asp:Button ID="Button1" runat="server" Text="Upload" Width="82px" OnClick = "Button1_Click" />
<br />
<br />
<br />
<ASPNetVideo:RealPlayer ID="RealPlayer1" runat="server" >
</ASPNetVideo:RealPlayer>
<br />
</div>
</form>
</body>
</html>
Please advise...Thanks.
<%# Register assembly="ASPNetVideo.NET2.AJAX" namespace="ASPNetVideo" tagprefix="ASPNetVideo" %>
<%# Register assembly="ASPNetVideo.NET3" namespace="ASPNetVideo" tagprefix="ASPNetVideo" %>
RealPlayer is most probably defined in both those assemblies. Try with only one of them and remove the other register.
You can also assign different namespaces to the two assemblies and then you wouldn't be getting an error once you resolve the ambiguity:
<%# Register assembly="ASPNetVideo.NET2.AJAX" namespace="ASPNetVideo" tagprefix="ASPNetVideo" %>
<%# Register assembly="ASPNetVideo.NET3" namespace="ASPNetVideo2" tagprefix="ASPNetVideo" %>

How to use form with method="post" in asp.net web form

I am using ajax toolkit asyncFileUpload control
I had problem that my server side events does not fired and found this posts Hidden/Shown AsyncFileUpload Control Doesn't Fire Server-Side UploadedComplete Event
I inserted my uploader inside form and with this attributes enctype="multipart/form-data" method="post"
This uploader is inside my webs form which is inside master page
After adding this attributes i got this error
A page can have only one server-side Form tag.
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.Web.HttpException: A page can have only one server-side Form tag.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
And here is my web form
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<form id="Form1" enctype="multipart/form-data" method="post" action="target_url"
runat="server">
<div id="Div1" runat="server">
Just some time to make sure that the page doesn't get reloaded after uploading:
<%=DateTime.Now %><br />
<ajaxToolkit:AsyncFileUpload ID="FileUpload" runat="server" OnUploadedComplete="FileUpload_UploadCompleted"
OnClientUploadComplete="FileUpload_ClientUploadCompleted" OnClientUploadError="uploadError"
OnLoad="FileUpload_OnLoad" />
<asp:Image runat="server" ID="imgUpload" src="" />
<asp:Label runat="server" ID="lblerror" Text="" />
</div>
</form>
</asp:Content>
Your MasterPage already has a form element. Nested forms aren't allowed...
I don't know much about the ajaxToolkit:AsyncFileUpload but, since it is a server control, it should change the parent forms properties. Have you tried removing the form like the code below?
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div id="Div1" runat="server">
Just some time to make sure that the page doesn't get reloaded after uploading:
<%=DateTime.Now %><br />
<ajaxToolkit:AsyncFileUpload ID="FileUpload" runat="server" OnUploadedComplete="FileUpload_UploadCompleted"
OnClientUploadComplete="FileUpload_ClientUploadCompleted" OnClientUploadError="uploadError"
OnLoad="FileUpload_OnLoad" />
<asp:Image runat="server" ID="imgUpload" src="" />
<asp:Label runat="server" ID="lblerror" Text="" />
</div>
</asp:Content>
Another Possible Solution:
"Pop" a "modal" form that just contains your form with the file upload control. This will remedy the nested forms issue. But, it does changed the functionality.
As a very dirty hack try adding adding a <form></form> in front of your form, and take the runat="server" out of your nested form.
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
**<form></form>**
<form id="Form1" enctype="multipart/form-data" method="post" action="target_url"
>
<div id="Div1" runat="server">
Just some time to make sure that the page doesn't get reloaded after uploading:
<%=DateTime.Now %><br />
<ajaxToolkit:AsyncFileUpload ID="FileUpload" runat="server" OnUploadedComplete="FileUpload_UploadCompleted"
OnClientUploadComplete="FileUpload_ClientUploadCompleted" OnClientUploadError="uploadError"
OnLoad="FileUpload_OnLoad" />
<asp:Image runat="server" ID="imgUpload" src="" />
<asp:Label runat="server" ID="lblerror" Text="" />
</div>
</form>
</asp:Content>
In the past this has worked for me - when forced to work with WebForms. I don't know why but I find that quite a lot with WebForms.
You really should switch to MVC if you want to write code like this however. Even if this does work it's not what I'd call a solution. WebForms just isn't designed to do this.

Content Page and Master Page events

I have had this problem for a while now and no matter what i cannot seem to resolve it. I have a master page and a content page.
The content page simply contains a button
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</asp:Content>
The master page simply contains the content place holders. The button1 one event fires normally, however as soon as a form is added to the master page the button stops firing. the master page looks something like this
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
Member Login
<asp:Button ID="btnLogin" runat="server" Text="Login" CssClass="bt_login"
onclick="btnLogin_Click" />
</form>
</div>
</div>
</div>
</div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</form>
Can some one please help, the button works fine without the form in teh master page, however i need a form in the master page
Thanks
Ok after running the exact same project on another machine, everything worked fine. So I'm guessing there is an issue with the way i installed visual studio and asp.net.

Uploading an image in ASP.NET MVC using EDM

I am new to using ASP.NET MVC and I've been having some difficulties with it. I created my model using the Entity Data Model just for the record.
My problem is that I'm trying to insert an image into my MS SQL 2008 server using my new ASP.NET page. The image is a part of the information that I need to store about Employees in my database. From my home HomeController.cs file I right-clicked the Create method and chose to create a view, which it did. However, uploading an image was not part of the auto-generated code.
In the Create View there are a few text-boxes that correspond to my table columns and a single submit button that creates my new database row somehow. I thought that the button would run the code for the other Create method in the HomeController.cs file that takes an Employee as a parameter but I guess my problem lies in the fact that I don't know what happens between me pressing the Submit button and the creation of an Employee object for the Create method.
For reference, here is the code I'm working with .First code for Homecontroller.cs and then code for Create.aspx (note that the variable _db is a copy of my Entity Data Model):
public ActionResult Create()
{
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude = "employeeNumber")] Employee employeeToCreate)
{
try
{
_db.AddToEmployee(employeeToCreate);
_db.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
I don't know why the code above indent's the way it does.
I also don't know why, but the code below doesn't show the first few lines properly so I deleted a few < > around C# code and asp code in order for the code to become visible.(FIXED)
<Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<LaunakerfiASP_MVC.Models.Employee>"
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Create
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Create</h2>
<%= Html.ValidationSummary("Create was unsuccessful. Please correct the errors and try again.") %>
<% using (Html.BeginForm()) { %>
<fieldset>
<legend>Fields</legend>
<p>
<label for="name">name:</label>
<%= Html.TextBox("name")%>
<%= Html.ValidationMessage("name", "*")%>
</p>
<p>
<label for="email">email:</label>
<%= Html.TextBox("email")%>
<%= Html.ValidationMessage("email", "*")%>
</p>
<p>
<label for="department">department:</label>
<%= Html.TextBox("department")%>
<%= Html.ValidationMessage("department", "*")%>
</p>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%=Html.ActionLink("Back to List", "Index") %>
</div>
</asp:Content>
So what I would like to do is to add an element to the Create.aspx view that let's me upload an image to the column 'picture' in the table 'Employee'.
In your controller action, you can access the uploaded files through Request.Files
Here are some links about file uploads in ASP.NET MVC :
http://www.hanselman.com/blog/ABackToBasicsCaseStudyImplementingHTTPFileUploadWithASPNETMVCIncludingTestsAndMocks.aspx
http://aspzone.com/tech/asp-net-mvc-file-upload/

Categories