I want to dynamic generate a asp:button in C# class, not in the HTML code
so that it can call the methods in the c# class,
I try to use "Response.Write("<asp:button...>")
it didn't show the button
Can anyone help?
Thanks a lot 7 1917
This was asked a couple of days ago, and many many times before then.
The end result being, is that those tags are interpreted by asp.net, and
then your code runs. You can't then write out more of those tags, and want
them to be interpreted by the engine.
Forget the way you did everything in ASP. Pretend you never did ASP at all.
All it will every do is cause you to not do things the right way.
Then read up on ASP.NET and the object oriented model before going any
further.
You will see that the right way to do this is to create actual objects and
add them to the page.
"Lam" <ja**********@hotmail.com> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl... I want to dynamic generate a asp:button in C# class, not in the HTML code so that it can call the methods in the c# class, I try to use "Response.Write("<asp:button...>") it didn't show the button Can anyone help?
Thanks a lot
I have created a method like this
private void createSaveButton()
{
System.Web.UI.WebControls.Button b1= new
System.Web.UI.WebControls.Button();
b1.Text="Save it";
Page.Controls.Add(b1);
}
when I run the code, it says that the button has to be added in the form
how can I do that?
thanks
"Marina" <so*****@nospam.com> wrote in message
news:OD**************@TK2MSFTNGP09.phx.gbl... This was asked a couple of days ago, and many many times before then.
The end result being, is that those tags are interpreted by asp.net, and then your code runs. You can't then write out more of those tags, and want them to be interpreted by the engine.
Forget the way you did everything in ASP. Pretend you never did ASP at
all. All it will every do is cause you to not do things the right way.
Then read up on ASP.NET and the object oriented model before going any further.
You will see that the right way to do this is to create actual objects and add them to the page.
"Lam" <ja**********@hotmail.com> wrote in message news:%2******************@TK2MSFTNGP15.phx.gbl...I want to dynamic generate a asp:button in C# class, not in the HTML code so that it can call the methods in the c# class, I try to use "Response.Write("<asp:button...>") it didn't show the button Can anyone help?
Thanks a lot
Do you have a form on your page in the .aspx? You need to have on there
ahead of time.
"Lam" <ja**********@hotmail.com> wrote in message
news:Or****************@TK2MSFTNGP10.phx.gbl... I have created a method like this private void createSaveButton()
{
System.Web.UI.WebControls.Button b1= new System.Web.UI.WebControls.Button();
b1.Text="Save it";
Page.Controls.Add(b1);
}
when I run the code, it says that the button has to be added in the form
how can I do that?
thanks
"Marina" <so*****@nospam.com> wrote in message news:OD**************@TK2MSFTNGP09.phx.gbl... This was asked a couple of days ago, and many many times before then.
The end result being, is that those tags are interpreted by asp.net, and then your code runs. You can't then write out more of those tags, and want them to be interpreted by the engine.
Forget the way you did everything in ASP. Pretend you never did ASP at all. All it will every do is cause you to not do things the right way.
Then read up on ASP.NET and the object oriented model before going any further.
You will see that the right way to do this is to create actual objects and add them to the page.
"Lam" <ja**********@hotmail.com> wrote in message news:%2******************@TK2MSFTNGP15.phx.gbl... >I want to dynamic generate a asp:button in C# class, not in the HTML >code > so that it can call the methods in the c# class, > I try to use "Response.Write("<asp:button...>") > it didn't show the button > Can anyone help? > > Thanks a lot > >
thanks
one last question
how can I write methods to handle the event when the button is clicked?
is it b1.click? this is the event handler
thanks for your time
"Marina" <so*****@nospam.com> wrote in message
news:OA**************@TK2MSFTNGP09.phx.gbl... Do you have a form on your page in the .aspx? You need to have on there ahead of time.
"Lam" <ja**********@hotmail.com> wrote in message news:Or****************@TK2MSFTNGP10.phx.gbl...I have created a method like this private void createSaveButton()
{
System.Web.UI.WebControls.Button b1= new System.Web.UI.WebControls.Button();
b1.Text="Save it";
Page.Controls.Add(b1);
}
when I run the code, it says that the button has to be added in the form
how can I do that?
thanks
"Marina" <so*****@nospam.com> wrote in message news:OD**************@TK2MSFTNGP09.phx.gbl... This was asked a couple of days ago, and many many times before then.
The end result being, is that those tags are interpreted by asp.net,
and then your code runs. You can't then write out more of those tags, and want them to be interpreted by the engine.
Forget the way you did everything in ASP. Pretend you never did ASP at all. All it will every do is cause you to not do things the right way.
Then read up on ASP.NET and the object oriented model before going any further.
You will see that the right way to do this is to create actual objects and add them to the page.
"Lam" <ja**********@hotmail.com> wrote in message news:%2******************@TK2MSFTNGP15.phx.gbl... >I want to dynamic generate a asp:button in C# class, not in the HTML >code > so that it can call the methods in the c# class, > I try to use "Response.Write("<asp:button...>") > it didn't show the button > Can anyone help? > > Thanks a lot > >
You have to write the handler, meaning it has to have the right signature.
Then, you would do something like:
AddHandler myBtn.Click, AddressOf MyClickHandler
where MyClickHandler is the method you wrote.
"Lam" <ja**********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... thanks one last question how can I write methods to handle the event when the button is clicked? is it b1.click? this is the event handler
thanks for your time
"Marina" <so*****@nospam.com> wrote in message news:OA**************@TK2MSFTNGP09.phx.gbl... Do you have a form on your page in the .aspx? You need to have on there ahead of time.
"Lam" <ja**********@hotmail.com> wrote in message news:Or****************@TK2MSFTNGP10.phx.gbl... >I have created a method like this > private void createSaveButton() > > { > > System.Web.UI.WebControls.Button b1= new > System.Web.UI.WebControls.Button(); > > b1.Text="Save it"; > > Page.Controls.Add(b1); > > > } > > when I run the code, it says that the button has to be added in the > form > > how can I do that? > > thanks > > "Marina" <so*****@nospam.com> wrote in message > news:OD**************@TK2MSFTNGP09.phx.gbl... >> This was asked a couple of days ago, and many many times before then. >> >> The end result being, is that those tags are interpreted by asp.net, and >> then your code runs. You can't then write out more of those tags, and >> want >> them to be interpreted by the engine. >> >> Forget the way you did everything in ASP. Pretend you never did ASP at > all. >> All it will every do is cause you to not do things the right way. >> >> Then read up on ASP.NET and the object oriented model before going any >> further. >> >> You will see that the right way to do this is to create actual objects >> and >> add them to the page. >> >> "Lam" <ja**********@hotmail.com> wrote in message >> news:%2******************@TK2MSFTNGP15.phx.gbl... >> >I want to dynamic generate a asp:button in C# class, not in the HTML >> >code >> > so that it can call the methods in the c# class, >> > I try to use "Response.Write("<asp:button...>") >> > it didn't show the button >> > Can anyone help? >> > >> > Thanks a lot >> > >> > >> >> > >
From where is this method called? There are some considerations that must
be made when dynamically adding controls to a page in order for them to
function properly.
As for dynamically setting the event handler, you will need to write the
event handler using the correct signature:
protected void myButton_OnClick(Object sender, EventArgs e)
...
protected void myButton_OnCommand(Object sender, CommandEventArgs e)
...
depending on what you're trying to do. You would assign the handler to the
button in the following manner:
myButton.OnClick += new EventHandler(myButton_OnClick)
or
myButton.OnCommand += new CommandEventHandler(myButton_OnCommand)
HTH
----------------
Dave Fancher http://davefancher.blogspot.com
"Lam" <ja**********@hotmail.com> wrote in message
news:Or****************@TK2MSFTNGP10.phx.gbl... I have created a method like this private void createSaveButton()
{
System.Web.UI.WebControls.Button b1= new System.Web.UI.WebControls.Button();
b1.Text="Save it";
Page.Controls.Add(b1);
}
when I run the code, it says that the button has to be added in the form
how can I do that?
thanks
"Marina" <so*****@nospam.com> wrote in message news:OD**************@TK2MSFTNGP09.phx.gbl... This was asked a couple of days ago, and many many times before then.
The end result being, is that those tags are interpreted by asp.net, and then your code runs. You can't then write out more of those tags, and want them to be interpreted by the engine.
Forget the way you did everything in ASP. Pretend you never did ASP at all. All it will every do is cause you to not do things the right way.
Then read up on ASP.NET and the object oriented model before going any further.
You will see that the right way to do this is to create actual objects and add them to the page.
"Lam" <ja**********@hotmail.com> wrote in message news:%2******************@TK2MSFTNGP15.phx.gbl... >I want to dynamic generate a asp:button in C# class, not in the HTML >code > so that it can call the methods in the c# class, > I try to use "Response.Write("<asp:button...>") > it didn't show the button > Can anyone help? > > Thanks a lot > >
Thank you guys
it's working
"Dave Fancher" <ei*****@remove.comcast.net> wrote in message
news:fI********************@comcast.com... From where is this method called? There are some considerations that must be made when dynamically adding controls to a page in order for them to function properly.
As for dynamically setting the event handler, you will need to write the event handler using the correct signature: protected void myButton_OnClick(Object sender, EventArgs e) ...
protected void myButton_OnCommand(Object sender, CommandEventArgs e) ...
depending on what you're trying to do. You would assign the handler to
the button in the following manner: myButton.OnClick += new EventHandler(myButton_OnClick) or myButton.OnCommand += new CommandEventHandler(myButton_OnCommand)
HTH ---------------- Dave Fancher http://davefancher.blogspot.com
"Lam" <ja**********@hotmail.com> wrote in message news:Or****************@TK2MSFTNGP10.phx.gbl...I have created a method like this private void createSaveButton()
{
System.Web.UI.WebControls.Button b1= new System.Web.UI.WebControls.Button();
b1.Text="Save it";
Page.Controls.Add(b1);
}
when I run the code, it says that the button has to be added in the form
how can I do that?
thanks
"Marina" <so*****@nospam.com> wrote in message news:OD**************@TK2MSFTNGP09.phx.gbl... This was asked a couple of days ago, and many many times before then.
The end result being, is that those tags are interpreted by asp.net,
and then your code runs. You can't then write out more of those tags, and want them to be interpreted by the engine.
Forget the way you did everything in ASP. Pretend you never did ASP at all. All it will every do is cause you to not do things the right way.
Then read up on ASP.NET and the object oriented model before going any further.
You will see that the right way to do this is to create actual objects and add them to the page.
"Lam" <ja**********@hotmail.com> wrote in message news:%2******************@TK2MSFTNGP15.phx.gbl... >I want to dynamic generate a asp:button in C# class, not in the HTML >code > so that it can call the methods in the c# class, > I try to use "Response.Write("<asp:button...>") > it didn't show the button > Can anyone help? > > Thanks a lot > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Maziar Aflatoun |
last post by:
Hi everyone,
I have the following shopping cart (basket view). However, Delete button in
my datagrid doesn't fire any events. Does anyone know why? (It's a user web
control)
<%@ Control...
|
by: z. f. |
last post by:
Hi,
I'm having an aspx page with a server form.
i have a grid with a delete button and below the grid, another area with
inputs for inserting new values and an "add" button for submiting the...
|
by: Venus |
last post by:
Hello,
I am trying to generate a dynamic form at runtime and would like to do it
using "<asp: ..." form elements as follows
Build up the string that is placed somewhere in the HTML code the...
|
by: hb |
last post by:
Hi,
When I add an asp:button (ex: id=btnLog) on home.aspx,
I need to create btnLog_Click() event in home.aspx.cs,
and also link this event and the button in OnInit() method
by adding:...
|
by: RUIZCJ |
last post by:
Hi,
I'm at my wits end!!! I have the following code. The submit button works on
my home computer but when I copy the dll and the ASPX file to my host
provider, the button does NOT fire.
TIA...
|
by: tatemononai |
last post by:
I had a beautiful script that was running, well, just beautifully. But
then I decided to take a button that fired an event and place it inside
a <asp:table. The event WILL NOT FIRE INSIDE THE...
|
by: csgraham74 |
last post by:
Hi guys,
I posted regarding this issue the other day but i still dont have an
answer to my problem.
Basically i have imported asp.net pages from dreamweaver into visual
studio. Ive added a...
|
by: Sean |
last post by:
I have a situation whereby I need to modify the text string appearing on an
ASP button with some text derived from a Javascript function. But I am
unsure of the correct syntax to do so.
...
|
by: mazdotnet |
last post by:
Hi all,
I'm really stuck trying to figure the following out. I have been
working on a shopping portal where you can select products from a list
inside a repeater on the bottom of the page and...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |