在回发使用 jQuery 显示隐藏的 div 后,我遇到了问题。有人建议我将可见性值存储在隐藏字段中,但我遇到了一些问题。继承人的代码:
<script type="text/javascript">
$(document).ready(function () {
$(".slidingDiv").hide();
$(".show_hide").show();
$("goBtn").click(function () {
$(".slidingDiv").slideToggle();
});
return false;
});
</script>
<div class="create">
<asp:TextBox ID="createTextbox" runat="server" Width="350px" Height="22px"></asp:TextBox>
<asp:ImageButton ID="goBtn" ImageUrl="img/goBtn.gif" runat="server" BorderStyle="None" onclick="createButton_Click"/>
</div>
<div class="slidingDiv" runat="server">
<asp:HiddenField ID="IsCreatePostbackVisible" runat="server" Visible="False" value="false"/>
<asp:Literal ID="Literal1" runat="server"></asp:Literal><br />
</div>
代码隐藏:
protected void createButton_Click(object sender, ImageClickEventArgs e)
{
string randAlias = Base62Random();
string aliasInput = createTextbox.Text;
DateTime date = DateTime.Now;
DateTime endDate = (DateTime.Now.AddYears(5));
string UserID = HttpContext.Current.User.Identity.Name.ToUpper();
string aliasType = "alias";
if (aliasInput == "")
{
ClientScript.RegisterClientScriptBlock(GetType(), "Javascript", "<script>alert('You must enter a valid URL')</script>");
}
else
{
Literal1.Text = "<a href=http://go/" + randAlias + ">go/" + randAlias;
}
using (DataClasses1DataContext dc1 = new DataClasses1DataContext())
{
tblData tblData = new tblData();
tblData.ALIAS_ID = randAlias;
tblData.URL = aliasInput;
tblData.START = date;
tblData.END = endDate;
tblData.USER = UserID;
tblData.TYPE = aliasType;
dc1.tblDatas.InsertOnSubmit(tblData);
dc1.SubmitChanges();
}
}