Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I rewrite this post because I'm stuck on this code.
I'm trying to convert a string to an integer and string to a date. In the EXP_DATE see 1/1/0001 12:00:00 AM as default value,while in the ID_CUSTOMER see 0 and I need to visualize Textbox values.
The problem is that they are inside the textboxes, while I am debugging it seems as if it does not save the values inside the textboxes.
One of the two textboxes are generated automatically if I click a button inside a repeater that displays the cleinte code and company name data (this is displayed inside a label).


This is my code:

What I have tried:

VB.NET
Public Sub INSERT_EXP_DATE_TABLE()
    MyParm = cmd.Parameters.Add("@ID_CUSTOMER", SqlDbType.Int)
    MyParm.Value = CInt(txt_COD_CUSTOMER.Text)
    MyParm = cmd.Parameters.Add("@COMPANY_NAME", SqlDbType.NVarChar)
    MyParm.Value = lbl_COMPANY_NAME.Text
    MyParm = cmd.Parameters.Add("@EXP_DATE", SqlDbType.Date)
    MyParm.Value = CDate(txt_EXP_DATE.Text)
    Try 
        cmd.Connection = cn
        cmd.CommandText = "LST_INSERT_TABLE_01"
        cmd.CommandType = CommandType.StoredProcedure 
        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
        MsgBox("Date expired conferm", vbInformation)
    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        cn.Close()
    End Try
End Sub
VB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Dim data As New Class_LST_READ_TABLE()
        data.READ_TABLE(Repeater1)
    End If
End Sub

Protected Sub btn_FIELD_TABLE_AUTOMATIC_Click(sender As Button, e As EventArgs)
    Me.txt_COD_CUSTOMER.Text = sender.Attributes("data-cod-cli")
    Me.lbl_COMPANY_NAME.Text = sender.Attributes("data-rag-soc")
    Me.txt_EXP_DATE.Text = sender.Attributes("data-exp-date")
End Sub

Protected Sub btn_SAVE_Click(sender As Object, e As EventArgs)
    For Each item As RepeaterItem In Repeater1.Items
        Dim txt_EXP_DATE As TextBox = item.FindControl("TXT_EXP_DATE")
        If txt_EXP_DATE IsNot "" Then
            Dim insert As New Class_LST_INSERT_TABLE
            insert.INSERT_EXP_DATE_TABLE()
            Exit For
        Else
            Dim update As New Class_LST_UPDATE_TABLE
            update.UPDATE_EXP_DATE_TABLE()
            Exit For
        End If
    Next
End Sub
Posted
Updated 4-Sep-20 4:16am
v3
Comments
CHill60 4-Sep-20 6:39am    
As I said on your previous post, you are probably not handling the post back of the page. Share the code that is calling this function as well as the HTML for the page containing the textboxes. Can you also include your Page Load code.
DARK__FOXX 4-Sep-20 6:48am    
(Code moved to question)
Richard Deeming 4-Sep-20 9:31am    
I have moved your code to your question. In future, if you want to update your question, click the green "Improve question" link to edit it.
Richard Deeming 4-Sep-20 9:35am    
NB: Your question is tagged ASP.NET, and you have included what looks like the code-behind from a WebForms page.

MsgBox will not work in an ASP.NET application. It might appear to work when you debug your code in Visual Studio, but that's only because in this specific instance the server and client are the same computer.

Once you deploy your application to a real server, one of two things will happen. In the best case scenario, MsgBox will throw an exception telling you that it can't be used from a non-interactive application. The alternative is that the message will pop up on the server, where nobody will ever see it, and your code will hang waiting for an administrator to log in to your server and acknowledge potentially hundreds of messages.
DARK__FOXX 4-Sep-20 9:53am    
Thanks for reply. I didn't know that Msgbox doesn't work with ASP.NET,so where can I find some resource about how to display error through server?

I only want to try to make this method work, I have tried them all and tried to follow your advices based on my basic knowledge.

1 solution

Quote:
I didn't know that Msgbox doesn't work with ASP.NET,so where can I find some resource about how to display error through server?

The problem is that MsgBox does work - but it works on the Server because all VB code is executed there. Since the user isn't sitting at the Server but the Client, he can;t see any message (and in fact doesn't get his page updated because the Server is waiting for a user that isn't there to click an "OK" button he can't see.)
It appears to work in development because the server and client are the same machine. In production, they could be thousands of miles / kilometers apart.

Instead, use Window alert() Method[^] to talk to the user, or a control on your page.
 
Share this answer
 

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