【发布时间】:2016-10-17 18:11:06
【问题描述】:
我尝试将日志记录页面写入我的“项目”。我找到了一些基于会话状态的解决方案。这是一个非常简单的项目并且工作正常,但是当我在我的代码中实现它时它不起作用。它看不到 POST 方法的值,它们是空的。我的项目中唯一的区别是我使用了 MasterPage 和占位符...这会以某种方式影响数据流吗?
找到项目 - 控件
<form id="form1" runat="server">
<asp:Panel ID="Panel1" runat="server" BackColor="#FFE0C0" Height="50px" Width="192px">
<asp:Label ID="Label1" runat="server" Text="login"></asp:Label>
<asp:TextBox ID="TBlogin" runat="server"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="hasło"></asp:Label>
<asp:TextBox ID="TBhaslo" runat="server" TextMode="Password"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Zaloguj się!" Width="190px" PostBackUrl="loguj.aspx" />
</asp:Panel>
<asp:SqlDataSource ID="SDSUzytkownik" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringSklep %>" SelectCommand="SELECT * FROM [uzytkownik] WHERE (([login] = @Log) AND ([haslo] = @Has))">
<SelectParameters>
<asp:FormParameter DefaultValue="""" FormField="TBlogin" Name="Log" />
<asp:FormParameter DefaultValue="""" FormField="TBhaslo" Name="Has" />
</SelectParameters>
</asp:SqlDataSource>
<br />
<asp:Label ID="LComment" runat="server" Text="Label" Visible="False"></asp:Label><br />
<br />
<asp:FormView ID="FVUzytkownik" runat="server" CellPadding="4" DataKeyNames="userID"
DataSourceID="SDSUzytkownik" ForeColor="#333333" OnDataBound="FVUzytkownik_DataBound">
<ItemTemplate>
Hello
<asp:Label ID="imieNazwiskoLabel" runat="server" Text='<%# Bind("imieNazwisko") %>'></asp:Label>!<br />
<br />
Your login:
<asp:Label ID="loginLabel" runat="server" Text='<%# Bind("login") %>'></asp:Label><br />
Your email:
<asp:Label ID="emailLabel" runat="server" Text='<%# Bind("email") %>'></asp:Label><br />
</ItemTemplate>
</asp:FormView>
<asp:Label ID="LabelTEST" runat="server" Text="LabelTestujący"></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text="Label" Visible="False"></asp:Label>
</form>
后面的代码
protected void FVUzytkownik_DataBound(object sender, EventArgs e)
{
LabelTEST.Text = "Im in";
if (FVUzytkownik.Row != null)
{
Session["Logged"] = Request.Form["TBlogin"];
Panel1.Visible = false;
LZalogowanyJako.Text = "You are logged as:" + Session["Logged"];
LabelTEST.Text = "<br/>Im logged <br/><br/> databse ROW = " + FVUzytkownik.Row + "<br/><br/> Session = " + Session["Logged"] + " <br/><br/> Request Form Login = " + Request.Form["TBlogin"];
}
else if (Request.Form["TBlogin"] != null && Session["Logged"] == null)
{
LComment.Text = "Logging failed. Wrong pass.";
LComment.Visible = true;
LabelTEST.Text = "<br/>Loggin failed <br/><br/> databse ROW = " + FVUzytkownik.Row + "<br/><br/> Session = " + Session["Logged"] + " <br/><br/> Request Form Login = " + Request.Form["TBlogin"];
}
else {
LabelTEST.Text = "<br/> All failed <br/><br/> databse ROW = " + FVUzytkownik.Row + "<br/><br/> Session = " + Session["Logged"] + " <br/><br/> Request Form Login = " + Request.Form["TBlogin"];
}
}
我的代码 - 母版页上的占位符
<div class="content">
<form id="form1" runat="server" action="/acc/Log.aspx" method="post">
<asp:ContentPlaceHolder ID="middle" runat="server">
</asp:ContentPlaceHolder>
</form>
</div>
占位符内容
<asp:Content ID="Content2" ContentPlaceHolderID="middle" runat="server">
<h2>Logowanie</h2>
<table style="width: 100%;">
<tr>
<td>Login:</td>
<td class="auto-style1">
<asp:TextBox ID="loginInput" runat="server" placeholder="ImieNazwisko" Width="155px"></asp:TextBox>
</td>
</tr>
<tr>
<td>Pass:</td>
<td class="auto-style1">
<asp:TextBox ID="hasloInput" runat="server" placeholder="8 znaków" Width="155px" TextMode="password"></asp:TextBox>
</td>
</tr>
<tr>
<td> </td>
<td class="auto-style1">
<asp:ImageButton ID="zaloguj" runat="server" Height="40px" ImageUrl="~/images/zaloguj.png" PostBackUrl="/logowanie/Logowanie.aspx" />
</td>
</tr>
<tr>
<td>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [uzytkownicy] WHERE (([login] = @login) AND ([haslo] = @haslo))">
<SelectParameters>
<asp:FormParameter FormField="loginInput" Name="login" Type="String" />
<asp:FormParameter FormField="hasloInput" Name="haslo" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="FVUzytkownik" runat="server" CellPadding="4" DataKeyNames="userID"
DataSourceID="SqlDataSource1" ForeColor="#333333" OnDataBound="FVUzytkownik_DataBound" EnableModelValidation="True">
<ItemTemplate>
Hello!
<br />
Your login:
<asp:Label ID="loginLabel" runat="server" Text='<%# Bind("login") %>'></asp:Label><br />
<br />
Your email :
<asp:Label ID="emailLabel" runat="server" Text='<%# Bind("email") %>'></asp:Label><br />
</ItemTemplate>
</asp:FormView>
</td>
<td>
<asp:Label ID="LabelZalogowanyJako" runat="server" Text="message log "></asp:Label>
<br />
<asp:Label ID="LabelTEST" runat="server" Text="LabelTESTowanie"></asp:Label>
</td>
</tr>
</table>
</asp:Content>
和后面的代码一样
protected void FVUzytkownik_DataBound(object sender, EventArgs e)
{
LabelTEST.Text = "Im in";
if (FVUzytkownik.Row != null)
{
Session["Logged"] = Request.Form["TBlogin"];
Panel1.Visible = false;
LZalogowanyJako.Text = "You are logged as:" + Session["Logged"];
LabelTEST.Text = "<br/>Im logged <br/><br/> databse ROW = " + FVUzytkownik.Row + "<br/><br/> Session = " + Session["Logged"] + " <br/><br/> Request Form Login = " + Request.Form["TBlogin"];
}
else if (Request.Form["TBlogin"] != null && Session["Logged"] == null)
{
LComment.Text = "Logging failed. Wrong pass.";
LComment.Visible = true;
LabelTEST.Text = "<br/>Loggin failed <br/><br/> databse ROW = " + FVUzytkownik.Row + "<br/><br/> Session = " + Session["Logged"] + " <br/><br/> Request Form Login = " + Request.Form["TBlogin"];
}
else {
LabelTEST.Text = "<br/> All failed <br/><br/> databse ROW = " + FVUzytkownik.Row + "<br/><br/> Session = " + Session["Logged"] + " <br/><br/> Request Form Login = " + Request.Form["TBlogin"];
}
}
以及效果画面:
【问题讨论】:
标签: c# asp.net post master-pages placeholder