我之前問過一個關於JavaScript代碼的問題,您可以在這裏看到它:How can I scroll down to a multiline TextBox's bottom line, Javascript's scrollIntoView is not working for this。那麼,它被解決了,並且接受的答案正在起作用。JavaScript方法在ASP.NET用戶控件中不起作用
後來我不得不搬到代碼部分,你可以在這個問題到用戶控制哪些終於看起來像這樣看:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LiveChatPart.ascx.cs" Inherits="BeyzamComArayuz.LiveChatUserControl.LiveChatPart" %>
<%@ Register src="/LiveChatUserControl/GenelOdaFlashPart.ascx" tagname="GenelOdaFlash" tagprefix="gOF" %>
<script language="javascript" type="text/javascript">
function buttonClicked() {
// var el = document.getElementById("TxtBxOdaMesajlari");
var textBox = $get("TxtBxOdaMesajlari");
textBox.scrollTop = textBox.scrollHeight;
// $get("TxtBxOdaMesajlari").scrollIntoView("false");
}
</script>
<asp:ScriptManager ID="ScrptMngr" runat="server"></asp:ScriptManager>
<tr>
<gOF:GenelOdaFlash runat="server"></gOF:GenelOdaFlash>
<td valign="top" align="left">
<table>
</table>
</td>
<td valign="top" align="left">
<table>
<tr>
<td>
buraya imajlar gelecek - chip vs.
</td>
</tr>
<tr>
<td>
<asp:ListBox ID="LstBxOdadakiKullanicilar" runat="server"
Width="175" Height="281" Enabled="false">
<asp:ListItem Value="1" Text="Bir"></asp:ListItem>
</asp:ListBox>
</td>
</tr>
<tr>
<td>
<asp:UpdatePanel ID="UpdtPnlButtonlar" runat="server">
<ContentTemplate>
<table>
<tr>
<td>
<asp:Button ID="ButtonOdadanCik" runat="server" Text="Odadan Çık" Width="175" Height="22" />
<asp:Button ID="ButtonHediyeGonder" runat="server" Text="Hediye Gönder" Width="175"
Height="22" />
<asp:Button ID="ButtonFullEkran" runat="server" Text="Full Ekran" Width="175" Height="22" />
<table>
<tr>
<td>
<asp:Panel ID="PnlKontroller" runat="server" GroupingText="Kontroller"
Visible="false">
<table>
<tr>
<td>
<asp:Label ID="LblChatTuru" runat="server" Text="Ücretsiz!"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Button ID="BttnSohbetTuruDegistir" runat="server"
Width="175" Text="Sohbet Türü Değiştir"
OnClick="BttnSohbetTuruDegistir_click" />
<asp:Button ID="BttnMolaVer" runat="server"
Width="175" Text="Mola Ver" OnClick="BttnMolaVer_click" />
</td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="ButtonOzelSohbet" runat="server" Text="Özel Sohbet" Height="108"
Width="175" OnClick="ButtonOzelSohbet_click" />
<asp:Panel ID="PnlOzelSohbetKamera" runat="server" Visible="false">
<asp:Label ID="asd" runat="server" Text="zsa"></asp:Label>
<div id="ozelOdaKamera" style="height: auto; float: left;">
<script type="text/javascript" src="/jwplayer/swfobject.js"></script>
<script type="text/javascript">
// For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection.
var swfVersionStr = "11.1.0";
// <!-- To use express install, set to playerProductInstall.swf, otherwise the empty string. -->
var xiSwfUrlStr = "playerProductInstall.swf";
var flashvars = {};
var params = {};
params.quality = "high";
params.bgcolor = "#FFFFFF";
params.allowscriptaccess = "sameDomain";
params.allowfullscreen = "true";
var attributes = {};
attributes.id = "uyeOzelOdaKameraFlash";
attributes.name = "uyeOzelOdaKameraFlash";
attributes.align = "middle";
swfobject.embedSWF(
"/Images/uyeOzelOdaKameraFlash.swf", "ozelOdaKamera",
"220", "150",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
// <!-- JavaScript enabled so display the flashContent div in case it is not replaced with a swf object. -->
swfobject.createCSS("#flashContent", "display:block;text-align:left;");
</script>
</div>
</asp:Panel>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="padding-left:8px;">
<asp:UpdatePanel ID="UpdtPnlMesajlar" runat="server" EnableViewState="true">
<ContentTemplate>
<table>
<tr>
<td>
<table>
<tr>
<td>
<%--<div id="satir">--%>
<asp:TextBox ID="TxtBxOdaMesajlari" runat="server"
ReadOnly="true" TextMode="MultiLine"
Height="100" Width="350">
</asp:TextBox>
<%--</div>--%>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="TxtBxMesaj" runat="server" Width="285"></asp:TextBox>
<%--this is the button which should run the javascript function--%>
<asp:Button ID="BttnGonder" runat="server" Text="Gönder"
Width="58" OnClick="BttnGonder_click"/>
</td>
</tr>
</table>
</td>
<td valign="top">
<asp:Panel ID="PnlAktiviteKayitlari" runat="server"
Visible="false" GroupingText="Aktivite Kayıtları">
<table>
<tr>
<td valign="top">
<asp:ListBox ID="LstBxAktiviteKayitlari" runat="server"
Enabled="false" Width="128">
<asp:ListItem Value="1" Text="Bir giriş yaptı"></asp:ListItem>
</asp:ListBox>
</td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
而在asp.cs文件我有
protected void BttnGonder_click(object sender, EventArgs e)
{
string cariId = "";
if (KullaniciTuru == 1)
{
cariId = Session["ModelId"].ToString();
}
else
{
cariId = Session["UyeId"].ToString();
}
string uyeHesapAdi = BAL.Cari.Cari.GetCariHesapAdi(int.Parse(cariId));
string mesaj = uyeHesapAdi + " : " + TxtBxMesaj.Text;
TxtBxOdaMesajlari.Text = TxtBxOdaMesajlari.Text + Environment.NewLine + mesaj;
//TxtBxOdaMesajlari.Focus();
ScriptManager.RegisterStartupScript(this, this.GetType(), "txtbxmesajlarslide", "buttonClicked();", true);
TxtBxMesaj.Text = string.Empty;
}
我的問題是,buttonClicked()
功能不工作了,我試圖使用Page.ClientScriptManager.RegisterClientScriptInclude
從ScottS's answer和Page.ClientScript.RegisterClientScriptBlock
,他們都沒有工作。我該怎麼辦?
編輯:我試圖調試與IE9內置的調試器的網頁,把一個斷點在buttonClicked()
功能,但它從來沒有hit.Then我用OnClientClick
事件的按鈕,並添加buttonClicked功能,它它的工作原理對於每次點擊但文本框只是跳回到buttonClicked()
函數之前的位置。
哦嗨,先生,謝謝你,但這anything.That在更新前我現在檢查更新並沒有改變。 – Bastardo 2012-01-12 19:50:13
@RoboLover:你可能只需要使用'document.getElementById'而不是'$ get'(我已經修改了答案)。如果失敗了,您還可以嘗試我添加到答案中的代碼隱藏方法。 – 2012-01-12 19:52:37
那麼,我將不得不嘗試其他人現在不工作的代碼隱藏方法。謝謝你,我真的很感謝你的幫助。 – Bastardo 2012-01-12 19:58:33