how to pass a value from an .aspx to a "code-behind" page ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi guys!
I am a beginner with aspx (i have some background with .asp). And i am
trying tu use a 'code-behind' page in order to execute all transactions in
that page and leave as clean as possible the .aspx with the html.

As my start-point, i am building a login page. I put the textbox and submit
button on the page index.aspx; and, i put all the db validation on the page
maquinaria.vb.

on index.aspx i have this button:
<asp:button id="submit" text="submit"
OnClick="login(usuario.text,clave.text)" runat="server" />

on maquinaria.vb i have this code:
function login(usuario, clave)
some code here
end function

the problem is that i always get this error:
BC30408: Method 'Public Function login(usuario As Object, clave As Object)
As Object' does not have the same signature as delegate 'Delegate Sub
EventHandler(sender As Object, e As System.EventArgs)'.

on .asp i worked this out using the "include" command in order to insert the
page with my active code.

Please, could any one help me with this one ?

Thank you very much guys !

C ya around

David Valiente
 
Okay,

Code behind is a clear way to link objects in a stateless enviroment like
web.
If you look at the top of your aspx page.. you will "inherits classname" and
there's a "codebehind file.cs or .vb" in your case

The button that you put on the index page is linked to a server side event.
What you need to do is (if you double click on the button - it should set
the empty proc for event implementation)
access the elements .. in your case txt boxes in something similar to this

private void lnkUpdate_Click(object sender, System.EventArgs e)
{
if(txtCName.Text != null && txtCName.Text != "")
{
bool isAdd = true;
SizeDetail mySize = new SizeDetail();

if(ViewState["sizeID"] != null)
{
isAdd = false;
mySize.SizeID = (int)(ViewState["sizeID"]);
}
mySize.SizeTitle = txtCName.Text;
mySize.IsActive = chkCEnabled.Checked;

SizesDB mySizesDB = new SizesDB();
mySizesDB.SetSizeDetail(mySize, isAdd);

Response.Redirect(ViewState["URLReferrer"].ToString());
}
}

This code is in C# but its very similar to the vb programming model so you
should be fine.
What i would say is that get on to
http://www.asp.net/Tutorials/quickstart.aspx
There you should find ample stuff to get yourself going..

Regards,

HD
 
Back
Top