473,785 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Button to call another Aspx page

Hello, i have implemented a button in some other pages that calls another
one, the problem is that everytime I hit the button he goes for the postback
code and I already disable that part. this is my code:

<%@ Page Language="VB" MasterPageFile= "~/MasterPage.mast er" Title="SIP ::
Nichos de Mercado" %>
<%@ Import Namespace="Syst em.Data" %>
<%@ Import Namespace="Syst em.Data.OleDb" %>

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
If IsPostBack() Then
Dim objConn As New
OleDbConnection ("Provider=SQLN CLI;Server=db2f x981\comware;Da tabase=SIP;Trus ted_Connection= yes;")
objConn.Open()
Dim sSQL, Resul As String
sSQL = "Insert into Nicho (Descripcion) values ('" &
Descripcion.Tex t & "')"
Dim objCmd As New OleDbCommand(sS QL, objConn)

Resul = objCmd.ExecuteN onQuery
If Resul Then
LblSaved.Visibl e = True
End If
End If
End Sub

Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s)
Response.Redire ct("Nichos_con. aspx")
End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder2"
Runat="Server">
<span style="font-size: 24pt">Nichos de Mercado<br />
<br />
</span><span style="font-size: 11pt; font-family: Tahoma">Por favor
ingrese los datos
solicitados en el formulario.<br />
<br />
<br />
<br />
<table border="0" cellpadding="0" cellspacing="0" style="left:
220px; width: 306px;
position: relative; top: 3px">
<tr>
<td style="width: 100px; height: 15px; text-align: center">
<strong><span style="font-size: 10pt">Nicho de
Mercado</span></strong></td>
<td style="width: 100px; height: 15px">
<asp:TextBox ID="Descripcion " runat="server"
Style="position : relative"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Button ID="Button1" runat="server" Font-Bold="True"
Font-Names="Tahoma" Style="position : relative"
Text="Salvar" OnClick="Button 1_Click" /></td>
</tr>
</table>
<br />
<asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
runat="server" ErrorMessage="E l campo de Nicho de Mercado no debe estar en
blanco"
Font-Bold="True" Font-Names="Tahoma" Font-Size="X-Small"
Style="left: 196px;
position: relative; top: -7px"
ControlToValida te="Descripcion "></asp:RequiredFie ldValidator>
<asp:Label ID="LblSaved" runat="server" Font-Bold="True"
Font-Names="MS Reference Sans Serif"
Font-Size="X-Small" Style="left: -73px; position: relative; top:
20px" Text=":: Registro Salvado ::"
Visible="False" ></asp:Label><br />
<br />
<br />
<br />
<asp:Button ID="Button2" runat="server" CausesValidatio n="False"
Font-Bold="True"
OnClick="Button 1_Click" Style="left: 273px; position: relative;
top: 1px" Text="Consultar Nichos" /><br />
</span>
</asp:Content>
The button is Button2, how can I solve this?
Oct 16 '08 #1
2 2583
You are obviously using VB.NET based on your code. However, I am noticing
that you are assigning eventhandlers to your Buttons using the OnClick
attribute rather than the Handles clause (which is the preferred way to do
it in VB.NET). Although either one should work, and I will admit that I did
not actually test your code, try the following:

Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.Click, Button2.Click
Response.Redire ct("Nichos_con. aspx")
End Sub

If you use the above code you can remove the OnClick attribute from your
Button tags (although it shouldn't hurt anything if you don't). See if it
does anything different with the above code. Also, I am getting the
impression that you have all your code in one file (is this correct?). It is
considered better practice, and definitely more organized, to use the
following three files (which is how Visual Studio 2005+ does it by default):

*.aspx
*.aspx.designer .vb (this file is automatically generated when you add a
control to *.aspx)
*.aspx.vb

I would suggest taking this into account. Good Luck!
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"egsdar" <eg****@discuss ions.microsoft. comwrote in message
news:EC******** *************** ***********@mic rosoft.com...
Hello, i have implemented a button in some other pages that calls another
one, the problem is that everytime I hit the button he goes for the
postback
code and I already disable that part. this is my code:

<%@ Page Language="VB" MasterPageFile= "~/MasterPage.mast er" Title="SIP ::
Nichos de Mercado" %>
<%@ Import Namespace="Syst em.Data" %>
<%@ Import Namespace="Syst em.Data.OleDb" %>

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
If IsPostBack() Then
Dim objConn As New
OleDbConnection ("Provider=SQLN CLI;Server=db2f x981\comware;Da tabase=SIP;Trus ted_Connection= yes;")
objConn.Open()
Dim sSQL, Resul As String
sSQL = "Insert into Nicho (Descripcion) values ('" &
Descripcion.Tex t & "')"
Dim objCmd As New OleDbCommand(sS QL, objConn)

Resul = objCmd.ExecuteN onQuery
If Resul Then
LblSaved.Visibl e = True
End If
End If
End Sub

Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s)
Response.Redire ct("Nichos_con. aspx")
End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder2"
Runat="Server">
<span style="font-size: 24pt">Nichos de Mercado<br />
<br />
</span><span style="font-size: 11pt; font-family: Tahoma">Por favor
ingrese los datos
solicitados en el formulario.<br />
<br />
<br />
<br />
<table border="0" cellpadding="0" cellspacing="0" style="left:
220px; width: 306px;
position: relative; top: 3px">
<tr>
<td style="width: 100px; height: 15px; text-align: center">
<strong><span style="font-size: 10pt">Nicho de
Mercado</span></strong></td>
<td style="width: 100px; height: 15px">
<asp:TextBox ID="Descripcion " runat="server"
Style="position : relative"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Button ID="Button1" runat="server"
Font-Bold="True"
Font-Names="Tahoma" Style="position : relative"
Text="Salvar" OnClick="Button 1_Click" /></td>
</tr>
</table>
<br />
<asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
runat="server" ErrorMessage="E l campo de Nicho de Mercado no debe estar en
blanco"
Font-Bold="True" Font-Names="Tahoma" Font-Size="X-Small"
Style="left: 196px;
position: relative; top: -7px"
ControlToValida te="Descripcion "></asp:RequiredFie ldValidator>
<asp:Label ID="LblSaved" runat="server" Font-Bold="True"
Font-Names="MS Reference Sans Serif"
Font-Size="X-Small" Style="left: -73px; position: relative;
top:
20px" Text=":: Registro Salvado ::"
Visible="False" ></asp:Label><br />
<br />
<br />
<br />
<asp:Button ID="Button2" runat="server" CausesValidatio n="False"
Font-Bold="True"
OnClick="Button 1_Click" Style="left: 273px; position: relative;
top: 1px" Text="Consultar Nichos" /><br />
</span>
</asp:Content>
The button is Button2, how can I solve this?


Oct 16 '08 #2
the onload event always runs before the click event. unlike a winform
app, in asp.net the full page processing cycle happens on the first hit
to the and every postback (any server callback).

-- bruce (sqlwork.com)

egsdar wrote:
Hello, i have implemented a button in some other pages that calls another
one, the problem is that everytime I hit the button he goes for the postback
code and I already disable that part. this is my code:

<%@ Page Language="VB" MasterPageFile= "~/MasterPage.mast er" Title="SIP ::
Nichos de Mercado" %>
<%@ Import Namespace="Syst em.Data" %>
<%@ Import Namespace="Syst em.Data.OleDb" %>

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
If IsPostBack() Then
Dim objConn As New
OleDbConnection ("Provider=SQLN CLI;Server=db2f x981\comware;Da tabase=SIP;Trus ted_Connection= yes;")
objConn.Open()
Dim sSQL, Resul As String
sSQL = "Insert into Nicho (Descripcion) values ('" &
Descripcion.Tex t & "')"
Dim objCmd As New OleDbCommand(sS QL, objConn)

Resul = objCmd.ExecuteN onQuery
If Resul Then
LblSaved.Visibl e = True
End If
End If
End Sub

Protected Sub Button1_Click(B yVal sender As Object, ByVal e As
System.EventArg s)
Response.Redire ct("Nichos_con. aspx")
End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder2"
Runat="Server">
<span style="font-size: 24pt">Nichos de Mercado<br />
<br />
</span><span style="font-size: 11pt; font-family: Tahoma">Por favor
ingrese los datos
solicitados en el formulario.<br />
<br />
<br />
<br />
<table border="0" cellpadding="0" cellspacing="0" style="left:
220px; width: 306px;
position: relative; top: 3px">
<tr>
<td style="width: 100px; height: 15px; text-align: center">
<strong><span style="font-size: 10pt">Nicho de
Mercado</span></strong></td>
<td style="width: 100px; height: 15px">
<asp:TextBox ID="Descripcion " runat="server"
Style="position : relative"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Button ID="Button1" runat="server" Font-Bold="True"
Font-Names="Tahoma" Style="position : relative"
Text="Salvar" OnClick="Button 1_Click" /></td>
</tr>
</table>
<br />
<asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
runat="server" ErrorMessage="E l campo de Nicho de Mercado no debe estar en
blanco"
Font-Bold="True" Font-Names="Tahoma" Font-Size="X-Small"
Style="left: 196px;
position: relative; top: -7px"
ControlToValida te="Descripcion "></asp:RequiredFie ldValidator>
<asp:Label ID="LblSaved" runat="server" Font-Bold="True"
Font-Names="MS Reference Sans Serif"
Font-Size="X-Small" Style="left: -73px; position: relative; top:
20px" Text=":: Registro Salvado ::"
Visible="False" ></asp:Label><br />
<br />
<br />
<br />
<asp:Button ID="Button2" runat="server" CausesValidatio n="False"
Font-Bold="True"
OnClick="Button 1_Click" Style="left: 273px; position: relative;
top: 1px" Text="Consultar Nichos" /><br />
</span>
</asp:Content>
The button is Button2, how can I solve this?

Oct 16 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1465
by: Justnew | last post by:
I have a button in my webform.aspx And I have a htm document or page. What I want is that when I click on the button I want to display the htm page. In other words it is just a back button Need help thanks in advance
0
5752
by: Oz | last post by:
Hi Using VS.NET 2003, Windows XP SP1, We have a page which has been developed using ASP.NET. On it, is a button which when clicked is supposed to add some data to a table. When the button is selected, it causes the ServerClick event to be called twice. Here's the code: You'll see that there are two grids on the page, and that the function SetupDataGrid populates data to the two grid. There are also
1
1049
by: Rahul Borade | last post by:
Hi, I am facing one problem. I have 2 pages in my application. Page1.aspx and Page2.aspx On Page1.aspx I have one asp button. By clicking that button I redirect the page to Page2.aspx. Page2.aspx page load event takes 30 seconds to execute. So for that, I want to show a message to the User "Please wait while the page executes ...".
8
3891
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 TABLE!?! When I move the button outside the table, it works just fine. Inside the table, it doesn't. What gives?
5
1242
by: Andy G | last post by:
I have many html pages that I need to put a button on. When this button is clicked I need to call a stored procedure that updates a record. -How do I add a button to html page that will call a .vbs or .js file (if that what I should even call, I would rather call a .vb class I have created but don't know if that is possible)? Thanks for the help, hopefully this is enough to go off of. I just need to get pointed in the right direction.
1
3905
by: Bruce | last post by:
I use btnSave.Attributes.Add("onclick", "ShowMessage()") to link my web control button to a JavaScript function. It works well until I added a Validation control into the page. After that, even the all of the validations passed, my ShowMessage() still does not get triggered. When checking the view source carefully, I found that the btnSave button have 2 onClick events defined in the tag.
5
1551
by: Neo Geshel | last post by:
Greetings. I am in a very big pickle. I am trying to add page content - as well as a submit button - programatically to a web form that is supposed to submit to DB and then refresh. That is, a user goes to the web page, which draws the current content out of the db and inserts into a "preview" area as well as the form itself. User makes changes, hits submit button. The page *should* refresh, with the changes saved to the db, and...
9
2781
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT IS IMPOSSIBLE TO PROGRAMMATICALLY ADD A BUTTON TO A DYNAMICALLY CREATED PAGE. Or, to be more precise, why it is impossible to have an onClick sub respond to that button’s Click event. My main page has only one line:
1
1507
by: needin4mation | last post by:
protected void Page_Load(object sender, EventArgs e) { TextBox mpTextBox = (TextBox)(Master.FindControl("txtFreeSearch")); Response.Write("mp" + mpTextBox.Text); //only works the second time }
9
4745
by: mosscliffe | last post by:
I am sorry but I am all very new and slow at understanding all this ASP.NET2. I found some code which showed how to page with a repeater. All very excited as I had been looking for this all day. It worked wonderfully, but it was in C# So I converted it to VB with http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx It got upset about private and so I changed those to protected
0
9645
marktang
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...
0
10330
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
jinu1996
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...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9952
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8976
agi2029
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.