开发者

Calling Javascript Method From asp.net page

I have a webview showing asp.net page. I cant set value asp.net label or any control from andriod side by Javascript calling but if the page is in html then i can set value to any html control. Does anybody know why this problem occurred

Here is my code:

StringBuilder buf=new StringBuilder("javascript:document.getElem开发者_如何学GoentById('lblStartTime').innerHTML='");
buf.append(mTimeDisplay);           
buf.append("';");       
webview.loadUrl(buf.toString()); 

And on aspx file:

<asp:Label ID="lblStartTime" runat="server" ClientIDMode="Static" Text="00:00"></asp:Label>

I have tried with any other control of asp.net even html tag span. label too.


Your ASP .NET control almost certainly has a different client ID to the server-side ID you have given it. An easy way to verify this is to view the source of your generated web page.

If you're using .NET 4.0, you'll have more control over the ID that ASP .NET creates for your client-side tags.

If not, the ClientID property of each control will tell you what the ID is on the client side. Use this instead of the server ID to access your elements via Javascript.

StringBuilder buf=new StringBuilder("javascript:document.getElementById('" + lblStartTime.ClientID "').innerHTML='");
buf.append(mTimeDisplay);           
buf.append("';");       
webview.loadUrl(buf.toString());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜