本文介绍了当我点击asp.net按钮时TextBox.Text刚丢失数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<div id="contact-popup" class="popup">
<div class="popup-title">
<span></span>
</div>
<div class="popup-content">
<div class="gridholder">
<div class="grid grid-5 gutr_n">
<div class="pl20">
<p>
Please fill in the form below to contact us</p>
<div class="field">
<asp:TextBox ID="txtName" runat="server" CssClass="required input" Width="200px"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="txtName_TextBoxWatermarkExtender" runat="server"
Enabled="True" TargetControlID="txtName" WatermarkText="Full Name">
</cc1:TextBoxWatermarkExtender>
<%--<input type="text" name="name" id="name_field" value="Full Name*" class="required input"
data-placeholder="Full Name*">--%>
</div>
<br />
<div class="field">
<asp:TextBox ID="txtEmail" runat="server" CssClass="required email input" Width="200px"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server"
Enabled="True" TargetControlID="txtEmail" WatermarkText="Email Address">
</cc1:TextBoxWatermarkExtender>
<%--<input type="text" name="email" id="Text1" value="Email*" class="required email input"
data-placeholder="Email*">--%>
</div>
<br />
<div class="field">
<asp:TextBox ID="txtPhone" runat="server" CssClass="required input" Width="200px"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender2" runat="server"
Enabled="True" TargetControlID="txtPhone" WatermarkText="Phone No">
</cc1:TextBoxWatermarkExtender>
<%--<input type="text" name="phone" id="Text2" value="Telephone*" class="required input"
data-placeholder="Telephone*">--%>
</div>
<br />
<div class="field">
<asp:TextBox ID="txtCity" runat="server" CssClass="required input" Width="200px"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender4" runat="server"
Enabled="True" TargetControlID="txtCity" WatermarkText="City">
</cc1:TextBoxWatermarkExtender>
<%--<input type="text" name="title" id="Text3" value="Subject*" class="required input"
data-placeholder="Subject*">--%>
</div>
<br />
<div class="field">
<asp:TextBox ID="txtAddress" runat="server" CssClass="required input"
Width="300px" Height="100px" TextMode="MultiLine"></asp:TextBox>
<%--<textarea name="content" id="Textarea1" cols="30" rows="5" class="required input"
data-placeholder="Message*" runat="server">Message*</textarea>--%>
</div>
<br />
<div class="field">
<asp:TextBox ID="txtZipCOde" runat="server" CssClass="required input"
Width="200px"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender5" runat="server"
Enabled="True" TargetControlID="txtZipCOde" WatermarkText="ZIP Code">
</cc1:TextBoxWatermarkExtender>
<%--<textarea name="content" id="Textarea1" cols="30" rows="5" class="required input"
data-placeholder="Message*">Message*</textarea>--%>
</div>
<br />
<div class="field">
<asp:TextBox ID="txtCountry" runat="server" CssClass="required input"
Width="200px" data-placeholder="Message*"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender6" runat="server"
Enabled="True" TargetControlID="txtCountry" WatermarkText="Country">
</cc1:TextBoxWatermarkExtender>
<%--<textarea name="content" id="Textarea1" cols="30" rows="5" class="required input"
data-placeholder="Message*">Message*</textarea>--%>
</div>
<br />
<div class="field">
<asp:TextBox ID="txtState" runat="server" CssClass="required input"
Width="200px" data-placeholder="Message*"></asp:TextBox>
<cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender7" runat="server"
Enabled="True" TargetControlID="txtState" WatermarkText="State">
</cc1:TextBoxWatermarkExtender>
<%--<textarea name="content" id="Textarea1" cols="30" rows="5" class="required input"
data-placeholder="Message*">Message*</textarea>--%>
</div>
<br />
<div class="field">
<asp:Button ID="btnBuy" runat="server" Text="Buy Package"
CssClass="button small gray tupper fr mr80" onclick="btnBuy_Click"
UseSubmitBehavior="False"/>
<%--<button type="submit" class="button small gray tupper fr mr80">
Submit</button>--%>
</div>
</div>
</div>
<div class="grid grid-7">
<div class="bdl_d pl30 dotted-vertical-left">
<div id="map">
</div>
<div class="dotted pt10 mt10 mb10">
</div>
<div class="contact">
<h3 class="h-3 red dblock smaller">
Packages</h3>
<p id="address">
</p>
</div>
<div class="contact">
<h3 class="h-3 red fl smaller">
Tel:</h3>
<p id="phone">
</p>
</div>
<div class="contact">
<h3 class="h-3 red fl smaller">
Fax:</h3>
<p id="fax">
</p>
</div>
<div class="contact">
<h3 class="h-3 red fl smaller">
Email:</h3>
<p id="email">
</p>
</div>
<div class="pb40">
</div>
</div>
</div>
<div class="cf">
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#contact-form .input').each(function() {
$(this).blur(function() {
if ($(this).val() == '') {
$(this).val($(this).attr('data-placeholder'));
}
});
$(this).focus(function() {
if ($(this).val() == $(this).attr('data-placeholder')) {
$(this).val('');
}
});
});
$('ul.contacts li a.contact').click(function() {
var contact = $(this).parent().find('span.data');
$('#phone').text(contact.attr('data-phone'));
if (contact.attr('data-fax') == '') {
$('#fax').parent().hide();
} else {
$('#fax').text(contact.attr('data-fax'));
$('#fax').parent().show();
}
$('#address').html(contact.attr('data-address'));
$('#email').text(contact.attr('data-email'));
$('#contact-form #location').val(contact.attr('data-id'));
$('#contact-popup .popup-title span').text(contact.attr('data-title'));
$("#contact-popup").dialog( "open" );
return false;
});
$('#contact-popup').dialog({
modal: true,
width:970,
autoOpen:false,
position:['center', 120],
open: function(){
var address = $('#address').html();
var geocode_address = address.replace(/'/g,"");
geocode_address = geocode_address.replace('<br>', ',');
initializeMap(geocode_address);
$('#name_field').blur();
}
});
$.validator.messages.required = '';
$('#contact-form').validate();
var urlHashPart = window.location.hash;
/*
if(urlHashPart) {
var contactOpen = urlHashPart.substr(1);
$('ul.contacts li a.contact[rel='+contactOpen+']').click();
}
*/
$('table td:nth-child(2) a,table td:nth-child(3) a,table td:nth-child(4) a').click(function(e){
e.preventDefault();
var link = $(this).attr('href');
var explode = link.split('#');
var country_id = explode[1];
$('ul.contacts li a.contact[rel='+country_id+']').click();
})
});
//$('input[placeholder], textarea[placeholder]').placeholder();
/*
$(window).bind('hashchange', function() {
var urlHashPart = window.location.hash;
var contactOpen = urlHashPart.substr(1);
$('ul.contacts li a.contact[rel='+contactOpen+']').click();
});
*/
</script>
<script type="text/javascript">
$('ul#news-list').carouFredSel({
items : {
visible : 3
},
auto : {
delay : 8000
},
scroll : 1,
direction : 'down',
next : "#news-prev",
prev : "#news-next"
});
</script>
Also Code below
Also Code below
protected void Page_Load(object sender, EventArgs e)
{
txtAddress.Focus();
if (!Page.IsPostBack)
{
LoadAllPackage();
}
}
protected void btnBuy_Click(object sender, EventArgs e)
{
//ViewState["address"] = txtAddress.Text;
UserInformation entry = new UserInformation();
TextBox tx = FindControl("txtAddress") as TextBox;
entry.Address = ((TextBox)(FindControl("txtAddress"))).Text;
entry.Address = tx.Text.Trim();
entry.City = txtCity.Text.Trim();
entry.Country = txtCountry.Text.Trim();
entry.Email = txtEmail.Text.Trim();
entry.Name = txtName.Text.Trim();
entry.Mobile = txtPhone.Text.Trim();
entry.State = txtPhone.Text.Trim();
entry.ZIPCode = txtZipCOde.Text.Trim();
ClsUserInformation.InsertUserInformation(entry);
}
推荐答案
这篇关于当我点击asp.net按钮时TextBox.Text刚丢失数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!