I have set button text change using javascript but Onclick and OnclientClick is not working at the same time.
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
CellPadding="4"
ForeColor="#CC0066"
GridLines="None" style="margin-top: 0px" Width="181px" Height="65px"
ShowHeader="False" onrowdatabound="GridView2_RowDataBound">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<b>Profile Photo:</b> <img id="img1" alt="image" src='<%# Eval("photo")%>' height='80' width='80'/>
<br />
<%-- <b>Name:</b> <%#Eval("name") %><br />
<b>Address:</b> <%#Eval("Address") %><br />
<b>college:</b> <%#Eval("college") %><br /> --%>
<asp:Button ID="Btnclick" runat="server" Text="Follow"
onclick="Btnclick_Click" OnClientClick="javascript:return SetText(this)" CausesValidation="False" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="name" />
<asp:BoundField DataField="Address" />
<asp:BoundField DataField="college" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True"/>
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
function SetText(id) {
if (id.value == "Follow") {
id.value = "Followed";
}
else if (id.value == "Followed") {
id.value = "unfollow";
}
return false;
}
</script>
string name;
protected void Btnclick_Click(object sender, EventArgs e)
{
//string script = "successfi";
//string sta = "Followed";
//ClientScript.RegisterStartupScript(this.GetType(), "SetText",script, true);
Lblid.Text = (string)Session["id"].ToString();
Lblname.Text = (string)Session["nam"].ToString();
lbluserphoto.Text = (string)Session["pho"].ToString();
GridViewRow grdrow = (GridViewRow)((Button)sender).NamingContainer;
((Button)sender).Enabled = true;
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("select photo from Registerationtable where name='" + grdrow.Cells[1].Text + "'", conn);
DataSet ds = new DataSet();
sda.Fill(ds);
Session["photo"] = ds.Tables[0].Rows[0]["photo"].ToString();
conn.Close();
string sta = Lblname.Text + " " + "is followed you";
Lblphoto.Text = (string)Session["photo"].ToString();
conn.Open();
//SqlDataAdapter sda = new SqlDataAdapter("select name,photo,status from Registerationtable where id='"+Lblid.Text+"'",conn);
//DataSet ds = new DataSet();
//sda.Fill(ds);
SqlCommand cmd = new SqlCommand("insert into Following values('" + Lblid.Text + "','" + Lblname.Text + "','" + lbluserphoto.Text + "','" + Lblphoto.Text + "','" + grdrow.Cells[1].Text + "','" + grdrow.Cells[2].Text + "','" + sta + "')", conn);
int result = cmd.ExecuteNonQuery();
if (result > 0)
{
Response.Write("<script>alert('follow successfully')</script>");
}
conn.Close();
conn.Open();
SqlCommand cmd2 = new SqlCommand("select username,userphoto,status from Following where followname='" + grdrow.Cells[1].Text + "'", conn);
SqlDataAdapter sda1 = new SqlDataAdapter(cmd2);
DataSet ds1 = new DataSet();
sda1.Fill(ds1);
conn.Close();
Session["uname"] = ds1.Tables[0].Rows[0]["username"].ToString();
Session["phot"] = ds1.Tables[0].Rows[0]["userphoto"].ToString();
//Session["phot"]=ds1.Tables[0].Rows[0]["photo"].ToString();
Session["stat"] = ds1.Tables[0].Rows[0]["status"].ToString();
}
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
(e.Row.FindControl("Btnclick") as Button).Attributes.Add("onclick", string.Format("SetText('{0}');", (e.Row.ClientID)));
}
}
Please tell me the solution.
Onclick is not working at the same time