Hi,
I'm trying to design a simple web form, but I cannot get the code in the
btnSubmit_Serve rClick event to fire. What am I doing wrong?
Here's the codebehind:
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
namespace CSharpTest
{
public class WebForm1 : System.Web.UI.P age
{
protected System.Web.UI.H tmlControls.Htm lInputButton btnSubmit;
private void Page_Load(objec t sender, System.EventArg s e)
{
btnSubmit = new System.Web.UI.H tmlControls.Htm lInputButton("s ubmit");
btnSubmit.ID = "btnSubmit" ;
btnSubmit.Value = "Submit Data";
btnSubmit.Serve rClick += new
System.EventHan dler(this.btnSu bmit_ServerClic k);
}
private void btnSubmit_Serve rClick(object sender, System.EventArg s e)
{
Response.Write( "<html><head><t itle>Title</title></head><body><p>T his is a
response.</body></html>");
}
}
}
and here's the HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1 </title>
</HEAD>
<body bgColor="lightc yan" MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
&nb sp;
<DIV style="Z-INDEX: 108; LEFT: 92px; WIDTH: 550px; POSITION: absolute;
TOP: 71px; HEIGHT: 431px"
ms_positioning= "GridLayout ">
<INPUT id="btnSubmit" style="Z-INDEX: 114; LEFT: 242px; WIDTH: 120px;
POSITION: absolute; TOP: 258px; HEIGHT: 32px"
type="submit" name="btnSubmit " runat="server" value="Submit Query">
</DIV>
</form>
</body>
</HTML>
TIA,
Epetruk
epetruk at stonefield dot idps dot co dot uk 3 1892
I don't see any page directive in your ASPX code.... on the top of the HTML
code you should have something like:
<%@ Page language="c#" Codebehind="Web Form1.aspx.cs" AutoEventWireup ="true"
Inherits="CShar pTest.WebForm1" %>
As I don't see any init code in your code behind code (the code generated by
Visual studio). It means that you have to make sure AutoEventWireup is set
to true as I show you right up here. Otherwise nothing will happen when you
click on the button as u mentioned!
I tried it with your code and it worked ;) but i had to change the line
Response.Write( "<html><head><t itle>Title</title></head><body><p>T his is a response.</body></html>");
to something simpler as it refused to compile.
Response.Write( "TEST");
Also you cannot write HTML tags in Response.Write as it will make you have 2
HTML tags in your page, first the one that you write in Response.Write and
the second that is generated by the ASPX page itself.
Hope this helps,
Francois
"Epetruk" <no****@blackho le.com> wrote in message
news:32******** *****@individua l.net... Hi,
I'm trying to design a simple web form, but I cannot get the code in the btnSubmit_Serve rClick event to fire. What am I doing wrong?
Here's the codebehind:
using System; using System.Collecti ons; using System.Componen tModel; using System.Data; using System.Drawing; using System.Web; using System.Web.Sess ionState; using System.Web.UI; using System.Web.UI.W ebControls; using System.Web.UI.H tmlControls;
namespace CSharpTest { public class WebForm1 : System.Web.UI.P age { protected System.Web.UI.H tmlControls.Htm lInputButton btnSubmit;
private void Page_Load(objec t sender, System.EventArg s e) { btnSubmit = new System.Web.UI.H tmlControls.Htm lInputButton("s ubmit"); btnSubmit.ID = "btnSubmit" ; btnSubmit.Value = "Submit Data";
btnSubmit.Serve rClick += new System.EventHan dler(this.btnSu bmit_ServerClic k); }
private void btnSubmit_Serve rClick(object sender, System.EventArg s e) { Response.Write( "<html><head><t itle>Title</title></head><body><p>T his is
a response.</body></html>"); } } }
and here's the HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>WebForm1 </title> </HEAD> <body bgColor="lightc yan" MS_POSITIONING= "GridLayout "> <form id="Form1" method="post" runat="server"> &nb sp; <DIV style="Z-INDEX: 108; LEFT: 92px; WIDTH: 550px; POSITION: absolute; TOP: 71px; HEIGHT: 431px" ms_positioning= "GridLayout "> <INPUT id="btnSubmit" style="Z-INDEX: 114; LEFT: 242px; WIDTH: 120px; POSITION: absolute; TOP: 258px; HEIGHT: 32px" type="submit" name="btnSubmit " runat="server" value="Submit Query"> </DIV> </form> </body> </HTML>
TIA,
Epetruk
epetruk at stonefield dot idps dot co dot uk
Hello Francois,
I'm afraid I'm still having problems with the code. I've checked
that the AutoEventWireup attribute is set to 'true', and I've
changed the text written in the Response method, but I'm
still unable to get my button click handler to fire.
Is there anything else I need to do? Was there anything else
you changed in the code I sent to make it work?
TIA
Francois wrote: I don't see any page directive in your ASPX code.... on the top of the HTML code you should have something like:
<%@ Page language="c#" Codebehind="Web Form1.aspx.cs" AutoEventWireup ="true" Inherits="CShar pTest.WebForm1" %>
As I don't see any init code in your code behind code (the code generated by Visual studio). It means that you have to make sure AutoEventWireup is set to true as I show you right up here. Otherwise nothing will happen when you click on the button as u mentioned!
I tried it with your code and it worked ;) but i had to change the line Response.Write( "<html><head><t itle>Title</title></head><body><p>T his is a response.</body></html>"); to something simpler as it refused to compile. Response.Write( "TEST");
Also you cannot write HTML tags in Response.Write as it will make you have 2 HTML tags in your page, first the one that you write in Response.Write and the second that is generated by the ASPX page itself.
Hope this helps,
Francois
"Epetruk" <no****@blackho le.com> wrote in message news:32******** *****@individua l.net... Hi,
I'm trying to design a simple web form, but I cannot get the code in the btnSubmit_Serve rClick event to fire. What am I doing wrong?
Here's the codebehind:
using System; using System.Collecti ons; using System.Componen tModel; using System.Data; using System.Drawing; using System.Web; using System.Web.Sess ionState; using System.Web.UI; using System.Web.UI.W ebControls; using System.Web.UI.H tmlControls;
namespace CSharpTest { public class WebForm1 : System.Web.UI.P age { protected System.Web.UI.H tmlControls.Htm lInputButton btnSubmit;
private void Page_Load(objec t sender, System.EventArg s e) { btnSubmit = new System.Web.UI.H tmlControls.Htm lInputButton("s ubmit"); btnSubmit.ID = "btnSubmit" ; btnSubmit.Value = "Submit Data";
btnSubmit.Serve rClick += new System.EventHan dler(this.btnSu bmit_ServerClic k); }
private void btnSubmit_Serve rClick(object sender, System.EventArg s e) {
Response.Write( "<html><head><t itle>Title</title></head><body><p>T his is a response.</body></html>"); } } }
and here's the HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>WebForm1 </title> </HEAD> <body bgColor="lightc yan" MS_POSITIONING= "GridLayout "> <form id="Form1" method="post" runat="server"> &nb sp; <DIV style="Z-INDEX: 108; LEFT: 92px; WIDTH: 550px; POSITION: absolute; TOP: 71px; HEIGHT: 431px" ms_positioning= "GridLayout "> <INPUT id="btnSubmit" style="Z-INDEX: 114; LEFT: 242px; WIDTH: 120px; POSITION: absolute; TOP: 258px; HEIGHT: 32px" type="submit" name="btnSubmit " runat="server" value="Submit Query"> </DIV> </form> </body> </HTML>
TIA,
Epetruk
epetruk at stonefield dot idps dot co dot uk
I am terribly sorry, I forgot to say that you have to comment out the
following line:
btnSubmit = new System.Web.UI.H tmlControls.Htm lInputButton("s ubmit");
What you have to understand is that if you do :
btnSubmit = new System.Web.UI.H tmlControls.Htm lInputButton("s ubmit");
you will create a new instance of an HtmlInputButton , then the reference
btnSubmit will not point anymore to the same object that is declared in the
aspx file:
<INPUT id="btnSubmit" style="Z-INDEX: 114; LEFT: 242px; WIDTH: 120px;
POSITION: absolute; TOP: 258px;
HEIGHT: 32px" type="submit" name="btnSubmit " runat="server" value="Submit
Query">
Then the event will fire to the wrong object and nothing will happen.
When you create a control in the ASPX code, it will be automatically
instanciated. Thus, you never need to instantiate manually the controls that
you have declared in the ASPX file.
Francois.
PS: the full code:
"Epetruk" <no****@blackho le.com> wrote in message
news:32******** *****@individua l.net... Hello Francois,
I'm afraid I'm still having problems with the code. I've checked that the AutoEventWireup attribute is set to 'true', and I've changed the text written in the Response method, but I'm still unable to get my button click handler to fire.
Is there anything else I need to do? Was there anything else you changed in the code I sent to make it work?
TIA
Francois wrote: I don't see any page directive in your ASPX code.... on the top of the HTML code you should have something like:
<%@ Page language="c#" Codebehind="Web Form1.aspx.cs" AutoEventWireup ="true" Inherits="CShar pTest.WebForm1" %>
As I don't see any init code in your code behind code (the code generated by Visual studio). It means that you have to make sure AutoEventWireup is set to true as I show you right up here. Otherwise nothing will happen when you click on the button as u mentioned!
I tried it with your code and it worked ;) but i had to change the line Response.Write( "<html><head><t itle>Title</title></head><body><p>T his is a response.</body></html>"); to something simpler as it refused to compile. Response.Write( "TEST");
Also you cannot write HTML tags in Response.Write as it will make you have 2 HTML tags in your page, first the one that you write in Response.Write and the second that is generated by the ASPX page itself.
Hope this helps,
Francois
"Epetruk" <no****@blackho le.com> wrote in message news:32******** *****@individua l.net... Hi,
I'm trying to design a simple web form, but I cannot get the code in the btnSubmit_Serve rClick event to fire. What am I doing wrong?
Here's the codebehind:
using System; using System.Collecti ons; using System.Componen tModel; using System.Data; using System.Drawing; using System.Web; using System.Web.Sess ionState; using System.Web.UI; using System.Web.UI.W ebControls; using System.Web.UI.H tmlControls;
namespace CSharpTest { public class WebForm1 : System.Web.UI.P age { protected System.Web.UI.H tmlControls.Htm lInputButton btnSubmit;
private void Page_Load(objec t sender, System.EventArg s e) { btnSubmit = new System.Web.UI.H tmlControls.Htm lInputButton("s ubmit"); btnSubmit.ID = "btnSubmit" ; btnSubmit.Value = "Submit Data";
btnSubmit.Serve rClick += new System.EventHan dler(this.btnSu bmit_ServerClic k); }
private void btnSubmit_Serve rClick(object sender, System.EventArg s e) {
Response.Write( "<html><head><t itle>Title</title></head><body><p>T his is a response.</body></html>"); } } }
and here's the HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>WebForm1 </title> </HEAD> <body bgColor="lightc yan" MS_POSITIONING= "GridLayout "> <form id="Form1" method="post" runat="server"> &nb sp; <DIV style="Z-INDEX: 108; LEFT: 92px; WIDTH: 550px; POSITION: absolute; TOP: 71px; HEIGHT: 431px" ms_positioning= "GridLayout "> <INPUT id="btnSubmit" style="Z-INDEX: 114; LEFT: 242px; WIDTH: 120px; POSITION: absolute; TOP: 258px; HEIGHT: 32px" type="submit" name="btnSubmit " runat="server" value="Submit Query"> </DIV> </form> </body> </HTML>
TIA,
Epetruk
epetruk at stonefield dot idps dot co dot uk
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rhy Mednick |
last post by:
I'm creating a custom control (inherited from UserControl) that is displayed
by other controls on the form. I would like for the control to disappear
when the user clicks outside my control the same way a menu does. To do
this my control needs to get notified when the user tried to click off of
it. The Leave and LostFocus events of the UserControl work most of the time
but not always. For example, if they click on a part of the form...
|
by: Steven |
last post by:
Hello,
I have a Javascript function which will get executed only when I click a
Image Button on my aspx page (code behind - C#).
C# InImgBut on click function -->
{
RegisterStartupScript("FormSubmittedJSCode", "<script>init();</script>"); //
line1
|
by: Michael Johnson Jr. |
last post by:
The problem is the following pseudo code causes you need to click buttons
twice to get event.
This is notable via debugging and single stepping.
I can't seem to quite figure out how to do events in ASP where they need to
rerender the page.
I been banging my head on this for 4 days now.
|
by: Stuart |
last post by:
Hi there
I am using a button column>SELECT and a datagrid.Item_Command to take a
value from the datagrid (in this case a customer account number) - store that
value in to a session variable and transfer to another page which picks up
the session variable and uses it to display information for that particular
customer:
Public Sub CustomerSearchGrid_ItemCommand(ByVal source As Object, ByVal e As...
|
by: Klaus Jensen |
last post by:
Hi!
This has been annoying me all day, and I can't get it to work It is really
driving me nuts!
Basicly this simple webapp created to illustrate my problem, renders five
buttons, and adds a handler to the click event. When a button is clicked,
the background-color is set to blue.
Try running the page, and clicking the "Do stuff and update controls
| |
by: Fueled |
last post by:
Hi everyone!
I've made quite a lot of research on this, and I've tried a couple of
proposed solutions. Nothing has worked for me, but I feel there's not
much I'm missing. So I'm turning to this group and its experts for
answers.
So :
- I've got a main page (main.aspx)
- On this page, I've got a button (btnArchive), on whose click I
dynamically add a UserControl (archive.ascx) to the main page.
|
by: lostdreamz |
last post by:
Ok, my situation is like this.
I have a form with a few text boxes each with a 'validating' event, OK
& Cancel buttons, and have the AcceptButton/CancelButton/DialogResult
properties all set.
Situation 1: (works fine)
If the user enters invalid text in a text box, presses Enter in the
text box, the validation displays a msgbox. They now correct the text,
press Enter in the text box, it validates correctly this time and the
|
by: Mike Collins |
last post by:
I cannot get the correct drop down list value from a drop down I have on my
web form. I get the initial value that was loaded in the list.
It was asked by someone else what the autopostback was set to...it is set to
false.
Can someone show me what I am doing wrong and tell me the correct way? Thank
you.
In the page load event, I am doing the following:
|
by: Alan Silver |
last post by:
Hello,
If you add (say) two text boxes to a form, then add a validator with
some simple rule for one of them, you can observer the following
problem:-
Type some erroneous value in the text box with the validator, then click
on the other text box. This makes the validator's red error message
appear. Now, change the invalid text to something valid, and without
clicking anywhere else, click the submit button.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |