我有以下Xamarin.Forms.ContentPage类结构
public class MyPage : ContentPage
{
public MyPage()
{
//do work to initialize MyPage
}
public void LogIn(object sender, EventArgs eventArgs)
{
bool isAuthenticated = false;
string accessToken = string.Empty;
//do work to use authentication API to validate users
if(isAuthenticated)
{
//I would to write device specific code to write to the access token to the device
//Example of saving the access token to iOS device
NSUserDefaults.StandardUserDefaults.SetString(accessToken, "AccessToken");
//Example of saving the access token to Android device …Run Code Online (Sandbox Code Playgroud) 如何通过JavaScript重置asp.net验证控件?当前代码示例清除错误消息文本,但不重置下一个表单提交的验证控件.
var cv= document.getElementById("<%= MyValidationContorl.ClientID %>");
cv.innerHTML = '';
Run Code Online (Sandbox Code Playgroud)
更新:
这是表单的完整代码示例.我似乎无法在另一个表单提交中触发验证控件:
function ClearData() {
var cv = document.getElementById("<%= MyValidationContorl.ClientID %>");
cv.innerHTML = '';
}
<html>
<form>
<asp:TextBox id="MyTextControl" runat="server" />
<asp:CustomValidator ID="MyValidationContorl" runat="server" />
<input type="button" onclick="javascript:ClearCCData(); return false;" runat="server" />
</form>
</html>
Run Code Online (Sandbox Code Playgroud) 任何人都可以提供如何循环通过System.DirectoryServices.PropertyCollection并输出属性名称和值的示例?
我正在使用C#.
@JaredPar - PropertyCollection没有Name/Value属性.它有一个PropertyNames和Values,类型为System.Collection.ICollection.我不知道构成PropertyCollection对象的基线对象类型.
@JaredPar再次 - 我最初错误地标记了错误类型的问题.那是我的坏事.
更新: 基于Zhaph - Ben Duguid输入,我能够开发以下代码.
using System.Collections;
using System.DirectoryServices;
public void DisplayValue(DirectoryEntry de)
{
if(de.Children != null)
{
foreach(DirectoryEntry child in de.Children)
{
PropertyCollection pc = child.Properties;
IDictionaryEnumerator ide = pc.GetEnumerator();
ide.Reset();
while(ide.MoveNext())
{
PropertyValueCollection pvc = ide.Entry.Value as PropertyValueCollection;
Console.WriteLine(string.Format("Name: {0}", ide.Entry.Key.ToString()));
Console.WriteLine(string.Format("Value: {0}", pvc.Value));
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 使用System.Environment.OSVersion命名空间 确定托管ASP.NET应用程序的Microsoft OS的最佳方法是什么
我需要一个Windows XP,Windows Server 2003和Windows Vista的示例
这是我试图使用伪代码完成的
switch(/* Condition for determining OS */)
{
case "WindowsXP":
//Do Windows XP stuff
break;
case "Windows Server 2003":
//Do Windows Server 2003 stuff
break;
case "Windows Vista":
//Do Windows Vista stuff
break;
}
Run Code Online (Sandbox Code Playgroud) .NET 4.0中有一些非常棒的功能我想开始使用,但我还不乐意改变VS 2010.有没有办法在VS 2008中使用.NET 4.0 beta?
如何从mm格式的当前日期检索月份?(即"05")
这是我目前的代码:
var currentDate = new Date();
var currentMonth = currentDate.getMonth() + 1;
Run Code Online (Sandbox Code Playgroud) 我今天刚刚阅读了这篇文章,关于Microsoft如何决定System.Data.OrcaleClient从.NET 4.0库中删除命名空间.
我使用它作为我使用Oracle数据库的主要工具.
当我决定将我的应用程序从.NET 2.0升级到.NET 4.0时,在.NET 4.0框架中使用Oracle数据库会有哪些替代选项?
这是我的事务范围源代码的当前体系结构.第三个插件抛出.NET异常(不是SQL异常),它不会回滚前两个插入语句.我做错了什么?
编辑: 我从insert2和insert3中删除了try/catch.我还从insert1 try/catch中删除了异常处理实用程序并放入"throw ex".它仍然不会回滚事务.
编辑2:我在Insert3方法中添加了try/catch,并在catch语句中添加了"throw".它仍然不会回滚事务.
更新:根据我收到的反馈,"SqlHelper"类使用SqlConnection对象建立与数据库的连接,然后创建一个SqlCommand对象,将CommandType属性设置为"StoredProcedure"并调用SqlCommand的ExecuteNonQuery方法.
我也没有将Transaction Binding = Explicit Unbind添加到当前连接字符串.我将在下一次测试中添加它.
public void InsertStuff()
{
try
{
using(TransactionScope ts = new TransactionScope())
{
//perform insert 1
using(SqlHelper sh = new SqlHelper())
{
SqlParameter[] sp = { /* create parameters for first insert */ };
sh.Insert("MyInsert1", sp);
}
//perform insert 2
this.Insert2();
//perform insert 3 - breaks here!!!!!
this.Insert3();
ts.Complete();
}
}
catch(Exception ex)
{
throw ex;
}
}
public void Insert2()
{
//perform insert 2
using(SqlHelper sh …Run Code Online (Sandbox Code Playgroud) 我试图将ASP.NET GridView控件绑定到一个string数组,我得到以下项目:
在所选数据源上找不到名为"Item"的字段或属性.
我应该在GridView控件中使用asp:BoundField列的DataField属性的正确值是什么.这是我的源代码:
ASPX页面
<asp:GridView ID="MyGridView" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Item" />
<asp:CommandField ButtonType="Link" ShowSelectButton="true" SelectText="Click Me!" />
</Columns>
</asp:GridView>
Run Code Online (Sandbox Code Playgroud)
代码背后:
string[] MyArray = new string[1];
MyArray[0] = "My Value";
MyGridView.DataSource = MyArray;
MyGridView.DataBind();
Run Code Online (Sandbox Code Playgroud)
UPDATE
我需要AutoGenerateColumns设置属性,false因为我需要生成其他asp:CommandField列.我已更新我的代码示例以反映此方案
C#自发布以来一直困扰我的一件事是缺乏通用的IsNumeric函数.我知道如果一个值是数字,很难产生一个一站式解决方案.
我过去使用过以下解决方案,但这不是最佳实践,因为我生成一个异常以确定该值是否为IsNumeric:
public bool IsNumeric(string input)
{
try
{
int.Parse(input);
return true;
}
catch
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
这仍然是解决此问题的最佳方法,还是有更有效的方法来确定C#中的值是否为数字?
c# ×6
asp.net ×4
.net-4.0 ×2
javascript ×2
validation ×2
.net ×1
data-binding ×1
date ×1
gridview ×1
iis ×1
oracle ×1
oracleclient ×1
parsing ×1
reset ×1
transactions ×1
windows ×1
xamarin ×1
xamarin.ios ×1