Custom buttons in *.cshtml execute server side scripts

Tips submitted by ASP.NET Maker users

Custom buttons in *.cshtml execute server side scripts

Postby Thomas.Hoffner » Mon Aug 05, 2013 1:11 am

If you want to add some custom buttons in *.cshtml (e.c. blankpage.cshtml) which will execute Server side script,
you have to edit in manually in the cshtml-file.

Then you have to add the following parts in this file per example I use the blankpage.cshtml to show:

################################# blankpage.cshtml Begin ######################################################
@functions {
//
// Page class (custompage)
//
public class ccustompage<C, S> : ccustompage_base<C, S>
where C : cConnection, new()
where S : cAdvancedSecurity, new()
{
//
// Server events
//
// Row Updating event
}

// custompage
public static ccustompage<cConnection, cAdvancedSecurity> custompage {
get { return (ccustompage<cConnection, cAdvancedSecurity>)ew_PageData["custompage"]; }
set { ew_PageData["custompage"] = value; }
}

// CurrentPage
public static ccustompage<cConnection, cAdvancedSecurity> CurrentPage {
get { return (ccustompage<cConnection, cAdvancedSecurity>)ew_PageData["CurrentPage"]; }
set { ew_PageData["CurrentPage"] = value; }
}

// CurrentTable
public static ccustompage<cConnection, cAdvancedSecurity> CurrentTable {
get { return CurrentPage; }
set { CurrentPage = value; }
}

// Custom Start #############################################################################################
// 1. Button Test
public void Button_1()
{
// Your code
}

// 2. Button Test
public void Button_2()
{
// Your code
}
//Custom End #############################################################################################
}
@{
var totalMessage = "";

Layout = "_layout.cshtml";

// Header
ew_Header(true);

// Create page object
if (custompage == null) {
custompage = new ccustompage<cConnection, cAdvancedSecurity>();
}

// Custom Start #############################################################################################
// 2 Buttons added
<form method="post" action="">
<input type="submit" name="dynmon" value="myButton1" />
<input type="submit" name="dynmon" value="myButton2" />
</form>
// Custom End #############################################################################################

// Page init
custompage.Page_Init();

// Page main
custompage.Page_Main();

// Custom Start (position ist important) #############################################################################################
if (IsPost)
{
switch ( Request.Form[ "dynmon" ] )
{
case "myButton1":
Button_1(); // Server side script
break;
case "myButton2":
Button_2(); // Server side script
break;
}
}
// Custom End #############################################################################################
}


<script type="text/javascript">

// Write your client script here, no need to add script tags.
</script>
@{
custompage.ShowMessage();
}
<!-- Put your custom html here -->
<script type="text/javascript">

// Write your startup script here
// document.write("page loaded");

</script>
@{
custompage.Page_Terminate();
}

################################# blankpage.cshtml End ######################################################

In my case I have to execute some functions I have allready written in c# including some Libraries written in .net(C#)
and so I cannot use Java !!

I hope it is useful for some users !!!


Best regards

Thomas Hoffner
Thomas.Hoffner
 
Posts: 32
Joined: Wed Jul 24, 2013 4:14 pm

Return to User Submited Tips (ASP.NET Maker)