Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
function SetPlan_Id(LblPlanId) {
            var PlanId = 'MainContent_GvGrid_' + LblPlanId;
            document.getElementById('<%= HPlanId.ClientID %>').innerHTML = document.getElementById(PlanId).innerHTML


this function is Working Fine In VB.NET...But Not In C#..
Because I Generated Hard Coded id From Here....

So What is the solution For C#..

this Function Is Call at Code Behind....
C#
protected void GvGrid_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label LblId = (Label)e.Row.FindControl("LblId");
                Panel pnl1 = (Panel)e.Row.FindControl("pnl1");
                string Id = LblId.ClientID;
                pnl1.Attributes.Add("onmouseover", "SetPlan_Id('" + Id + "');");
            }
        }
Posted
Updated 18-Dec-14 18:18pm
v2
Comments
DamithSL 19-Dec-14 0:06am    
how you call this method?
Mayur Ahir 19-Dec-14 0:11am    
At Code Behind..
protected void GvGrid_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label LblId = (Label)e.Row.FindControl("LblId");
Panel pnl1 = (Panel)e.Row.FindControl("pnl1");
string Id = LblId.ClientID;
pnl1.Attributes.Add("onmouseover", "SetPlan_Id('" + Id + "');");
}
}
DamithSL 19-Dec-14 0:18am    
change
pnl1.Attributes.Add("onmouseover", "SetPlan_Id('" + Id + "');");
to
pnl1.Attributes.Add("onmouseover", "SetPlan_Id(this);");
and change function as
function SetPlan_Id(LblPlan) {
document.getElementById('<%= HPlanId.ClientID %>').innerHTML = LblPlan.innerHTML;
Put debugger and see what is the value of "Id" in code behind.

XML
I think you don't need this part in javascript:
var PlanId = 'MainContent_GvGrid_' + LblPlanId;

Since you're already sending lbl.ClientId as parameter...just call
document.getElementById('<%= HPlanId.ClientID %>').innerHTML = document.getElementById(LblPlanId).innerHTML

In general you never want to have hard-coded string for ID for server side controls. If you need C# version (should be the same, really, except C# is case sensitive - stupidest language property ever) you have to check the page source and see what is the id of the label once the page is fully loaded.


Just a minor gripe: javascript generally isn't about C# and VB.NET, it is client side code while other two are server side.
 
Share this answer
 
Try to use LblId.Text instead of LblId.ClientId as LblId is a server side control which placed inside the gridview.

protected void GvGrid_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label LblId = (Label)e.Row.FindControl("LblId");
Panel pnl1 = (Panel)e.Row.FindControl("pnl1");
string Id = LblId.Text;
pnl1.Attributes.Add("onmouseover", "SetPlan_Id('" + Id + "');");
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900