먼저이 분야의 초보자라는 사실을 튜토리얼을 통해 알려야합니다.버튼을 클릭 할 때 소스 코드 표시
그 말은 codebehind 파일에서 버튼을 클릭하면 텍스트 상자에 sourcecode를로드하는 방법을 찾고 있다고 말했습니다. 같은 aspx 파일에 대한 간다.
나는이 웹 사이트를 만들고 있는데, 여기서 내가하는 일의 코드 예제를 보여줄 것이다. 따라서 myweb.com/tutorial1done.aspx로 이동하면이 페이지는 나에게 자습서의 최종 결과를 표시합니다. 쇼 소스 단추를 클릭하면 2 개의 텍스트 상자가 보이게하고 첫 번째 상자에 codebehind를 추가하고 aspx 소스를 두 번째 상자에 추가해야합니다.
가능한지 모르겠지만 희망합니다. 쉬운이해야하지 않는 한, 지금 소스 강조가 필요하지 않은 경우
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class DateTimeOutput : System.Web.UI.Page
{
protected void output(String value)
{
outputText.Text += value + Environment.NewLine;
}
protected void runButton_Click(object sender, EventArgs e)
{
DateTime dt = new DateTime();
output(dt.ToString());
DateTime nowDt = DateTime.Now;
output(nowDt.ToString());
}
protected void clearButton_Click(object sender, EventArgs e)
{
outputText.Text = "";
}
protected void dt_showSource_btn_Click(object sender, EventArgs e)
{
if (dtcb_output.Visible == false)
{
dtLabel1.Visible = true;
dtcb_output.Visible = true;
}
else
{
dtLabel1.Visible = false;
dtcb_output.Visible = false;
}
if (dtaspx_output.Visible == false)
{
dtLabel2.Visible = true;
dtaspx_output.Visible = true;
}
else
{
dtLabel2.Visible = false;
dtaspx_output.Visible = false;
}
}
}
}
:
ASPX :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DateTimeOutput.aspx.cs" Inherits="WebApplication1.DateTimeOutput" %>
<!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>
<link rel="stylesheet" href="../styles/codeformatter.css" />
</head>
<body>
<form id="form1" runat="server">
<customControls:Header runat="server" heading="Date and Time Output" />
<div>
<asp:Panel ID="Panel1" runat="server">
<asp:TextBox ID="outputText" runat="server" Height="175px" TextMode="MultiLine"
Width="400px"></asp:TextBox>
</asp:Panel>
</div>
<asp:Panel ID="Panel2" runat="server">
<asp:Button ID="runButton" runat="server" Text="Run Code"
onclick="runButton_Click" Width="95px" />
<asp:Button ID="clearButton" runat="server" Text="Clear Console"
onclick="clearButton_Click" Width="95px" />
<br />
<br />
<asp:Button ID="dt_showSource_btn" runat="server"
onclick="dt_showSource_btn_Click" Text="Show Source" />
</asp:Panel>
<asp:Label ID="dtLabel1" runat="server" Text="Code Behind:" Visible="False"></asp:Label>
<br />
<asp:TextBox ID="dtcb_output" runat="server" Height="175px"
TextMode="MultiLine" Visible="False" Width="400px"></asp:TextBox>
<br />
<br />
<asp:Label ID="dtLabel2" runat="server" Text="ASPX:" Visible="False"></asp:Label>
<br />
<asp:TextBox ID="dtaspx_output" runat="server" Height="175px"
TextMode="MultiLine" Visible="False" Width="400px"></asp:TextBox>
</form>
</body>
</html>
그리고 코드 숨김
이
지금까지 나는이 있습니다.Thx.
미리 정의 된 소스 코드를 의미하는지 또는 현재 페이지의 소스 코드를 언급하고 있는지 확실하지 않은가요? –
나는 현재 페이지의 출처를 언급하고 있었다. - 그러나 mattens 대답은 가능하지 않다는 것을 알려준다. :) – fjappe