小编Mic*_*ern的帖子

在Xamarin.Forms中编写设备平台特定代码

我有以下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)

c# xamarin.ios xamarin.android xamarin xamarin.forms

22
推荐指数
3
解决办法
3万
查看次数

通过javascript重置asp.net验证控件?

如何通过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)

javascript asp.net validation reset

21
推荐指数
3
解决办法
3万
查看次数

如何遍历PropertyCollection

任何人都可以提供如何循环通过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)

c# asp.net iis directoryservices

20
推荐指数
3
解决办法
3万
查看次数

使用Environment.OSVersion确定操作系统

使用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)

c# windows asp.net

18
推荐指数
2
解决办法
2万
查看次数

我可以在Visual Studio 2008中使用.NET 4.0 beta吗?

.NET 4.0中有一些非常棒的功能我想开始使用,但我还不乐意改变VS 2010.有没有办法在VS 2008中使用.NET 4.0 beta?

.net-4.0 visual-studio-2008

18
推荐指数
2
解决办法
1万
查看次数

在javascript中以mm格式获取月份

如何从mm格式的当前日期检索月份?(即"05")

这是我目前的代码:

var currentDate = new Date();
var currentMonth = currentDate.getMonth() + 1;
Run Code Online (Sandbox Code Playgroud)

javascript date

17
推荐指数
3
解决办法
5万
查看次数

System.Data.OracleClient命名空间已停止?

我今天刚刚阅读了这篇文章,关于Microsoft如何决定System.Data.OrcaleClient从.NET 4.0库中删除命名空间.

我使用它作为我使用Oracle数据库的主要工具.

当我决定将我的应用程序从.NET 2.0升级到.NET 4.0时,在.NET 4.0框架中使用Oracle数据库会有哪些替代选项?

oracle oracleclient .net-4.0

14
推荐指数
1
解决办法
2万
查看次数

TransactionScope不回滚事务

这是我的事务范围源代码的当前体系结构.第三个插件抛出.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)

.net c# transactions transactionscope

12
推荐指数
2
解决办法
2万
查看次数

将ASP.NET GridView控件绑定到字符串数组

我试图将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# asp.net data-binding gridview

11
推荐指数
3
解决办法
3万
查看次数

C#中缺少IsNumeric函数

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# validation parsing

11
推荐指数
4
解决办法
6994
查看次数