没有得到变量从网页...提交到数据库 [英] Not getting variables from page... to submit to database

查看:178
本文介绍了没有得到变量从网页...提交到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获得该页面的帖子提交到我的网页的值。

I am unable to get the values that the page posts to submit to my page.

形式可能是一个有点混乱,但基本上在页面加载它显示的内容......如果在用户登录它显示了一个编辑按钮,他们可以单击它改变了以我的形式,他们可以编辑页。

The form probably is a bit confusing but basically on page load it shows the content... if a user in logged in it shows an edit button they are able to click which changes the view to my form where they can edit the page.

然后,单击保存按钮从而将数据提交到数据库中。

Then they click the save button which in turn submits the data to the database.

下面是我提交表单。

<asp:Content ID="Content4" ContentPlaceHolderID="Title" Runat="Server">
  <asp:MultiView ID="TitleLanguage" runat="server">
                <asp:View ID="EnglishT" runat="server"><asp:Label ID="en_title" runat="server"/></asp:View>
                 <asp:View ID="FrenchT" runat="server"><asp:Label ID="fr_title" runat="server"/></asp:View>
       <asp:View ID="EditT" runat="server">
                    <asp:TextBox ID="Edit_EnglishT" runat="server" />
                    <asp:TextBox ID="Edit_FrenchT" runat="server" />
       </asp:View>
      </asp:MultiView>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="PageContent" Runat="Server">
    <asp:LoginView runat="server" ID="EditLoginView"><LoggedInTemplate><div id="logged">
        <asp:Button ID="EditButton" runat="server" OnClick="btnEdit_Click" Text="Edit Page" CssClass="loggedbutton" PostBackUrl="~/page.aspx"/>
        <asp:Button ID="SaveButton" runat="server" OnClick="btnSave_Click" visible="false" Text="Save" CssClass="loggedbutton" PostBackUrl="~/page.aspx" UseSubmitBehavior="true" />
    </div>
</LoggedInTemplate></asp:LoginView>
   <asp:MultiView ID="LanguageView" runat="server">
                <asp:View ID="English" runat="server"><asp:Label ID="en_content" runat="server"/></asp:View>
                 <asp:View ID="French" runat="server"><asp:Label ID="fr_content" runat="server"/></asp:View>
       <asp:View ID="Edit" runat="server">
<h1>English Page</h1>
                   <asp:TextBox ID="Edit_English" runat="server" TextMode="MultiLine" Height="400px" />
<h1>French Page</h1>
                   <asp:TextBox ID="Edit_French" runat="server" TextMode="MultiLine" Height="400px" />
       </asp:View>
   </asp:MultiView>
</asp:Content>

下面是code我用得到的变量。

Here is the code I'm using to get the variables.

 protected void btnSave_Click(object sender, EventArgs e)
{
    Button EditButton = (Button)EditLoginView.FindControl("EditButton");
    Button SaveButton = (Button)EditLoginView.FindControl("SaveButton");



        //update the file in the database
    String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["randolphConnectionString"].ConnectionString;
using(SqlConnection con = new SqlConnection(strConnString))
using(SqlCommand cmd = con.CreateCommand())
{ 
        string strQuery = " UPDATE pages  SET en_content = @en_Content, fr_Content = @fr_content, fr_Title=@fr_title, en_Title=@en_title, last_update=@last_update WHERE link_title = @link";
            cmd.CommandText= strQuery;
            cmd.Parameters.Add("@en_title", SqlDbType.VarChar).Value = Edit_EnglishT.Text;
            cmd.Parameters.Add("@fr_title", SqlDbType.VarChar).Value = Edit_FrenchT.Text;
            cmd.Parameters.Add("@en_content", SqlDbType.VarChar).Value = Edit_English.Text;
            cmd.Parameters.Add("@fr_content", SqlDbType.VarChar).Value = Edit_French.Text;
            cmd.Parameters.Add("@last_update", SqlDbType.DateTime).Value = DateTime.Now;
            cmd.Parameters.Add("@link", SqlDbType.VarChar).Value = linktitle;
            cmd.Connection.Open();
            cmd.ExecuteNonQuery();
        TitleLanguage.ActiveViewIndex = 0;
        LanguageView.ActiveViewIndex = 0;
        EditButton.Visible = true;
        SaveButton.Visible = false;
        loadpage();

}

我是新来的ASP.NET,所以我试图用我所知道的关于ASP经典拉......基本上我缺少的是部分的request.form ...任何帮助将是巨大的!

I'm new to asp.net so I'm trying to use what I know about asp classic to pull... basically what i'm missing is the request.form section... Any help would be great!

推荐答案

想通了!当我于linktitle变量调用它根本不存在,因为即使我宣布它当网页被刷新它删除的变量公共变量。

Figured it out! When I was calling upon the linktitle variable it didn't exist because even though I declared it as a public variable when the page was refreshing it erased the variable.

通过将信息在一个隐藏字段围绕这工作...我敢肯定有另一种方式来做到这一点,但我无法弄清楚如何。

Worked around that by placing the information in a hidden field... I'm sure there is another way to do this but I couldn't figure out how.

这篇关于没有得到变量从网页...提交到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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