小编Esp*_*spo的帖子

在回发上设置viewstate

我按下按钮时尝试设置ViewState变量,但它只在我第二次单击按钮时才有效.这是代码隐藏:

protected void Page_Load(object sender, EventArgs e)
{
    if (Page.IsPostBack)
    {
        lblInfo.InnerText = String.Format("Hello {0} at {1}!", YourName, DateTime.Now.ToLongTimeString());
    }
}

private string YourName
{
    get { return (string)ViewState["YourName"]; }
    set { ViewState["YourName"] = value; }
}


protected void btnSubmit_Click(object sender, EventArgs e)
{
    YourName = txtName.Text;

}
Run Code Online (Sandbox Code Playgroud)

有什么我想念的吗?这是设计文件的表单部分,就像POC一样非常基本:

<form id="form1" runat="server">
<div>
Enter your name: <asp:TextBox runat="server" ID="txtName"></asp:TextBox>
<asp:Button runat="server" ID="btnSubmit" Text="OK" onclick="btnSubmit_Click" />
<hr />
<label id="lblInfo" runat="server"></label>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)

PS:样本非常简单,"使用txtName.Text而不是ViewState"不是正确答案,我需要将信息放在ViewState中.

asp.net viewstate postback

5
推荐指数
1
解决办法
4180
查看次数

为什么页脚项目不包含在Repeater.Items中?

我需要从按钮的OnClick事件中的FooterTemplate内的文本框中获取值.我的第一个想法是遍历我的转发器上的items-property,但正如您在此示例中所看到的,它只包含实际的数据绑定项,而不是页脚项.

ASPX:

<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
        Item<br />
    </ItemTemplate>
    <FooterTemplate>
        Footer<br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </FooterTemplate>
</asp:Repeater>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
Run Code Online (Sandbox Code Playgroud)

代码behind.cs:

protected void Page_Load(object sender, EventArgs e)
{
    ListItemCollection items = new ListItemCollection();
    items.Add("value1");
    items.Add("value2");
    Repeater1.DataSource = items;
    Repeater1.DataBind();
}

protected void Button1_Click(object sender, EventArgs e)
{
    System.Diagnostics.Debug.WriteLine(Repeater1.Items.Count);
}
Run Code Online (Sandbox Code Playgroud)

此代码只输出"2"作为计数,那么如何在footertemplate中引用我的文本框?

asp.net repeater footer

5
推荐指数
1
解决办法
5676
查看次数

如何在FCKeditor中动态更改图像上载路径*

我正在为我的FCKeditor使用ASP.NET二进制文件,并且需要在同一页面上插入两个编辑器.上传的图像/浏览需要转到两个不同的目录,如何从代码隐藏中执行此操作?

我知道上传文件的路径是在config.ascx-file中使用UserFilesPath设置设置的,但我找不到从我的aspx.cs文件中覆盖此值的方法.

此外,我发现(冲突的)文档说明Session["FCKeditor:UserFilesPath"]可以设置,但我不喜欢将usercontrol特定信息放在全局会话变量中.

c# upload fckeditor

5
推荐指数
1
解决办法
6231
查看次数

如何允许用户选择多个文件进行上传?

Gmail刚刚发布了对其界面的更新,允许用户使用CTRL按钮选择多个文件进行上传.他们是怎么做到的?您可以阅读有关新功能的信息,并在此处查看屏幕截图:

http://gmailblog.blogspot.com/2009/02/updates-to-attachments-multi-select-and.html

html upload gmail

4
推荐指数
1
解决办法
952
查看次数

任何人使用Sendgrid的解析API与c#ASP.NET MVC

我将在我的MVC应用程序中构建一个解析控制器,并想知道是否有人已经这样做了.

http://sendgrid.com/docs/API_Reference/Webhooks/parse.html

.net c# email asp.net-mvc sendgrid

4
推荐指数
1
解决办法
5125
查看次数

单元测试silverlight它住在哪里?

我想用silverlight开始单元测试,一些在线样本使用以下语句

EnqueueCallback
EnqueueConditional
EnqueueTestComplete
Run Code Online (Sandbox Code Playgroud)

这些住在哪里?

silverlight location unit-testing

3
推荐指数
1
解决办法
513
查看次数

使用数据透视表时如何显示 Excel 2007 生成的 MDX?

标题说的差不多。在 Excel 2007 中使用数据透视表时,是否可以显示发送到 OLAP 源的 MDX?

ssas mdx pivot-table excel-2007

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

TDD.无论如何先测试?

你还在先做测试吗?或者在某些情况下,您正在进行一些编码,然后编写测试以确保代码有效?至于我,我更喜欢创建一个类.当然,在课堂创作过程中,我认为s interface and how to test the class. But I don首先要编写测试代码.你先写了吗?你认为你应该总是先写测试代码吗?

tdd unit-testing

1
推荐指数
1
解决办法
305
查看次数

查询很慢,在"dbcc freeproccache"之后变得很快.这可能是我的参数吗?

有问题的网站通常表现得相当不错,但随着时间的推移它变得越来越慢.

我们有一个巨大的查询来查找用户正在搜索的产品,它们大多采用以下形式:

WHERE ProductName LIKE @ProductName OR @ProductName IS NULL
  AND ProductGroup LIKE @ProductGroup or @ProductGroup IS NULL
  AND (...)
Run Code Online (Sandbox Code Playgroud)

这样,如果我们只搜索产品编号,我们就不必传递所有参数.这可能是查询变慢的原因吗?与第一次缓存查询有关的事情,以及下次参数更改时,它使用旧的查询计划?

如果是这样; 解决这个问题的最佳方法是什么?动态SQL?

t-sql sql-server parameters performance sql-server-2005

1
推荐指数
1
解决办法
1250
查看次数

为什么iTextSharp的GetTextFromPage会返回更长更长的字符串?

我正在使用iTextSharpnuGet(5.5.8)中的最新lib来解析pdf文件中的一些文本.我面临的问题是该GetTextFromPage方法不仅从页面返回应该返回的文本,还返回上一页中的文本.这是我的代码:

var url = "https://www.oslo.kommune.no/getfile.php/Innhold/Politikk%20og%20administrasjon/Etater%20og%20foretak/Utdanningsetaten/Postjournal%20Utdanningsetaten/UDE03032016.pdf";
var strategy = new SimpleTextExtractionStrategy();
using (var reader = new PdfReader(new Uri(url)))
{
    for (var page = 1; page <= reader.NumberOfPages; page++)
    {
        var textFromPage = PdfTextExtractor.GetTextFromPage(reader, page, strategy);
        Console.WriteLine(textFromPage.Length);
    }
}
Run Code Online (Sandbox Code Playgroud)

输出看起来像这样,这不是我需要的.我需要页面上实际显示的文字:

1106
2248
3468
4835
5167
6431
7563
8860
9962
11216
12399
13640
14690
15760
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

itextsharp pdf-scraping

1
推荐指数
1
解决办法
1438
查看次数

是否可以将传递给.NET方法的变量类型限制为不是派生类?

我可以通过在编译而不是运行时捕获此类错误的方式约束传递给我的方法的类型吗?

我当前的代码如下所示:

void Main()
{
    var dog = new Dog();
    SaveAnimal(dog);
}

void SaveAnimal(Animal animal) {
    var isAnimal = animal.GetType().UnderlyingSystemType == typeof(Animal);
    Debug.Assert(isAnimal, "You can not save dogs!");
}

class Animal {
    public int Legs { get; set; }
}

class Dog : Animal {
    public int TailLength { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

.net c#

1
推荐指数
1
解决办法
86
查看次数

Sql server 2005日期函数

我想知道怎么做不.在其他表中使用getdate()和现有日期的天数,其中该表包含多个记录,即我想知道5天前或10天后或15天后发布的作业.我写过这样的查询

declare @q1 datetime;
select cdate from jobposting where cdate like (select cdate)
select datediff ( dd, q1, getdate())
Run Code Online (Sandbox Code Playgroud)

其中q1必须存储jobposting表中的所有日期,但我无法得到正确的答案.

或者我也尝试过

select datediff ( dd, select cdate from jobposting, getdate())
Run Code Online (Sandbox Code Playgroud)

在提前感谢你.

t-sql sql-server-2005 date

0
推荐指数
1
解决办法
556
查看次数

C:比较两个字节以查看一个是否在另一个的某个范围内

我正在编写代码,比较代表整数的2个字节.我想看看字节R是否与G的+ -10相同.我对代码的问题是在结尾附近的if-statment中进行比较.字节永远不会超出范围,即使它们应该.我确定问题来自于我如何添加/减去error_range,但我不知道有任何其他方法可以做到这一点.

我首先考虑将字节转换为整数但我在网上找不到任何帮助.如果这比我在这里做的更好,请告诉我该怎么做.

任何帮助表示赞赏!

const char ERROR_RANGE = 0x1010; //warning: overflow in implicit constant conversion
char R, G; /2 separate bytes
char buffer; //enough space for 1 byte

image = fopen(fileName,"r"); //open file

fread(&buffer, 1, 1, image); //read 1 byte  
memcpy (&R,&buffer,1); //store it as R

fread(&buffer, 1, 1, image); //read 1 byte   
memcpy (&G,&buffer,1); //store it as G

fclose(image);

if((R >= (G + ERROR_RANGE)) && (R <= (G - ERROR_RANGE)))
{
    printf("Outside of range!\n");
}
Run Code Online (Sandbox Code Playgroud)

谢谢.

c byte

0
推荐指数
2
解决办法
2293
查看次数