ArticleDirectory
- Step 1: create a web project and reference the mysoft. Web assembly:
- Step 2: Configure web. config
- Step 3: write client scripts to communicate with the server
- How to load a User Control Using ajax:
Today, I took some time to write a simple example of mysoft. web-related components.Program.
Although it is simple, but it is completely dirty, the following describes the implementation of this example one by one:
Step 1: create a web project and reference the mysoft. Web assembly:
Add the mysoft. Web reference to the current project. The latest version is in the bin directory.
Step 2: Configure web. config
<Pages enableviewstate ="False"Enablesessionstate ="True"> <Controls> <add tagprefix ="My"Namespace="Mysoft. Web. UI. Controls"Assembly ="Mysoft. Web"/> </Controls> </pages> Get, post"Path ="Ajax/*. ashx"Type ="Mysoft. Web. ajaxpagehandler, mysoft. Web"/> </Httphandlers>
The above controls is required when using the mysoft internal control.
The configuration in httphandlers is used for Ajax processing.
Step 3: write client scripts to communicate with the server
Background: Enable the client to read the server timeCode
Note: enableajaxcallback must be enabled.
Public partial class _ default: ajaxpage
{
Protected void page_load (Object sender, eventargs E)
{
}
[Ajaxmethod]
Public datetime getserverdatetime ()
{
Return datetime. now;
}
Protected override bool enableajaxcallback
{
Get
{
Return true;
}
}
}
Foreground: <input type = "button" value = "Get server time" onclick = "getdatetime ();"/>
Function getdatetime (){
VaR time = ajaxmethods. getserverdatetime ();
Alert (time. tolocalestring ());
}
The ajaxmethods internal object indicates a set of all [ajaxmethod] Methods on the current page.
How to load a User Control Using ajax:
Create a new user control named testparamcontrol. ascx
Client code:
Function loadusercontrolwithparam (){
VaR value = $ ('txtname'). value;
If (! Value ){
Dialog. Alert ('enter a name! ');
Return;
}
// Divcontainer is the <Div id = 'divcontainer '/> container
//~ /Testparamcontrol. ascx is the user control path.
// {Name: Value} Here is the user control parameter. Multiple parameters can be input.
Ajax. updatepanel ('diviner iner ','~ /Testparamcontrol. ascx', {Name: Value });
}
Server code:
Public partial class testparamcontrol: system. Web. UI. usercontrol, mysoft. Web. UI. iajaxprocesseventhandler
{
Protected void page_load (Object sender, eventargs E)
{
}
# Region iajaxprocesseventhandler Member
// Data loading must implement the iajaxprocesseventhandler Interface
Public void onajaxprocess (callbackparams)
{
Because data is transmitted from the client to the server as a string, some conversions are required.
Callbackparams can be easily converted to various data types, as shown below:
Int age = callbackparams ["age"]. To <int> ();
Datetime time = callbackparams ["startdate"]. To <datetime> ();
Obtain the string directly. You can use callbackparams ["parameter name"] Or callbackparams ["parameter name"]. value;
This. label1.text = "Your name is:" + callbackparams ["name"]. value;
}
# Endregion
}
The function of inserting code blocks reports a bug:
System. nullreferenceexception: object reference is not set to the instance of the object.
In the codemarksframework. livewriter. plugins. frmlivewriterplug.. ctor ()
In the codemarksframework. livewriter. plugins. frmlivewriterplug .. ctor (string & content)
In codemarksframework. livewriter. plugins. livewriteradapter. createcontent (iwin32window dialogowner, string & content)
In windowslive. Writer. posteditor. contentsources. contentsourcemanager. incluminsertion (icontentsourcesite sourcesite, contentsourceinfo contentsource)
I don't know who knows how to solve it!
Write it here first, download the source code for research, and there are many features that you need to explore on your own!
Here is:
Ajax:
Dialog Box:
Prompt box of dialog:
Example: http://files.cnblogs.com/maoyong/WebExample.rar
Mysoft. Data from entry to entry