可点击的WebControl,ASP.NET [英] Clickable Webcontrol, ASP.NET

查看:121
本文介绍了可点击的WebControl,ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问题是关于<一个href=\"http://stackoverflow.com/questions/10489552/creating-a-table-dynamically-with-multiple-lines-of-text-in-each-cell-and-each\">my最后一个问题如果你想要更多的背景信息。

This is question is in relation to my last question in case you want some more background information.

我的问题是:是否有可能使细胞在asp.net表可点击

My question is: Is it possible to make a cell in an asp.net Table clickable?

或者是它至少可能使一个可点击的WebControl(这应该是可能的一个的ControlCollection的地方),这不是一个按钮或一个LinkBut​​ton,在ASP.NET?
如果没有,是否有可能多行的信息到按钮上的文字?

Or Is it at least possible to make a clickable WebControl (which should be possible to place in a ControlCollection), that is not a Button or a LinkButton, in ASP.NET? And if not, is it possible to multiple lines of information into the button text?

我已经尝试添加其他组件按钮的ControlCollection(这是我见过的在Windows工作形式的按钮),看看我是否能渲染子组件到一个按钮,但没有成功:

I've tried adding other components to the button's ControlCollection (which I've seen working in the Windows Forms version of the Button), to see if I could render child components to a button, but without success:

private void ModifyTableCell(TableCell cell)
{
    //Create new button
    Button btnCell = new Button();
    btnCell.Click += (sender, args) =>
    {
        //Event for the button
    };

    //Create new Label
    Label lblCell = new Label();
    lblCell.Font.Bold = true;
    lblCell.Text = "This text won't appear";

    btnCell.Controls.Add(lblCell); //Attempt to add label to Button
    cell.Controls.Add(btnCell);
}

修改:最后我只是创造一个多行的LinkBut​​ton整个单元

EDIT: I ended up just creating a multi-lined LinkButton for the entire cell.

推荐答案

您应该能够通过分配的onclick 属性,使pretty太多的控制可以点击的,借力 __ doPostBack 功能。

You should be able to make pretty much any control clickable by assigning an onclick attribute and leveraging the __doPostBack function.

ctrl.Attributes["onclick"] = string.Format("__doPostBack('{0}', '{1}');", ctrl.ClientID, "SomeArgument");

您也可以使用 GetPostBackEventReference 方法了。此选项实际上是更安全,因为它会注册 __ doPostBack 函数它已不存在:

You could also use the GetPostBackEventReference method too. This option is actually safer, because it will register the __doPostBack function it doesn't already exist:

ctrl.Attributes["onclick"] = Page.ClientScript.GetPostBackEventReference(ctrl, string.Empty);

然后,在code-后面你可以简单地覆盖 RaisePostBackEvent 方法:

protected override void RaisePostBackEvent(IPostBackEventHandler source, string eventArgument)
{
    base.RaisePostBackEvent(source, eventArgument);

    if (eventArgument == "SomeArgument") //using the argument
    {
        //do whatever
    }
}

这篇关于可点击的WebControl,ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆