locked
How to Fire Textchange from modal popup RRS feed

  • Question

  • User-308948172 posted

    Hi ,

    Is it possible to trigger the textchange event of a page from a modal popup?

    Here's what I have User Control inside a Modal popup

    GridView User Control is wrap with update panel so that I can update My TxtName

    Passing Gridview SelectedItem to my TxtName.Text

        Protected Sub Select_Clicked(ByVal sender As Object, ByVal e As EventArgs)
            Dim currentrow As GridViewRow = TryCast(DirectCast(sender, Control).Parent.NamingContainer, GridViewRow)
    
            CType(Me.Parent.Parent.FindControl("txtId"), TextBox).Text = currentrow.Cells(1).Text
            CType(Me.Parent.Parent.FindControl("txtName"), TextBox).Text = currentrow.Cells(2).Text
    
            CType(Me.Parent.Parent.FindControl("MPE"), AjaxControlToolkit.ModalPopupExtender).Hide()
    
        End Sub

    Value successfully pass but txtName.TextChanged event didn't fire Yell

        <asp:UpdatePanel runat="server" ID="UpdateFace" UpdateMode="Conditional">
            <ContentTemplate>
                 <asp:TextBox ID="txtName" runat="server" ReadOnly="True" AutoPostBack="true" />
            </ContentTemplate>
        </asp:UpdatePanel>

    //Nothing happen even on debug mode

     Protected Sub txtName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtName.TextChanged
    //Some Operation
    Me.btnUpdate.Enabled = True End Sub

    Monday, February 3, 2014 1:32 AM

Answers

  • User1734617369 posted

    Hi,

    That is a bit tricky, what you need to do is to add an event in your user control, like this for example:

    Public Class WebUserControl1
        Inherits System.Web.UI.UserControl
    
        Public Event RaiseTextChanged As EventHandler
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            CType(Me.Parent.Parent.FindControl("txtName"), TextBox).Text = "OK"
            RaiseEvent RaiseTextChanged(Nothing, EventArgs.Empty)
        End Sub
    
    End Class

    and in your page you need to handle that event:

    Public Class WebForm1
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Protected Sub txtName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtName.TextChanged
    
    
        End Sub
    
        Private Sub CheckEvent() Handles UC1.RaiseTextChanged
            txtName_TextChanged(Nothing, EventArgs.Empty)
        End Sub
    
    End Class

    and in that event handler you can trigger the TextChanged for the textbox.

    /Johan

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 4, 2014 4:05 AM

All replies

  • User2103319870 posted

    Hi,

    You dont have a TextChanged EventHandler attached to your button. Due to this server side code wont get executed 

    Please try with the code given below

    HTML:

     <asp:TextBox ID="txtName" runat="server" ReadOnly="True" AutoPostBack="true" OnTextChanged="txtName_TextChanged" />

    Code Behind

    Protected Sub txtName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtName.TextChanged
    //Some Operation
            Me.btnUpdate.Enabled = True
        End Sub

    Monday, February 3, 2014 1:53 AM
  • User1734617369 posted

    Hi,

    The TextChanged event won't be triggered if you assign a value to the textbox programatically, it is triggered if the textbox loses focus and the text has changed on the client side.

    Best regards
    Johan

    Monday, February 3, 2014 3:09 AM
  • User-308948172 posted

    still not working.. :(

        <asp:UpdatePanel runat="server" ID="UpdateFace" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:TextBox ID="txtName" runat="server" ReadOnly="True" AutoPostBack="true" OnTextChanged="txtName_TextChanged" />
            </ContentTemplate>
        </asp:UpdatePanel>



    Monday, February 3, 2014 3:46 AM
  • User-308948172 posted

    Hi Johan, Any Suggestion on how to trigger it programmatically

    Best regards,

    Ron

    Monday, February 3, 2014 3:47 AM
  • User1734617369 posted

    Hi,

    You can call it as txtName_TextChanged(null, EventArgs.Empty) for example.

    /Johan

    Monday, February 3, 2014 6:31 AM
  • User-308948172 posted

    Hi,

    You can call it as txtName_TextChanged(null, EventArgs.Empty) for example.

    /Johan

    Hi valuja

    Can I call it inside my User Control ?

    Tuesday, February 4, 2014 12:37 AM
  • User1734617369 posted

    Hi,

    That is a bit tricky, what you need to do is to add an event in your user control, like this for example:

    Public Class WebUserControl1
        Inherits System.Web.UI.UserControl
    
        Public Event RaiseTextChanged As EventHandler
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            CType(Me.Parent.Parent.FindControl("txtName"), TextBox).Text = "OK"
            RaiseEvent RaiseTextChanged(Nothing, EventArgs.Empty)
        End Sub
    
    End Class

    and in your page you need to handle that event:

    Public Class WebForm1
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Protected Sub txtName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtName.TextChanged
    
    
        End Sub
    
        Private Sub CheckEvent() Handles UC1.RaiseTextChanged
            txtName_TextChanged(Nothing, EventArgs.Empty)
        End Sub
    
    End Class

    and in that event handler you can trigger the TextChanged for the textbox.

    /Johan

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, February 4, 2014 4:05 AM
  • User-308948172 posted

    Wow Surprised

    That really works BIG Thanks to valuja. 

    BTW

    I was attract with

    valuja

    That is a bit tricky, what you need to do is to add an event in your user control, like this for example:

    Do you have suggestion in your mind which won't be tricky?

    Im very interested with this kind of topic 

    Tuesday, February 4, 2014 4:23 AM
  • User1734617369 posted

    Not really, when you like to call methods or trigger events between page and user controls they need to know of each other in some way so it is just a matter of taste on how to do it, either as this with an event in the user control that is hanldes by the parent or with a public method in the parent that can be called by the user control in some way.

    /Johan

    Tuesday, February 4, 2014 4:37 AM
  • User-308948172 posted

    Hmm thanks a lot Johan hope you can still help me in the future :)

    BTW,

    Can you give me a suggestion with this Thread

    http://forums.asp.net/t/1965393.aspx?Dataset+xsd

    Thanks

    Regards,

    Ron

    Tuesday, February 4, 2014 5:42 AM