|
-
Sep 27th, 2010, 12:23 PM
#1
Thread Starter
Lively Member
Call button click Event in href tag
CODE BEHIND PAGE CODE
Code:
protected void Button1_Click(object sender, EventArgs e)
{
SHow("MANSI");
}
public void SHow(string error)
{
Page page1 = HttpContext.Current.Handler as Page;
if (page1 != null)
{
error = error.Replace("'", "\'");
ScriptManager.RegisterStartupScript(page1, page1.GetType(), "err_msg", "alert('" + error + "');", true);
}
}
SOURCE CODE
Code:
<ul>
<li><a href="#" onClick='Button1_Click'>Home</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Gallery</a></li>
<li><a href="#">About CWS</a></li>
<li><a href="#">Contact</a></li>
</ul>
When I click on Home,I am getting Javascript error Button1_Click is undefined,but it is defined in the code behind,you can see above.
-
Sep 27th, 2010, 12:28 PM
#2
Re: Call button click Event in href tag
Try using an asp:Button, or at least an input type='button', in either case you need the runat="server" part so it knows it's not a JS call but a postback to the server. If you're using VB then you'll need the Handles clause on your event handler sub, or for VB/C# you specify the sub's name like you have already shown in your post.
-
Sep 27th, 2010, 01:21 PM
#3
Frenzied Member
Re: Call button click Event in href tag
hay,
why you didn't use a asp link button?
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Sep 27th, 2010, 02:54 PM
#4
Re: Call button click Event in href tag
Woah, woah, woah...
The reason that it isn't working i because you don't have anything tying the HTML controls, to the event handler in the server side code.
As JuggaloBrotha has pointed out, you don't have any controls marked with runat="server", so as a result, there is no "tie-up" between the two things.
Bottom line is, I think there is something fundamentally wrong with what you are trying to achieve. Can you describe exactly what you want to do? Once we know that, I am sure we will be able to point you in the right direction.
For instance, you might not even have to do the work on the server side at all. If all you are doing is trying to show an alert message when the user clicks a link, then all this can be done on the client side, without the need to postback to the server.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|