window.frames['iframeView'].location.href=document.getElementById('TextBox').value
2012年11月12日 星期一
asp.net ajax 彈不出alert對話框的解決辦法
vb 寫法ScriptManager.RegisterStartupScript(Button2, GetType(Button), "JavaScript_Sample1", "window.alert(""Hello!! Code Behind!!"")", True)
c# 寫法ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "message", "javascript:alert('" + "YouAre Msg" + "')", true);
-------------------------------------------
asp.net ajax 彈不出alert對話框的解決辦法
想用js腳本輸出一些提示,可是不管是用 Page.RegisterClientScriptBlock還是用 Page.RegisterStartupScript
注冊,該死的提示信息總是不出來。其實不是不出來,只是我們叫錯了它們的名字,我們只要用下面的這條語句︰
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "click", "alert('提示信息')", true);
就可以正常的彈出alert對話框了。
注︰如果在頁面中有多個UpdatePanel,如果每個UpdatePanel的UpdateMode都是“always”[默認值]的話,
那麼你使用那個UpdatePanel的實例作為參數都可以;如果每個UpdaePanel的UpdateMode=conditional,
那麼你必須使用正在更新的那個UpdatePanel作為參數,這樣腳本才能起作用。
所以...我把msg Function 改為..
///
/// display msg : msg("")
///
///
protected void AJAX_msg(string msgstr)
{
msgstr = msgstr.Replace("'", "").Replace("\n", "").Replace("\r", "").Replace('"', '”').Replace("(", "(").Replace(")", ")").Replace(";", ";");
string javastr = "alert('" + msgstr.ToString() + "' );\n";
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "AJAX_msg", javastr, true);
}
///轉載 網路上
ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "message", "javascript:alert('" + GetMsg.GetCode("W0834") + "')", true);
ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "message", "javascript:alert('" + "YouAre Msg" + "')", true);
---------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
string js="document.getElementById('btn').value='測試';";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), js, true);
}
js註冊在
底下,button上面,這時候button還沒載入,會出現js錯誤
如果您在Code-Behind寫了
protected void Page_Load(object sender, EventArgs e)
{
string js="document.getElementById('btn').value='測試';";
ScriptManager.RegisterStartupScript(this,this.GetType(),Guid.NewGuid().ToString(),js,true);
}
js註冊在button之後,
前面,因為這時候button已經載入,js的程式碼抓得到button目標,執行成功
如果是單純做頁面跳頁(window.location.href)
我都是用
RegisterClientScriptBlock,這樣使用者還沒看到畫面,頁面就已經跳頁
如果要抓取頁面上的DOM做處理,我都是用RegisterStartupScript 確保js一定抓得到頁面上的DOM
c# 寫法ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "message", "javascript:alert('" + "YouAre Msg" + "')", true);
-------------------------------------------
asp.net ajax 彈不出alert對話框的解決辦法
想用js腳本輸出一些提示,可是不管是用 Page.RegisterClientScriptBlock還是用 Page.RegisterStartupScript
注冊,該死的提示信息總是不出來。其實不是不出來,只是我們叫錯了它們的名字,我們只要用下面的這條語句︰
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "click", "alert('提示信息')", true);
就可以正常的彈出alert對話框了。
注︰如果在頁面中有多個UpdatePanel,如果每個UpdatePanel的UpdateMode都是“always”[默認值]的話,
那麼你使用那個UpdatePanel的實例作為參數都可以;如果每個UpdaePanel的UpdateMode=conditional,
那麼你必須使用正在更新的那個UpdatePanel作為參數,這樣腳本才能起作用。
所以...我把msg Function 改為..
///
/// display msg : msg("")
///
///
protected void AJAX_msg(string msgstr)
{
msgstr = msgstr.Replace("'", "").Replace("\n", "").Replace("\r", "").Replace('"', '”').Replace("(", "(").Replace(")", ")").Replace(";", ";");
string javastr = "alert('" + msgstr.ToString() + "' );\n";
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "AJAX_msg", javastr, true);
}
///轉載 網路上
ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "message", "javascript:alert('" + GetMsg.GetCode("W0834") + "')", true);
ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "message", "javascript:alert('" + "YouAre Msg" + "')", true);
---------------------------------------
protected void Page_Load(object sender, EventArgs e)
{
string js="document.getElementById('btn').value='測試';";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), js, true);
}
js註冊在
底下,button上面,這時候button還沒載入,會出現js錯誤
如果您在Code-Behind寫了
protected void Page_Load(object sender, EventArgs e)
{
string js="document.getElementById('btn').value='測試';";
ScriptManager.RegisterStartupScript(this,this.GetType(),Guid.NewGuid().ToString(),js,true);
}
js註冊在button之後,
前面,因為這時候button已經載入,js的程式碼抓得到button目標,執行成功
如果是單純做頁面跳頁(window.location.href)
我都是用
RegisterClientScriptBlock,這樣使用者還沒看到畫面,頁面就已經跳頁
如果要抓取頁面上的DOM做處理,我都是用RegisterStartupScript 確保js一定抓得到頁面上的DOM
2012年11月2日 星期五
RadioButton 使用javascript 在Gridview 中單選
//GridView OnRowDataBound
protected void grid_view_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
RadioButton rb = (RadioButton)e.Row.FindControl("RadioButton1");
rb.Attributes.Add("onclick", "judge(this)");//給RadioButton加onclick屬性
}
}
Dialog 開啟新視窗傳值
Step.1 page_load in code
this.Button1.Attributes.Add("OnClick", "return getRelPeople('" + this.returndata.ClientID.ToString() + "','" + this.Session["LoginID"].ToString() + "','" + this.Session["CASE_CUSTSYSID"].ToString() + "');");
Step.2 js
function getRelPeople(Target, LoginID, CUST_SYSID) {
var width = screen.availWidth;
var height = screen.availHeight - 50;
var returnValue = window.showModalDialog("CASE_BROW_GET_XXXXX.aspx?LoginID=" + LoginID + "&CUST_SYSID=" + CUST_SYSID + "&wType=Case&TFB_Table=CFW_ORDER_TABLE", 'TradeList', "scrollbars=yes;location=no;resizable=yes;help=no;status=no;dialogHeight:" + height + "px;dialogwidth:" + width + "px;");
if (returnValue != null) {
window.document.getElementById(Target).value = returnValue;
return true; //&ChkFlg=Y
}
return false;
}
Step.3 CASE_BROW_GET_XXXXX.aspx
.....
.....
.....
string returndata = this.ViewState["GETCUST"].ToString();
ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "message", "javascript:sent2('" + returndata + "');window.close();", true);
return;
Step.4 js
function sent2(seletedValue) {
window.returnValue = seletedValue;
}
GridView合併欄位
//GridView合併欄位 GridView加入OnPreRender事件
i =Rows ;j = Columns; Cells =
protected void grid_view_PreRender(object sender, EventArgs e)
{
for (int j = 2; j < 3; j++)
{
int i = 1;
foreach (GridViewRow wkItem in grid_view.Rows)
{
if (Convert.ToInt32(wkItem.RowIndex) == 0)
{
wkItem.Cells[j].RowSpan = 1;
wkItem.Cells[j+1].RowSpan = 1;
}
else
{
//if (wkItem.Cells[j].Text.Trim() == grid_view.Rows[Convert.ToInt32(wkItem.RowIndex) - i].Cells[j].Text.Trim())
if (((Label)wkItem.FindControl("lblGUAR_NM")).Text.Trim() == ((Label)grid_view.Rows[Convert.ToInt32(wkItem.RowIndex) - i].FindControl("lblGUAR_NM")).Text.Trim())
{
grid_view.Rows[Convert.ToInt32(wkItem.RowIndex) - i].Cells[j].RowSpan += 1;
grid_view.Rows[Convert.ToInt32(wkItem.RowIndex) - i].Cells[j+1].RowSpan += 1;
i = i + 1;
wkItem.Cells[j].Visible = false;
wkItem.Cells[j+1].Visible = false;
}
else
{
grid_view.Rows[Convert.ToInt32(wkItem.RowIndex)].Cells[j].RowSpan = 1;
grid_view.Rows[Convert.ToInt32(wkItem.RowIndex)].Cells[j+1].RowSpan = 1;
i = 1;
}
}
}
}
}
GridView RaidoButon Group 不複選
//RadioButton加入事件
OnCheckedChanged="RadioButton_CheckedChanged" AutoPostBack="true"
//RadioButton 事件CheckedChanged
protected void RadioButton_CheckedChanged(object sender, EventArgs e)
{
string RadioNowGUAR_SYSID = ((Label)((RadioButton)sender).NamingContainer.FindControl("lblGUAR_SYSID")).Text; //抓取當下RadioButton
string RadioNowACCT_DATA = ((Label)((RadioButton)sender).NamingContainer.FindControl("lblACCT_DATA")).Text; //抓取當下RadioButton
string tempGUAR_SYSID,tempACCT_DATA;
foreach (GridViewRow item in grid_view.Rows) //此為檢查是否有相同Group
{
if (((RadioButton)item.FindControl("RadioButton2")).Checked == true) //此為檢查是否為同Group
{
tempGUAR_SYSID = ((Label)item.FindControl("lblGUAR_SYSID")).Text;
tempACCT_DATA = ((Label)item.FindControl("lblACCT_DATA")).Text;
if (tempGUAR_SYSID == RadioNowGUAR_SYSID)
{
if (tempACCT_DATA != RadioNowACCT_DATA)
{
((RadioButton)item.FindControl("RadioButton2")).Checked = false;
}
}
}
}
}
訂閱:
文章 (Atom)