When you specify an element in ASP.NET like this:
<asp:TextBox ID="TextBox1" runat="server">
You end up with an input box that has an ID with a generated name! Take a look for yourself, view source on the page, and you'll see that your input box "TextBox1" actually has an ID that looks like "ctl00_form1_TextBox1" or some jazz like that. So of course your getElementById call won't find any element with an ID of "TextBox1" - because there isn't one. Fortunately you can change this behavior. Just add a "ClientID" attribute, like so:
<asp:TextBox ID="TextBox1" runat="server" ClientIDMode="Static">
With that, your input box really will have the id "TextBox1", and you'll be able to get the value of it the way you were attempting to.
EDIT
So, the above doesn't apply to the problem in this question, apparently. What's happening is that the twitter widget thing is weird and makes it awkward if you want to use a dynamic ID.
When the twitter widget runs, it uses document.write() calls to construct the widget. So, if your web page is already there, document.write will just overwrite the page. The best thing I can think of to do is to load it in an iframe, then copy what was loaded in the iframe to wherever you want it on the page.
Rather than creating a separate page just to load the widget in an iframe, I tried to construct an iframe page dynamically. In the end, I came up with the below, which appears to work in Firefox 13, but doesn't work in IE 8, and I haven't tested it in later versions of IE. Possibly this method could be tweaked so as to load the widget in completely separate page generated by the server - or you could even just load it in an iframe and then place the iframe on the page in the place you want it to appear.
Anyway, after making all this I now hate the twitter widget. It's completely stupid. Why does it have to use document.write? Why can't it play nice and construct DOM objects so that other kids can play too? Whatever. Here's what I got, and I'll leave it at that:
<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<link href="//widgets.twimg.com/j/2/widget.css" rel="stylesheet" type="text/css">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<script type="text/javascript" charset="utf-8" src="http://widgets.twimg.com/j/2/widget.js"></script>
<script type="text/javascript">
function fn(usr) {
var ifr = document.createElement("iframe");
document.body.appendChild(ifr);
ifr.style.visibility = "hidden";
ifr.contentWindow.document.write("<script type=\"text/javascript\" charset=\"utf-8\" src=\"http://widgets.twimg.com/j/2/widget.js\"></" + "script>");
ifr.contentWindow.document.write("<script>" + fn2.toString() + ";</" + "script>");
ifr.contentWindow.document.write("<script>fn2('" + usr + "')</"+"script>");
ifr.contentWindow.document.close();
t = setInterval(function () {
if (ifr.contentWindow.document.readyState == "complete") {
clearInterval(t);
setTimeout(function () {
try {
var frame_styles = ifr.contentWindow.document.getElementsByTagName("style");
for (i = 0; i < frame_styles.length; i++) {
var newstyles = document.createElement("style");
newstyles.innerHTML = frame_styles[i].innerHTML;
document.body.appendChild(newstyles);
}
} catch (ex) { }
document.getElementById("sloc").innerHTML = ifr.contentWindow.document.body.innerHTML;
}, 1000);
}
}, 50);
}
function fn2(usr) {
new TWTR.Widget({
version: 2,
type: 'profile',
rpp: 4,
interval: 30000,
width: 250,
height: 300,
theme: {
shell: {
background: '#333333',
color: '#ffffff'
},
tweets: {
background: '#000000',
color: '#ffffff',
links: '#4aed05'
}
},
features: {
scrollbar: false,
loop: false,
live: false,
behavior: 'all'
}
}).render().setUser(usr).start();
}
</script>
<input type="text" id="txtfield" />
<asp:Button ID="Button1" Text="Click" OnClientClick="fn(document.getElementById('txtfield').value);return false;" runat="server" />
<div id="sloc"></div>
</asp:Content>