Reputation: 181
I am new to ASP.net. I downloaded one responsive page template from this link. For my convenience I changed this HTML code to asp.net web form(i.e .html to .aspx) I added a button in that page and I generated click event. When I place a breakpoint in the .cs code and when I click this button in the browser the event is not handled. Even I tried with link button and other controls. I wrote some code in page_load event. It works perfectly. How to solve this issue. Any problem with the downloaded template or can't I handle events in such type of layout. Please go through the below code
Even I tried placing outside the html list control. Its not working. Please go through the link for the details of template here
Issue Placed Menu but event is not working. I tried using other control and its working..
<asp:Menu ID="mini" OnMenuItemClick="mini_MenuItemClick" runat="server" Orientation="Horizontal">
<Items> <asp:MenuItem Text="Item">
<asp:MenuItem Text="sdaad" Value="1">
<asp:MenuItem Text="MenuSub1" Value="MenuSub1" ></asp:MenuItem>
<asp:MenuItem Text="MenuSub2" Value="MenuSub2" ></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="Item" Value="Item">
<asp:MenuItem Text="MenuSub" Value="MenuSub"></asp:MenuItem>
</asp:MenuItem>
</asp:MenuItem></Items>
</asp:Menu>
Upvotes: 0
Views: 385
Reputation: 166
I have tried again after download that template and get issue if because of jQuery Validation script, there are three text boxes in bottom so when we are click on our asp.net button then page will first run client side script and client side script will return false so it will not do post-back till validation js will not return true, so to solve asp.net click problem just remove :
<script type="text/javascript" src="js/jqBootstrapValidation.js"></script>
Upvotes: 1
Reputation: 1656
Find and change Categories block to the next:
<div class="categories">
<asp:Button ID="Button1" CssClass="btn btn-primary" runat="server" Text="Button" OnClick="Button1_Click" />
<ul class="cat">
<li>
<ol class="type">
<li><a href="#" data-filter="*" class="active">All</a></li>
<li><a href="#" data-filter=".web">Web Design</a></li>
<li><a href="#" data-filter=".app">App Development</a></li>
<li><a href="#" data-filter=".branding">Branding</a></li>
</ol>
</li>
</ul>
<div class="clearfix"></div>
</div>
your ButtonClickListenes is:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script language='javascript'>alert('Button is working');</script>");
}
Your code behind (full version):
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
MyFunction();
}
protected void MyFunction()
{
SqlConnection con = new SqlConnection("Data Source=DESKTOP-CEUQVES;Initial Catalog=register;Integrated Security=True;Pooling=False");
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select * from Admintr where projectid=mba ", con);
DataSet ds = new DataSet();
sda.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
//GridView1.Columns[0].Visible = false;
}
}
protected void Unnamed_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "view")
{
string str = e.CommandArgument.ToString();
Response.ContentType = "image/jpg";
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + str + "\"");
Response.TransmitFile(Server.MapPath(str));
Response.End();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script language='javascript'>alert('Button is working');</script>");
}
Upvotes: 0
Reputation: 2137
Give an ID to your button control.
ID="Button1"
Your Click event should be like this:
protected void Button1_Click(object sender, EventArgs e){
//some code
}
Upvotes: 0
Reputation: 187030
One way to check whether the event has been bound to the control, is to go to the design view of the page, select properties for the button, see the section for events and check whether an event has been attached to click. If not double click in the click event section and an event will get attached to your element.
Why do you want to put that button inside a list control?
Upvotes: 0
Reputation: 1656
Have you attached ID to your button? Give ID to your Button and try again. As it is server control, it is not so logical to use it without ID... And post your code behind, I need to look at it and then may be I could help you.
Upvotes: 0