1

I have default.aspx with a "Submit" Button and a code behind function called as "btn_Submit" which will perform submit action. Once I deploy the application and if there is any logical problem in btn_Submit code, then I can use runat=server script in default.aspx file and I need not go for another deployment.

But When I tried the same for ascx file, it works very well in development environment i.e in VS but when I move the same to Test server, system throws function not defined. I have renamed the existing function name.

So is it possible to add runat=server script and add c# code in ascx file?

Gopi
  • 5,656
  • 22
  • 80
  • 146

3 Answers3

1

Yes it is possible.. You have to surround your code with markup

    <script language="c#" runat="server">
public void Page_Load(object sender, EventArgs e)
{
  //hello, world!
}
</script>

Take a look to thisquestion! I think it will help you..

But it is really better to separate your code..

Community
  • 1
  • 1
bAN
  • 13,375
  • 16
  • 60
  • 93
0

Did you tell the button which method to run on submit? With "auto event wireup" it will try to find a "buttonname_Click" method if you didn't specify anything. If that doesn't exist, you will get an error.

To call a method with a different name, specify that in the OnClick property of the button.

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111
0

I am not sure why this happened and still was not able to solve it, So redeployed the application :(

Gopi
  • 5,656
  • 22
  • 80
  • 146