Checkbox checkedchanged事件没有autopostback = true [英] Checkbox checkedchanged event without autopostback = true

查看:94
本文介绍了Checkbox checkedchanged事件没有autopostback = true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I added checkbox control to the GridView column dynamically. On each GridView_RowBound() event, checkbox is being added to the column. Also defined, CheckBox_CheckedChanged event in the RowBound() event as below










<pre>Protected Sub GridviewChildItem_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)

    If e.Row.RowType = DataControlRowType.DataRow AndAlso Not String.IsNullOrEmpty(CRMSignCond) Then
        Dim lbValue As Label = DirectCast(e.Row.Cells(5).FindControl("lbValue"), Label)
        e.Row.Cells(5).Attributes.Add("onmousemove", "Show('" + lbValue.Text + "')")
        e.Row.Cells(5).Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor;Hide();")
    End If

    AddTemplateControls(Nothing, e)


End Sub
Private Sub AddTemplateControls(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
    Dim cbTargetSign As New CheckBox
    Dim rbConsolidate As New RadioButtonList
    Dim tbSignGrp As New TextBox

    cbTargetSign.ID = "chkSelect"
    cbTargetSign.AutoPostBack = False
    cbTargetSign.Checked = True
    rbConsolidate.ID = "rbConsolidate"
    tbSignGrp.ID = "tbSigningGroup"
    tbSignGrp.Width = 25
    If Not e.Row.RowIndex = -1 Then
        e.Row.Cells(6).Controls.Add(cbTargetSign)
        e.Row.Cells(4).Controls.Add(tbSignGrp)
        e.Row.Cells(7).Controls.Add(rbConsolidate)
    End If
    rbConsolidate.RepeatDirection = RepeatDirection.Horizontal
    rbConsolidate.Items.Add("Yes")
    rbConsolidate.Items.Add("No")
    rbConsolidate.Items(1).Selected = CBool(True)
    If cbTargetSign.Checked Then
        rbConsolidate.Enabled = False
    End If
    **AddHandler cbTargetSign.CheckedChanged, AddressOf cbTargetSign_CheckedChanged**
End Sub







Checkbox- CheckedChanged event.

<pre lang="vb">Public Sub cbTargetSign_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)

End Sub



每当我检查网格中的复选框时,checkChanged事件都不会触发。任何人都指导我如何解决这个问题?



注意:我不想将AutoPostBack的复选框设置为TRUE,因为它会使用默认值重新加载整个网格。 />


我尝试了什么:



我没有任何线索可以继续期待指导。


Every time, when i check the checkbox in the grid, checkedChanged event doesn't trigger. Anyone guide me how to resolve this ?

Note: I don't want to set AutoPostBack of checkbox to TRUE since it reloads the entire grid with default values.

What I have tried:

I am not having any clue to proceed further, expecting guidance.

推荐答案

你真的有几个选项,而正确的选项取决于你在CheckedChanged事件中做了什么。



1.将AutoPostBack设置为True,让页面完成其PostBack并处理任何需要完成的逻辑。



2 。可能会将您的网格放在UpdatePanel中。然后,您可以按照步骤1进行操作,但只会刷新面板内容而不是整个页面。



3.使用客户端jQuery或JavaScript控制改变。
You really have a couple of options and the right one depends on what you are doing in your CheckedChanged event.

1. Set AutoPostBack to True, let the page complete its PostBack and handle any logic that needs to be done.

2. Possibly look at placing your grid in an UpdatePanel. You can then follow step 1, but only the contents of the panel will be refreshed not the entire page.

3. Looking at using client side jQuery or JavaScript to control the change.


你需要更好地了解web和asp.net架构。您的服务器代码只运行生成html \ js然后发送到客户端执行,您的.net代码没有在浏览器内运行,它无法响应客户端事件。它只能在您执行回发时运行,这意味着将AutoPostBack设置为true并重新发布整个页面。如果您不希望在浏览器中刷新页面,则可以使用UpdatePanel将您的checkbox事件转换为ajax调用。页面生命周期仍将运行,但浏览器将仅更新UpdatePanel中的组件。除此之外,还有一个编写自己的ajax代码的案例。
You need to get a better understanding on web and asp.net architecture. Your server code only runs to generate html\js which is then sent to the client to execute, your .net code isn't running inside the browser, it can't respond to client events. It can only run when you do a postback which means setting AutoPostBack to true and having the whole page re-post. If you don't want the page refreshing in the browser you can use an UpdatePanel which converts your checkbox event into an ajax call instead. The page lifecycle will still run but the browser will only update the components in the UpdatePanel. Other than that it's a case of writing your own ajax code.


这篇关于Checkbox checkedchanged事件没有autopostback = true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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