在XAML中我可以这样写:
<Setter Property="PropertyName" Value="{Binding ...}" />
Run Code Online (Sandbox Code Playgroud)
我将如何在代码中执行此操作?我之前在代码中构造了绑定,但我似乎无法ValueProperty在Setter类上找到任何要传递给它的静态对象BindingOperations.SetBinding().
我知道愚蠢的问题,但我试着在谷歌上查找它没有运气.
我是ASP.NET MVC 1.0的新手.我正在转换使用VS2008 .NET3.5构建的经典应用程序.我创建了一个母版页,必须从数据库中读取菜单.现在,在经典ASP.NET3.5 VS2008中生成HTML到相应菜单div的代码是在母版页的代码背后.
我现在无法理解母版页的代码在ASP.NET MVC 1.0中的位置?
有人有例子吗?
谢谢
我在页面上有一个标签,当文本框中的文本被更改时,我正在更新标签的文本属性(带有计算值).
我正在更新标签:
$myLabel.text("123");
Run Code Online (Sandbox Code Playgroud)
文本正在屏幕上正确显示但是当我尝试将文本值保存到后面代码中的对象时(当我按下按钮时)标签的文本属性为""而不是"123".
代码背后:
var myLabel = myLabel.Text;
//the var myLabel is "" when it should be "123"
Run Code Online (Sandbox Code Playgroud)
关于为什么会这样的任何想法?
提前致谢,
跳越
我们有一个页面可以创建客户账单的可打印版本.我们正在使用主题<pages styleSheetTheme="CityDesign">.此页面未使用母版页,也没有与之关联的样式表.我已添加<%@ Page Language="C#" EnableTheming="false" Theme="" %>到页面和protected void Page_PreInit(object sender, EventArgs e) { Page.Theme = String.Empty;}后面的代码.页面仍然应用了主题.我究竟做错了什么?
我有一个asp.net页面,我有以下标记.基本上,这个标记是通过从表中读取记录并循环遍历代码来生成的.对于表中的每条记录,都会有一个div块.
基本上,此表单用于读取/显示用户的设置.设置条目存储在表格中.
<div id='divContainer' runat='server'>
<div id='div1' runat='server'>
<table>
<tr>
<th>Name</th>
<td><input type='text' id='txtName1' value='something' /></td>
</tr>
</table>
</div>
<div id='div2' runat='server'>
<table>
<tr>
<th>Domain name</th>
<td><input type='text' id='txtName2' value='something' /></td>
</tr>
</table>
</div>
<div id='div3' runat='server'>
<table>
<tr>
<th>URL</th>
<td><input type='text' id='txtName3' value='something' /></td>
</tr>
</table>
</div>
<div id='div4' runat='server'>
<table>
<tr>
<th>Some other value is enabled ?</th>
<td><input type='checkbox' id='chk4' /></td>
</tr>
</table>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
每个输入元素的id都是唯一的.现在在代码隐藏中,我想读取每个输入元素的值以保存用户所做的更改.我怎样才能阅读这里的元素?由于标记在代码隐藏中生成为字符串并附加了外部div的INNER HTML,因此我无法读取像我们在IDE中拖放的控件那样的值.
我有一个用户控件中使用的Xaml,用作属性网格中的编辑器.问题是,从后面的代码中附加行为的c#会是什么样子?
<i:Interaction.Behaviors>
<igExt:XamComboEditorSelectedItemsBehavior SelectedItems="{Binding SelectedItems, ElementName=_uc}"/>
</i:Interaction.Behaviors>
Run Code Online (Sandbox Code Playgroud)
因为这是在一个动态加载到PropertyGrid中的编辑器上,所以我只是创建一个编辑器实例,其中包含来自代码的绑定,而不是必须拥有非常简短且只包含一个编辑器的不同xaml文件.
或者更简单地重新实现行为中的所有代码并在我在后面的代码中创建编辑器时调用它?
我有一个带有Form元素(<form runat="server">)的母版页,一个带有Button元素(<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Sync" />)的内容页面,以及一个包含该Button1_Click函数的Code Behind页面.
用户进入页面并单击按钮.Code Behind代码执行(在服务器上),它在其中更新数据库中的某些表.Code Behind代码所做的最后一件事是InnerHTML在内容页面上设置Span元素,并显示成功或失败消息.
一切都很好.问题是如果用户刷新页面,则重新提交表单,浏览器会询问是否真的是用户想要的.如果用户回答是肯定的,则重新执行Code Behind代码并再次更新数据库.如果用户反应消极,则没有任何反应.
重新执行代码背后的代码并不是什么大问题.它不会伤害任何东西.但这并不是我想要的行为.
我知道我可以使用Response.Redirect()重定向回页面,但用户永远不会看到我的成功或失败消息.我应该提一下,消息实际上不仅仅是"成功"或"失败",否则我想我可以在Redirect上的QueryString中添加一些内容.
有没有办法从Code Behind代码重置Form元素,以便如果用户刷新页面,表单不会重新提交?
主页......
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="IntuitSync.SiteMaster" %>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:ipp="">
<head runat="server">
</head>
<body>
<form runat="server">
<div runat="server" id="mainContetntDiv">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
内容...
<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.master" CodeBehind="SyncToCloud.aspx.cs" Inherits="IntuitSync.SyncToCloud" %>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Sync" />
<span runat="server" id="SyncStatus"></span>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
守则背后......
using System; …Run Code Online (Sandbox Code Playgroud) 对于我的 Xamarin Forms 项目(最新版本 1.3),当我在 Xamarin Studio(最新版本,5.5.4)中创建视图时,我将视图定义如下:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="FormsDemo.Register">
<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="First Name" />
<Entry x:Name="FirstName" Grid.Row="0" Grid.Column="1" />
<Label Grid.Row="1" Grid.Column="0" Text="Last Name" />
<Entry x:Name="LastName" Grid.Row="1" Grid.Column="1" />
<Label Grid.Row="2" Grid.Column="0" Text="Email" />
<Entry x:Name="Email" Grid.Row="2" Grid.Column="1" />
<Button x:Name="SaveButton" Grid.Row="3" Grid.Column="0" Text="Login" />
</Grid>
</ContentPage.Content>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
但是,在我的代码隐藏中,根本找不到任何对其名称的控件的引用。以下代码出错(由注释指出):
using System;
using System.Collections.Generic;
using …Run Code Online (Sandbox Code Playgroud) 假设我的ID为"Input1","Input2"和"Input3".
有没有办法循环它们,而不是必须写:
Input1.Value = 1;
Input2.Value = 1;
Input3.Value = 1;
Run Code Online (Sandbox Code Playgroud)
在jquery中你可以只引用像$('#Input'+ i)这样的元素并循环遍历i,类似的东西在后面的ASP代码中非常有用.