「我有3個按鈕點擊按鈕使用java腳本div會出現每個div有不同的按鈕來保存一些數據在asp中。淨 頁,但它刷新整個頁面我想只刷新特定的股利和數據保存到我的分貝」我怎樣才能點擊按鈕裏面的div不刷新整個頁面asp.net C#
按鈕代碼
<asp:Button ID="btnConse" runat="server" CssClass="Button" AlternateText="1" Text="Consequence"
OnClientClick="ToggleDiv('Consequence');return false;" />
<asp:Button ID="btnTask" runat="server" CssClass="Button" AlternateText="1" Text="Task"
OnClientClick="ToggleDiv('Task');return false;" />
<asp:Button ID="Button4" runat="server" CssClass="Button" AlternateText="1" Text="Incident"
OnClientClick="ToggleDiv('Incident');return false;" />
Java腳本的
<script type="text/javascript">
function ToggleDiv(Flag) {
if (Flag == "Consequence") {
document.getElementById('divConsequence').style.display = 'block';
document.getElementById('divTask').style.display = 'none';
document.getElementById('divIncident').style.display = 'none';
}
else {
if (Flag == "Task") {
document.getElementById('divConsequence').style.display = 'none';
document.getElementById('divTask').style.display = 'block';
document.getElementById('divIncident').style.display = 'none';
}
else {
if (Flag == "Incident") {
document.getElementById('divConsequence').style.display = 'none';
document.getElementById('divTask').style.display = 'none';
document.getElementById('divIncident').style.display = 'block';
}
}
}
}
</script>
股利
<div id="divConsequence" style="display: none;">
<div class="TabTextHoriCenter">
<asp:Label ID="Label28" runat="server" Text="div Consequence"></asp:Label>
<asp:Button ID="btnSaveCon" runat="server" CssClass="Button" AlternateText="1" Text="Consequence" OnClick="btnSaveCon_Click" />
</div>
</div>
<div id="divTask" style="display: none;">
<div class="TabTextHoriCenter">
<asp:Label ID="Label33" runat="server" Text="div Task"></asp:Label>
<asp:Button ID="btnSaveTask" runat="server" CssClass="Button" AlternateText="1" Text="Task" OnClick="btnSaveTask_Click" />
</div>
</div>
<div id="divIncident" style="display: none;">
<div class="TabTextHoriCenter">
<asp:Label ID="Label34" runat="server" Text="div incident"></asp:Label>
<asp:Button ID="btnSaveInc" runat="server" CssClass="Button" AlternateText="1" Text="Incident" OnClick="btnSaveInc_Click" />
</div>
</div>
在此
的div有按鈕執行服務器操作
我怎麼能只刷新該div而不是整個頁面?
的.cs代碼
protected void btnAddFiles_Click(object sender, EventArgs e)
{
if (fuFile.HasFile)
{
FileUpload Custom = new FileUpload();
Custom = fuFile;
if (Session["FileUpload"] != null)
{
FileUpload[] fuu = (FileUpload[])Session["FileUpload"];
int cnt = 0;
for (int k = 0; k < fuu.Length; k++)
{
if (fuu[k] != null)
{
cnt++;
}
else
{
break;
}
}
fuu[cnt] = Custom;
Session["FileUpload"] = fuu;
}
else
{
FileUpload[] fuu = new FileUpload[100];
fuu[0] = Custom;
Session["FileUpload"] = fuu;
}
if (flag == 1)
{
FilesAttached.Value = "";
flag = 0;
}
FileInfo Finfo = new FileInfo(fuFile.PostedFile.FileName);
string Ext = Finfo.Extension.ToLower();
string f = fuFile.FileName.ToLower();
string fname = Session["CompanyID"].ToString() + Session["MyRiskArea"].ToString();
Session["time"] = String.Format(Global.yyyy_mmm_ddhh_mm_ss_tt.ToString(), DateTime.Now);
int i = Convert.ToInt32(Ext.Length);
String NewString = f.Remove(f.Length - i, i) + Session["time"].ToString();
string str = NewString + Ext;
fuFile.SaveAs(Server.MapPath(Global.AttachedFiles + "/" + str));
ht.Add(Session["time"].ToString(), f);
ht1.Add(Session["time"].ToString(), System.IO.Path.GetFullPath(fuFile.FileContent.ToString()));
dlIncidents.DataSource = ht;
dlIncidents.DataBind();
fuFile.Focus();
dlIncidents.Visible = true;
//BindGrid();
}
}
使用ajax .........! – Jai
你知道你可以做一個'else if'來代替else語句中的單獨部分 – Pete
使用UpdatePanel – gls123