Follow by Email

Monday, 7 January 2013

Update panel using trigger in VB.Net

.aspx Page:


 <asp:UpdatePanel ID ="updt1" runat ="server" >
                                                    <ContentTemplate >

                                                    <asp:TextBox ID="txtHomeEmail" runat="server" Width="100%" AutoPostBack="True"></asp:TextBox>
                                                    </ContentTemplate>
                                                    <Triggers >
                                                    <asp:AsyncPostBackTrigger ControlID ="txtHomeEmail" EventName ="TextChanged" />
                                                    </Triggers>
                                                    </asp:UpdatePanel>


Then code behind page:


Protected Sub txtHomeEmail_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtHomeEmail.TextChanged


        'Code which you want to perform on text change

        Dim strEmailCheck As String
        strEmailCheck = "select home_email from patients where home_email='" & txtHomeEmail.Text & "'"
        Dim objCmdEmailCheck As New SqlClient.SqlCommand()
        objCmdEmailCheck.Connection = objConn
        objCmdEmailCheck.CommandTimeout = Application("CommandTimeout")
        objCmdEmailCheck.CommandText = strEmailCheck

        Dim ObjEmailCheckSet As New DataSet()
        Dim objEmailCheckRs As New SqlClient.SqlDataAdapter(objCmdEmailCheck)
        objEmailCheckRs.Fill(ObjEmailCheckSet)

        Dim ObjEmailCheckTable As DataTable
        ObjEmailCheckTable = ObjEmailCheckSet.Tables(0)

        If ObjEmailCheckTable.Rows.Count > 0 Then
            Dim textForMessage As String
            textForMessage = "<script language='javascript'> alert('Email Id already exist')</script>"
            Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "UserPopup", textForMessage)

            txtHomeEmail.Text = ""


        End If



    End Sub

0 comments:

Post a Comment


                                                            

 
Design by Abhinav Ranjan Sinha