hai,
i wish to know how to call a function from an aspx page,
i define that function in aspx.cs page,pls anyone can tell me
Thanks
9 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Soft CornerRank #1,221 · 1.5K reputationPosted Feb 10, 2011, 1:10 AM EST
✓ Accepted answer0
Hi , In your aspx page Just write this code, where u want a call
<% tablebuild(); %>
It will work and as i said above ,use a namespace in the Inherits section of Page directive (by default it will b there but in case if u got an error) let me know if u done with this :)
0
Amit ChoudharyRank #145 · 15.8K reputationPosted Feb 10, 2011, 12:21 AM EST
0
Hi friend,
I dont understand what method you have wrote in aspx file. Is it server side method or Javascript function??
please elaborate more..
Thanks
0
Soft CornerRank #1,221 · 1.5K reputationPosted Feb 10, 2011, 12:31 AM EST
0
Hi krithika, you have define one function say f_MyFunction in .cs file . Now u want to acces this funct in aspx. then try this
Soft CornerRank #1,221 · 1.5K reputationPosted Feb 10, 2011, 1:10 AM EST
In your aspx page Just write this code, where u want a call
<% tablebuild(); %>
It will work and as i said above ,use a namespace in the Inherits section of Page directive (by default it will b there but in case if u got an error)
let me know if u done with this :)
Amit ChoudharyRank #145 · 15.8K reputationPosted Feb 10, 2011, 12:21 AM EST
I dont understand what method you have wrote in aspx file. Is it server side method or Javascript function??
please elaborate more..
Thanks
Soft CornerRank #1,221 · 1.5K reputationPosted Feb 10, 2011, 12:31 AM EST
you have define one function say f_MyFunction in .cs file . Now u want to acces this funct in aspx. then try this
<%=f_MyFunction()%>
use a namespace in the Inherits section of Page directive. For more information about Page directive, see http://msdn2.microsoft.com/en-us/library/ydy4x04a(VS.80).aspx
krithika muthukrishnanRank #8,369 · 223 reputationPosted Feb 10, 2011, 12:46 AM EST
hai
i write this code in first.aspx.cs page
how can i call this function from first.aspx source page.
public void tablebuild()
{
Response.Write("
string connectionstring = @"data source=System-7\sqlExpress;initial catalog=Project;User ID=sa;Password=as;";
SqlConnection con = new SqlConnection(connectionstring);
con.Open();
string query = "select category,posts from titlename";
DataTable dt = new DataTable();
SqlDataAdapter objadapter = new SqlDataAdapter(query, con);
objadapter.Fill(dt);
int i = 0;
while (dt.Rows.Count > i)
{
Response.Write("
i = i + 1;
}
}
Thanks,
Krishna GaradRank #191 · 12.8K reputationPosted Feb 10, 2011, 1:04 AM EST
first set page attribute EnablePageMethod=true
in your .aspx page now write any javascript function to call the function of .aspx.cs file
like
Might it helps you.
Krishna GaradRank #191 · 12.8K reputationPosted Feb 10, 2011, 1:15 AM EST
krithika muthukrishnanRank #8,369 · 223 reputationPosted Feb 10, 2011, 1:21 AM EST
krithika muthukrishnanRank #8,369 · 223 reputationPosted Feb 10, 2011, 1:22 AM EST
Amit ChoudharyRank #145 · 15.8K reputationPosted Feb 10, 2011, 1:26 AM EST
first.aspx.page write the aspx suppose you can call it as below:
<%# tablebuild()%> or <% tablebuild()%>
Try any of this will surely execute the call to this function.
Enjoy..
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts