問題: テキストを入力している asp.net Textbox があり、テキストの変更時にその値を変数に割り当てる必要がありますが、これは起こりません。
質問: Textbox から値を取得する最良の方法は何ですか?
C# コード:
protected void btnSourceConnect_Click(object sender, EventArgs e)
{
if (Util.Connection(SourceString, 0))
{
lblTesting.Text = "Working!";
}
else
{
lblTesting.Text = "It No Work";
}
}
protected void txtSourceServer_TextChanged(object sender, EventArgs e)
{
SourceString.DataSource = txtSourceServer.Text;
}
protected void txtSourceDatabase_TextChanged(object sender, EventArgs e)
{
SourceString.InitialCatalog = txtSourceDatabase.Text;
}
protected void txtSourceUN_TextChanged(object sender, EventArgs e)
{
SourceString.UserID = txtSourceUN.Text;
}
protected void txtSourcePass_TextChanged(object sender, EventArgs e)
{
SourceString.Password = txtSourcePass.Text;
}
Asp.Net コード:
<table style="width: 100%;Border:1px solid Black;">
<tr>
<td class="style1">
Source Server:</td>
<td class="style1">
<asp:TextBox ID="txtSourceServer" runat="server"
ontextchanged="txtSourceServer_TextChanged" AutoPostBack="True"></asp:TextBox>
</td>
<td class="style1">
Source Database:
</td>
<td class="style1">
<asp:TextBox ID="txtSourceDatabase" runat="server"
ontextchanged="txtSourceDatabase_TextChanged" AutoPostBack="True"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
User Name:
</td>
<td class="style1">
<asp:TextBox ID="txtSourceUN" runat="server"
ontextchanged="txtSourceUN_TextChanged" AutoPostBack="True"></asp:TextBox>
</td>
<td class="style1">
Password:
</td>
<td class="style1">
<asp:TextBox ID="txtSourcePass" runat="server"
ontextchanged="txtSourcePass_TextChanged" AutoPostBack="True"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
</td>
<td class="style1">
</td>
<td class="style1">
</td>
<td class="style1">
<asp:Button ID="btnSourceConnect" runat="server" Text="Test Connection"
onclick="btnSourceConnect_Click" />
</td>
</tr>
</table>