A beginner needs help!

  • Thread starter Chung Hang Shum
  • Start date
C

Chung Hang Shum

I'm a beginner in ASP.Net. I'd wroten mange asp code before and now I
need to transfer them from asp to asp.Net.
In classical ASP you can write code like this:

<% If strRequest = "ConfirmPasswd" then%>
<TABLE border="0" class="ContentArea" width="100%">
<TR><TD>Change Password?</TD></TR>
</TABLE>
<TABLE border="0" cellPadding="2" class="ContentArea" width="100%">
<TR><TD width="27">
<form method="post" action="MyPage.asp?action=DoPasswd" id=form3
name=form3>
<input type="submit" value="OK" id=submit2 name=submit2>
</form></TD><TD>
<form method="post" action="MyPage.asp">
<input type="submit" value="Cancel">
</form>
</TD></TR></TABLE>
<% ElseIf strRequest = "DoPasswd" Then%>
<TABLE border="0" cellPadding="2" class="ContentArea" width="100%">
<TR><TD colSpan=2>Your password is changed.<br>
Your new password is: <b><%=update_password%></b><br>
</TD></TR>
<TR><TD>
<form method="post" action="MyPage.asp">
<input type="submit" value="OK">
</form>
</TD></TR></TABLE>
<% ElseIf strRequest = "something" Then%>
...........
<% End if %>

How can I do this in ASP.Net? I write in C# and use code-behind.
I have tried Literal control, but it didn't work. All I got is a
hidden input field with name _ViewState.

Can somebody help me please?

Chung Hang Shum
 
D

Davide Vernole [MVP]

Chung Hang Shum said:
I'm a beginner in ASP.Net. I'd wroten mange asp code before and now I
need to transfer them from asp to asp.Net.
In classical ASP you can write code like this:

<% If strRequest = "ConfirmPasswd" then%>
<TABLE border="0" class="ContentArea" width="100%">
<TR><TD>Change Password?</TD></TR>
</TABLE>
<TABLE border="0" cellPadding="2" class="ContentArea" width="100%">
<TR><TD width="27">
<form method="post" action="MyPage.asp?action=DoPasswd" id=form3
name=form3>
<input type="submit" value="OK" id=submit2 name=submit2>
</form></TD><TD>
<form method="post" action="MyPage.asp">
<input type="submit" value="Cancel">
</form>
</TD></TR></TABLE>
<% ElseIf strRequest = "DoPasswd" Then%>
<TABLE border="0" cellPadding="2" class="ContentArea" width="100%">
<TR><TD colSpan=2>Your password is changed.<br>
Your new password is: <b><%=update_password%></b><br>
</TD></TR>
<TR><TD>
<form method="post" action="MyPage.asp">
<input type="submit" value="OK">
</form>
</TD></TR></TABLE>
<% ElseIf strRequest = "something" Then%>
..........
<% End if %>

How can I do this in ASP.Net? I write in C# and use code-behind.
I have tried Literal control, but it didn't work. All I got is a
hidden input field with name _ViewState.

Can somebody help me please?

Chung Hang Shum

First of all I suggest you to use this tutorial
http://www.asp.net/Tutorials/quickstart.aspx to be confident with ASP.NET.
In particular see differences between ASP and ASP.NET (PostBack paradigm,
etc).

To resolve your issue I propose you to use some panels webcontrol. Insert in
each panel the control you want to show in it. Than use the visible property
to show/hide the panel. For example you could have:

***ASPX***
<asp:panel id="pnlQuestion" runat="server" visible="true">
<asp:label id="lblChange" runat="server">Change Password ?</asp:label>
<br><br>
<asp:button id="btnConfirm" runat="server" /> &nbsp; <asp:button
id="btnBack" runat="server" />
</asp:panel>

<asp:panel id="pnlChange" runat="server" visible="false">
<asp:label id="lblMessage" runat="server">Your new password is:
</asp:label>
&nbsp; <asp:label id="lblNewPwd" runat="server" />
<br>
<br>
<asp:button id="btnOk" runat="server" />
</asp:panel>

In the code behind, in the method delegate for the btnConfirm click event,
you should have a snippet of code like this:

***Code Behind***
//code to calculate new password
this.pnlQuestion.Visible = false;
((label)this.pnlChange.FindControl("lblNewPwd")).Text = NewPassword;
this.pnlChange.Visible = true;

....and so on.

HTH
 
C

Chung Hang Shum

Thanks.
I did just as you said, but I can't set Text field in the label child
control.
All I get is:
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE"
value="dDwtMTY4NTYzMDIzMzs7bDxDaGFuZ2VQYXNzd2Q7VXBncmFkZTs+Pl9TZEjTS+jPjU73Z+pj93YE9F8i"
/>

<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
{
theform = document.forms["Password_change"];
}
else {
theform = document.Password_change;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
// -->
</script>


Why? What have I done wrong?

Chung Hang
 
D

Davide Vernole [MVP]

Chung Hang Shum said:
Thanks.
I did just as you said, but I can't set Text field in the label child
control.
All I get is:
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE"
value="dDwtMTY4NTYzMDIzMzs7bDxDaGFuZ2VQYXNzd2Q7VXBncmFkZTs+Pl9TZEjTS+jPjU73Z+pj93YE9F8i"
/>

<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
{
theform = document.forms["Password_change"];
}
else {
theform = document.Password_change;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
// -->
</script>


Why? What have I done wrong?

Chung Hang

Is this all your web form ? I think no !
Please post all the aspx page content and the relative code behind or the
part where you implement my suggestions.
Follow my suggest and read the tutorial. In the tutorial you can find some
useful samples.
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top