我将HTML存储在数据库中,并尝试使用文字控件将其呈现在页面上。问题在于文字不呈现代码,而只是在网页上显示标记。我已经检查了HTML,将其直接添加到页面时可以正常工作,但是将其设置为文字文本属性时则无法工作。
我之前已经做过很多次了,实际上我已经重复使用了代码,但是由于某种原因,只显示了标记。
页面文字:
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentArea" Runat="Server">
<asp:Literal ID="Literal1" runat="server" Mode="PassThrough"></asp:Literal>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
VB代码:
Private Sub LoadContent()
Dim strConnectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim conn As SqlConnection = New SqlConnection
conn.ConnectionString = ConfigurationManager _
.ConnectionStrings("ConnectionString").ConnectionString
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = ("select HTML from Pages where " & _
"PageName like @SearchText + '%'")
cmd.Parameters.AddWithValue("@SearchText", "TheShop")
cmd.Connection = conn
Dim sb As StringBuilder = New StringBuilder
conn.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader …Run Code Online (Sandbox Code Playgroud) 我有一个简单的asp.net webform页面,我用它来显示基于pageID的页面相关数据.
我正在尝试定义页面级变量,以便我可以访问此页面中使用的不同函数中的变量.但我收到的错误很少.例如,如果我的代码是
public partial class PageHome : System.Web.UI.Page
{
int _LangID = 1;
_LangID = int.Parse(Helper.GetAppSetting("LangID_En"));
int _PageID = 0;
int _PID = Helper.GetPageID(_LangID, "Home.aspx");
protected void Page_Load(object sender, EventArgs e)
{
int _LanguageID = _LangID;
GetPageDetails(_PageID);
}
}
Run Code Online (Sandbox Code Playgroud)
然后我明白了
Error message:
Invalid token '=' in class, struct, or interface member declaration (_LangID = int.Parse(Helper.GetAppSetting("LangID_En"));)
Invalid token '.' in class, struct, or interface member declaration (_LangID = int.Parse(Helper.GetAppSetting("LangID_En"));)
Method must have a return type
Identifier expected
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用在构造函数中定义这些变量
//public PageHome() …Run Code Online (Sandbox Code Playgroud) 我有一个ashx页面设置来处理来自服务的传入http帖子.
而且我想知道是否有更好的方法来填充我的匿名类型而不是手动执行.例如.
public class myclass
{
[key]
public int ID { get; set; }
public int field1 { get; set; }
public int field2 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后在我的ashx页面上
myclass mc = new myclass();
mc.field1 = context.Request.Form[field1];
mc.field2 = context.Request.Form[field2];
Run Code Online (Sandbox Code Playgroud)
是不是只有一种方法来转换或转换为我的类型?
myclass mc = new myclass();
mc = context.Request.Form;
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用异步和等待.NET Framework 4.5中提供的功能执行多个数据库调用.这是我第一次实现此功能.
如果每个查询花费7秒,则过去需要35秒(5个查询*7秒).通过以下实现,我期待它应该在接近7-9秒的时间内在asp页面中获取和填充控件.但是,它仍然需要35秒,证明了我的同步行为.
有人可以帮助我在下面的异步实现中出错.
我对任何投入表示赞赏,因为几天以来我一直在为此而烦恼
protected void Page_Load(object sender, System.EventArgs e)
{
RegisterAsyncTask(new PageAsyncTask(FillControlsAsync));
}
public async Task FillControlsAsync()
{
Task[] tasks = new Task[]{
PopulateControlTask(query1, "controlID1"),
PopulateControlTask(query2, "controlID2"),
PopulateControlTask(query3, "controlID3"),
PopulateControlTask(query4, "controlID4"),
PopulateControlTask(query5, "controlID5")
});
await Task.WhenAll(tasks);
}
public async Task PopulateControlTask(string query, string control)
{
await Task.Run(() =>
{
DataSet ds;
OracleCommand cmd;
OracleDataAdapter da;
try
{
if (!Page.IsPostBack)
{
cmd = new OracleCommand(query, cn);
da = new OracleDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
switch (control)
{ …Run Code Online (Sandbox Code Playgroud) 既然AutoMapper正在废除静态API和在运行时更改映射的能力,那么在没有IoC管理器的情况下我的WebForms应用程序就会出现问题.
对于这个问题的缘故拿给出我不能提出一个IoC经理到这个应用程序,而这将是"好做",没有它的应用一直在努力罚款数年,并且它不能正确的进行此时此刻.在未来可能,但不是现在.
使用AutoMapper之前我曾经做过的事情是在我实例化的每个类中都有一个方法,它由构造函数自动调用.在那种方法中,我将有必要:
Mapper.CreateMap<>()
Run Code Online (Sandbox Code Playgroud)
调用.这具有以下优点:
我很高兴能够以这种方式满足每次执行操作的性能,而不是在Application_Start()中执行此操作.
但是使用AutoMapper 5 ... 从静态API读取迁移后,我现在必须:
如果我在上面的1.和2.中的假设是正确的,我现在有一大堆紧密耦合的意大利面条代码.
所以我的问题是:
如何在一个webforms应用程序中使用AutoMapper 5,在解决方案中有许多项目(因此有很多类型),没有优雅的IoC?
当我以编程方式调用Timer1_Tick(null,null)事件消息变空时?如何解决此问题OnMessageReceieve在事件触发时调用.
string message = string.Empty;
public void OnMessageReceieve(string message)
{
// I have a message in message variable
txtMessage.Text += message;
Timer1.Enabled = true;
Timer1_Tick(null, null);
// UpdatePanel1.Update();
}
protected void Timer1_Tick(object sender, EventArgs e)
{
//message variable gets empty here?
if (!string.IsNullOrEmpty(message))
{
txtMessage.Text += message;
}
}
Run Code Online (Sandbox Code Playgroud) 在我的webform中,我从后面的代码创建了按钮:
Button btnShowCase = new Button();
btnShowCase.ID = "btnShowCase_" + ticketNumber;
btnShowCase.CssClass = "BtnShowCase";
btnShowCase.Text = "Display";
btnShowCase.OnClientClick = "ShowCase";
Run Code Online (Sandbox Code Playgroud)
在客户端点击我想执行功能
protected void ShowCase(object sender, EventArgs e)
{
Do something
}
Run Code Online (Sandbox Code Playgroud)
OnClientClick不调用ShowCase.我做错了什么?
我正在尝试向用户维护和按钮的单击下载excel文件添加按钮,其中包含一些数据.我创建了PXAction,它的方法如上:
public PXAction<Users> getUsers;
[PXUIField(DisplayName = "Get Users", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select,Visible = true), PXButton(CommitChanges = true)]
public IEnumerable GetUsers(PXAdapter adapter)
{
var accessByRoles = PXSelect<RolesInGraph>.Select(this.Base);
var usersByRole = PXSelect<UsersInRoles>.Select(this.Base);
var dt = GetTable();//GetTable returns some DataTable just for test now
XLWorkbook workbook = new XLWorkbook();
workbook.Worksheets.Add(dt, "UserAccessRigths");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
workbook.SaveAs(MyMemoryStream);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=\"UserAccessRigths.xlsx\"");
HttpContext.Current.Response.AppendHeader("Content-Length", MyMemoryStream.ToArray().Length.ToString());
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
HttpContext.Current.Response.BinaryWrite(MyMemoryStream.ToArray());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
一切正常,但浏览器中必须开始下载的部分.我得到了excel的响应,但它没有被下载.这是我在浏览器中得到的响应:

如果有人能帮助我,我将非常感激.
提前致谢
如何从转发器中获取隐藏字段的值到javascript函数中?实质上,使用以下中继器:
<asp:Repeater runat="server" ID="dtrRedStations">
<ItemTemplate>
<div class="RepeaterClass">
<asp:HiddenField runat="server" ID="hdnStationRedID" />
<asp:HiddenField runat="server" ID="hdnStationRedEXID" />
<div class="col-xs-12">Name: <asp:Label runat="server" ID="lblStationRedName" Text='<%#Bind("Name")%>'></asp:Label></div>
<div class="col-xs-12">Number: <asp:Label runat="server" ID="lblStationRedNumber" Text='<%#Bind("Number")%>'></asp:Label></div>
<div class="col-xs-12">Job:<asp:Label runat="server" ID="lblStationRedJobClass" Text='<%#Bind("Job")%>'></asp:Label></div>
</div>
</ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
我想在div中添加一个可点击事件,该事件从第一个隐藏字段值中获取值,并使用它在javascript中设置第二个隐藏字段值.但我无法弄清楚如何在运行时告诉哪个转发器实例绑定了我所在的值.
我将维护一个具有WebForms项目的旧Web应用程序。我需要向应用程序添加一个新项目。可以以任何方式成为MVC Core项目吗?我的意思是,一个MVC Core项目可以与WebForms项目共存于同一应用程序中吗?
webforms ×10
asp.net ×8
c# ×7
.net ×1
acumatica ×1
ado.net ×1
asp.net-core ×1
async-await ×1
automapper ×1
automapper-5 ×1
call ×1
excel ×1
function ×1
javascript ×1
jquery ×1
literals ×1
timer ×1
vb.net ×1