Basic simple dumb question

I

ItNerd

Someone PLEASE HELP ME!!!!!

All I want to do is a simple postback and grab the value from a textbox
on clicking a linkbutton like below, but the value is not writing to the
screen. I am frustrated with this seemingly simple task. I have
enabledviewstate=true on the @Page directive, and I tried using onclick
on the linkbutton, nothing. I know the event is firing because I can
set the value to a hardcoded string and get it to show. In addition, I
have the Page_Load

if (IsPostBack){UserNameLabel.Text = newUserName.Text;}

So I have no idea what the heck is the problem.





public void updateUserName(Object sender, CommandEventArgs e)
{

UserNameLabel.Text = newUserName.Text;

}

<form id=form1 runat=server>
<asp:panel ID="userNamePanel" EnableViewState=true Runat="server">
<TR>
<TD>
<asp:label id="UserNameLabel" EnableViewState=True
Runat="server"></asp:label></TD>
<TD>
<asp:textbox id="newUserName" EnableViewState=true
Runat="server"></asp:textbox></TD>
</TR>
</asp:panel>

<asp:panel ID="updatePanel" Runat="server">
<asp:linkbutton class="lnav1" id="updateUserNameLink"
CommandArgument="shit" OnCommand="updateUserName" runat="server"
Text="Update">
</asp:linkbutton>
</form>
 
R

Raterus

I can see some general errors you have
-Why do you have <tr> and <td> within the panel "userNamePanel"?
-You don't have a closing tag for panel "updatePanel"
 
I

ItNerd

Typos when I cut and paste. It is correct and when I test the event
using a hardcoded value rather than trying to grab the textbox value it
works fine.

I just want to grab the textbox value, and I am still frustrated.
Thanks in advance for any help you can provide.
 
R

Raterus

I think your problem is here

if (IsPostBack){UserNameLabel.Text = newUserName.Text;}

Don't do that, these constructs usually look like this

if (!IsPostBack)
{
// do procedures only to be done first time page is loaded
}

Then keep your updateUserName the same, hopefully will work then.
 
I

ItNerd

Thanks for the tip. I finally got it to work. The problem was
that I had <form> tags inside of my <form runat=server> tag.

I suppose the viewstate had no idea which form I meant to grab data from
and couldn't find it by the name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top