c# - 字面量不更新
问题描述
我有点新,所以还在学习。我有一个 AJAX 计时器,每秒用 SELECT 查询数据库。
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="SongTimer"
EventName="Tick" />
</Triggers>
<ContentTemplate runat="server">
<asp:Timer runat="server" ID="SongTimer" Enabled="false" OnTick="SongTimer_Tick" Interval="1000"></asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" UpdateMode="conditional" ID="updateVid">
<ContentTemplate>
<div id="player"></div>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="updpnl" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="SongTimer"
EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:HiddenField ID="hdnVideoID" ClientIDMode="Static" runat="server" />
<asp:Literal ID="litVideo" runat="server"></asp:Literal>
</ContentTemplate>
</asp:UpdatePanel>
然后我询问由包含在文字中的脚本设置的隐藏字段是否等于数据库返回的值。
protected void SongTimer_Tick(object sender, EventArgs e)
{
utils util = new utils();
string[] IDs = util.GetCurrentVideo(Convert.ToInt32(GroupID)).Split('=');
foreach (string id in IDs)
{
if (!id.Contains(".com"))
{
VideoID = id;
}
}
if (hdnVideoID.Value.Contains(VideoID))
{
return;
}
else {
hdnVideoID.Value = util.GetCurrentVideo(Convert.ToInt32(GroupID));
btnJoin_Click(null, null);
lblLink.Text = VideoID;
}
}
每次数据库更改时,它都会通过我的断点并检查我的函数,这些函数通过更改脚本来更改视频,但是,客户端上没有任何反应,即使应该更改运行脚本的文字。隐藏字段控件设置为静态,因此在脚本中引用得很好。任何帮助将不胜感激。谢谢你!
public void btnJoin_Click(object sender, EventArgs e)
{
UpdateFeed();
SongTimer.Enabled = true;
}
public void UpdateFeed()
{
utils util = new utils();
util.GetGroupDetails(Request.Params["id"].ToString(), ref GroupName, ref GroupDescription, ref ww, ref CurrentVideo, ref CurrentTimeFrame);
lblLink.Text = CurrentVideo;
hdnNewVideo.Value = CurrentVideo;
string FullURL = CurrentVideo;
hdnHasChanged.Value = "N";
string[] IDs = FullURL.Split('=');
CurrentTimeFrame = CurrentTimeFrame + 3.0;
VideoID = "";
foreach (string id in IDs)
{
if (!id.Contains(".com"))
{
VideoID = id;
}
}
string b = "";
b += "<script>";
b += " var tag = document.createElement('script');";
b += "";
b += " tag.src = \"https://www.youtube.com/iframe_api\";";
b += " var firstScriptTag = document.getElementsByTagName('script')[0];";
b += " firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);";
b += "";
b += " var player;";
b += " function onYouTubeIframeAPIReady() {";
b += " player = new YT.Player('player', {";
b += " height: '390',";
b += " width: '100%',";
b += " videoId: '" + VideoID + "',";
b += " events: {";
b += " 'onReady': onPlayerReady,";
b += " 'onStateChange': onPlayerStateChange";
b += " }";
b += " });";
b += " }";
b += "";
b += " function onPlayerReady(event) {";
b += " event.target.playVideo();";
b += " }";
b += " var done = false;";
b += " function onPlayerStateChange(event) {";
b += " if (event.data == YT.PlayerState.PLAYING && !done) {";
b += " GetCurrentTime();";
b += " SetTime();";
b += " done = true;";
b += " }";
b += " }";
b += " function stopVideo() {";
b += " player.stopVideo();";
b += " }";
b += "function SetTime(){player.seekTo(" + CurrentTimeFrame + ")}";
b += "function GetCurrentTime() {";
b += " var CurrentTime = player.getCurrentTime();";
b += " var CurrentVideo = player.getVideoUrl();";
b += "";
b += " document.getElementById('hdnTimeStamp').value = CurrentTime;";
b += " document.getElementById('hdnVideoID').value = CurrentVideo;";
b += " }";
b += " </script>";
litVideo.Text = b;
updpnl.Update();
}
解决方案
推荐阅读
- spock - 如何实施 Spock 参数化测试最佳实践?
- c# - 使用实体框架从oracle数据库中删除记录
- python - 列表中最接近的号码
- c++ - 如何让一个案例运行 N 次
- react-native - 排毒测试 React Native (Expo) + PouchDB 应用程序
- angular - 在任何按键角上执行功能
- r - 使用带有 knitr::kable 和 kableExtra::add_header_above 的 for 循环
- java - 无法在 Java for...循环中迭代对象
- generics - 处理惯用函数链中的空列表
- c++ - 可以捕获 std::vector 的重新分配吗?