html页面调用default.aspx.vb并将Ispostback设置为false [英] html page calls default.aspx.vb and gets Ispostback false

查看:104
本文介绍了html页面调用default.aspx.vb并将Ispostback设置为false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个ASP HTML页面,允许用户将数据输入到网页中.当他们单击提交按钮时,它将调用default.aspx.vb. ISPostback始终为false,因此会跳过我的sql add参数.这是代码:

Hi,
I have an asp html page that allows the user to input data into a web page. When they click the submit button it calls a default.aspx.vb. The ISPostback is always false so it skips my sql add parameters. Here is the code:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="default.aspx.vb" Inherits="_default"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>GDR Request Form</title>

    <script src="Scripts/jquery-1.8.2.js" type="text/javascript"></script>
    <script src="Scripts/jQuery.maskedinput.js" type="text/javascript"></script>

    <link href="Styles/style2.css" rel="stylesheet" type="text/css" />
</head>

<body>

    <form id="form1" runat="server">

    <div id="content" style="text-align:center" >
         <table class="ftitle2" >
             <tr>
                 <td style="text-align:left" width="295px">
                     Organization name (if different from the Sponsor):</td>
                 <td>
                     <asp:TextBox ID="txtOrganization" runat="server" Width="466px"></asp:TextBox>

                 </td>
                 <td width="25px">
                     Date:</td>
                 <td>
                     <asp:TextBox ID="txtRequester_Date" runat="server" width="70px"

                        ToolTip="Please Enter The Request Date. (MM/DD/YYYY)"></asp:TextBox>
                 </td>
             </tr>
        </table>

        </table>
         <asp:Button ID="Button1" runat="server" Text="Submit" />
         <br />

    </div>





'***************************************************************************
'default.aspx.vb
'***************************************************************************
Imports System.Data.SqlClient
Imports System.Data

Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles Me.Load

        txtRequester_Date.Text = Date.Today
        txtRequestDate.Text = Date.Today

        If (IsPostBack) Then
            ' this creates the connection.
            Dim sqlConn As New SqlConnection("Data Source=JITC-PC\GEOINT; Initial catalog=DEV_GEOINT; Integrated Security=SSPI;")
            ' create the command object
            Dim sqlCmd As New SqlCommand("sp_InsertRequest", sqlConn)
            ' define the connection for the command object
            sqlCmd.Connection = sqlConn
            sqlCmd.CommandType = CommandType.StoredProcedure
            ' define the SQL parameter
            sqlCmd.Parameters.AddWithValue("@Org", txtOrganization.Text)
            sqlCmd.Parameters.AddWithValue("@REQ_Date", txtRequester_Date.Text)
            ' open the connection
            sqlConn.Open()
            ' execute the data insertion
            sqlCmd.ExecuteNonQuery()
            ' close SQL connection
            sqlConn.Close()
            ' dispose of the connection object (mostly optional but good practice)
            sqlConn.Dispose()
            ' Notify the submission was accepted
            Response.Write("Thank-you for your Request!")
        End If
    End Sub

    Private Function isempty(ByVal p1 As Object) As String
        Throw New NotImplementedException
    End Function

End Class

推荐答案

第一件事,为什么要在页面加载中编写逻辑?您正在通过按钮单击提交页面-定义单击处理程序,并在该单击事件方法中将保存数据写入DB逻辑中.

顺便说一句,请记住将AutoEventWireUp设置为"true"以处理自动点击事件.
First thing, why to write a logic in pageload? You are submitting a page via button click - define click handler and write the save data in DB logic in that click event method.

BTW, do remember to set AutoEventWireUp to ''true'' to have automatic click event handled.


这篇关于html页面调用default.aspx.vb并将Ispostback设置为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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