Click here to Skip to main content
15,917,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to pass NoMatrik from gridview to txtUserId at another form(login form)

frmForm1


VB
Protected Sub gvSenaraiP_RowCommand(sender As Object, e As GridViewCommandEventArgs)
        If e.CommandName = "cmdSelect" Then
            Dim someScript As String
            If (Not ClientScript.IsStartupScriptRegistered(Me.GetType(), someScript)) Then
                ClientScript.RegisterStartupScript(Me.GetType(), someScript, "OpenWindow('frmLogin1.aspx','" & Session("strIdKaunseling") & "','" & Session("strNoMatrik") & "');", True)
            End If
        End If
    End Sub


frmLogin1


VB
Protected Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
        If Me.txtPassword.Text = "" Or Me.txtUserId.Text = "" Then

            UsrPwd = Me.txtPassword.Text
            UsrLogin = Session("strNoMatrik")
            EUsrPWD = EncryptPwd(UsrPwd)

            dbconn = New OleDb.OleDbConnection(strConClm)
            dbconn.Open()

            '---BACA TABLE CLM_PENGGUNA---
            sql = "SELECT CLM_LoginPwd,CLM_LoginID, CLM_UNama, CLM_Tahap, CLM_StatusPG, CLM_KP FROM CLM_Pengguna WHERE CLM_LoginID = '" & UsrLogin & "'"
            dbcomm = New OleDbCommand(sql, dbconn)
            dbread = dbcomm.ExecuteReader()
            dbread.Read()

            If dbread.HasRows = True Then
                If Replace(dbread("CLM_LoginPwd"), Chr(0), "*") = Replace(EUsrPWD, Chr(0), "*") Then
                    Dim someScript As String = ""

                    '---GLOBAL VARIABLE---
                    Session("strLoginID") = Me.txtUserId.Text

                    If (Not ClientScript.IsStartupScriptRegistered(Me.GetType(), someScript)) Then
                        ClientScript.RegisterStartupScript(Me.GetType(), someScript, "OpenWindow('Klien/frmForm2.aspx','" & Session("strIdKaunseling") & "','" & Session("strNoMatrik") & "');", True)
                    End If
                End If

                dbread.Close()
                dbcomm = Nothing
                dbconn.Close()
            End If
        Else
            MsgBox("Unauthorised access.")
        End If
    End Sub
Posted
Updated 12-Oct-14 21:56pm
v2
Comments
Sinisa Hajnal 13-Oct-14 2:42am    
Just to clarify: your frmForm2 opens, but its textbox is empty, right? And where are you setting value to that textbox?
U_Hanisa 13-Oct-14 3:56am    
Please check my updated code
U_Hanisa 13-Oct-14 2:53am    
Sorry..actually I don't know how to setting value to the textbox. I want to pass UserID from gridview at difference form to textbox at login form

you can use querystring and access the querystring in login form's page load to set the userID textbox.
 
Share this answer
 
Comments
U_Hanisa 13-Oct-14 4:41am    
Thank you. I'm a beginner of VB.Net, so I clueless about the coding. Can you give me the examples?
Sinisa Hajnal 13-Oct-14 4:44am    
You can easily find them. Part of getting from beginner to expert is by doing things yourself and researching.
Arora_Ankit 13-Oct-14 6:05am    
add following url on link button in grid 'login.aspx?id=<%# DataBinder.Eval(Container.DataItem, "UserID") %>'

in page load add this

var userID=Request.QueryString["id"] ?? string.Empty;
txtUserID.Text=userID;
This is C# code. same logic will work for you in VB
You can use Session object to store your login name. I wouldn't put it in querystring as that enables others to send your second form usernames directly without passing through validation login.

Example: Klien/frmForm2.aspx?userID=12 <-- this is guesswork, but one can try several tries until one passes.


You're setting that in this line:
C#
Session("strLoginID") = Me.txtUserId.Text

Now just use it in your Form2 like :
txtUserId.Text = Session("strLoginID").ToString();


There is a problem with your code. You're not sending password to be validated along with username...your password validation assumes there will be only one username returned for password to be validated. Why not send both username and password in the query?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900