需求是這樣的,當我們利用/ReportServer方式檢視Reporting Service報表,網頁上會自動產生輸入參數的TextBox WebControl,說穿了就是一個個<input type="text">,如果其中有些參數具有機密性,希望能以<input type="password">方式呈現,Reporting Service目前是無法支援的。

Reporting Service提供了兩種客製化報表檢視網頁的方法,第一種是用rs:Stylesheet Query String指定CSS檔,原本我找到了用body { background=url("javascript:...") }的做法,很不幸地,在IE7上,CSS裡內嵌的Javascript似乎會被忽略(應是基於安全的考量吧),所以只好轉向使用第二種做法,修改C:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting Services\ReportServer\Pages\ReportViewer.aspx。

我的構想是這樣的,我們以參數輸入提示文字中夾帶了(*)字樣作為信物,例如: "請輸入密碼(*)",在ReportViewer.aspx的最後方加入以下的Javascript Code,就可以為這些需要隱藏輸入內容的欄位新增一個<input type="password">的密碼輸入方格,在onblur時,將值填入真正的<input type="text">中。而為了避免真正的text input洩漏天機,可利用inp.style.postion="absolute"; inp.style.left="-1000px";的技巧把它藏到火星去。最後,由於password input沒有記憶功能,在Post-Back後會自動清空,所以我們要記得在每次Post-Back時將text input中的值抄回password input,如此,就大功告成了!

</form>
<script>

var tds=document.getElementsByTagName("TD");
for (var i=0; i<tds.length; i++) {
  var td=tds[i];
  if (td.className=="ParamLabelCell" && td.innerText.indexOf("(*)")>0)
  {
    td.innerText=td.innerText.replace("(*)","");
    var inpSpan=td.nextSibling.children[0];
    var origInp=inpSpan.children[0];
    var pwdInp=document.createElement("INPUT");
    inpSpan.appendChild(pwdInp);
    pwdInp=inpSpan.children[1];
    pwdInp.outerHTML="<INPUT type='password' onblur='document.all(\""
        + origInp.id +"\").value=this.value;' value='" + origInp.value + "' />";
    origInp.style.position="absolute";
    origInp.style.left="-1000px";
  }
}

</script>

其產生效果如下圖:


Comments

# by 蔡小芳

新手上路 時再找不到編譯完的report放哪阿 想懇請版主指導一下

# by Jeffrey

to 蔡小芳,不太明白你遇到的問題,"編譯完的report"所指為何?

# by 蔡小芳

不好意思 看來是我搞錯了 我以為以上那段語法是針對我要更改的那張報表,剛剛睡醒仔細看,原來是更改ReportViewer.aspx這支...好像不能只針對某張報表更改喔?

# by 蔡小芳

再請問一下版主,我剛剛有找到ReportViewer.aspx這支,也有把上面的script中的內容加上去,參數提示也改成請輸入密碼(*),可是好像沒有變耶,我不知道哪邊還要設定,懇請版主指導一下...

# by 蔡小芳

Report.aspx...剛剛發現我的報表不知道為啥路徑是這個,慘了,版主的東西是不是就不能用啦,慘...

Post a comment