是否可以将webmethod放在.ascx.cs文件中而不是.aspx文件中。 [英] Is it possible to place a webmethod inside .ascx.cs file instead of in .aspx file.

查看:57
本文介绍了是否可以将webmethod放在.ascx.cs文件中而不是.aspx文件中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Setting.aspx中的usercontroller(GeneralSetting.ascx)。像这样我在设置页面中有10个以上的用户控制器。我的要求是将usercontroller的值保存到db中,我只需要使用.ascx& .ascx.cs文件。是否可以这样做。



请在下面找到代码段。



GeneralSettings.ascx =======



函数SaveGeneralSettings(){

调试器;

if(ValidateGeneralSettings( )){$ / $


var txtSamplingPercentage = $(#txtSamplingPercentage)[0] .value;

var txtAttempts = $(# txtAttempts)[0] .value;

var txtTimeInterval = $(#txtTimeInterval)[0] .value;



TicketSampling = new Object();



TicketSampling.SamplingPercentage = txtSamplingPercentage;

UndeliveredMail.MailRetryCount = txtAttempts;

UndeliveredMail.RetryTimeInterval = txtTimeInterval;





PageMethods.UpdateGeneralSettings(TicketSampling);

}

返回false;

}







GeneralSetting.ascx.cs =======>



公共部分class设置:PageBase

{

#region properties / variable

private const string TABRESOURCEID =3BB29895-415B-46B6-9ED0-25539308579C ;

私有静态Guid TabResourceId {get {return new Guid(TABRESOURCEID); } $

#endregion属性/变量



protected override void OnInit(EventArgs e)

{

base.OnInit(e);

RadScriptManager.GetCurrent(this).EnablePageMethods = true;

}



公开覆盖Guid ResourceId

{

get

{

返回PageResourceKeyConfig.SystemSettings ;

}

set

{

抛出新的NotImplementedException();

}

}



#region webmethods



[WebMethod]

public static void UpdateGeneralSettings(TicketSampling TicketSamplingDetails)

{

GeneralSetting objGeneralsetting = null;

objGenera lsetting = new GeneralSetting();

objGeneralsetting.Sampling = new TicketSampling()

{

SamplingPercentage = TicketSamplingDetails.SamplingPercentage,

};



string xmlstring = XMLSerializerHelper.GetAsXMLFromObject< generalsetting>(objGeneralsetting);

string tabname =General;



SaveSystemSettings(TabResourceId,tabname,xmlstring);

}



#endregion webmethods



private static bool SaveSystemSettings(Guid TabResourceId,string tabname,string xmlstring)

{

bool isSuccess = false;



使用(ISystemSettingsManager systemSettingManager = BLFactory.GetInstance< isystemsettingsmanager>(ContextProvider.CurrentContext))

{

isSuccess = systemSettingManager.SaveSystemSetting(TabResourceId,tabname,xmlstring);

}

return isSuccess;

}



我知道如果我在setting.aspx上面放置wwebmethod它会正常工作,但我需要放在.ascx.cs文件中。我怎样才能实现这一点。



提前致谢。

I have a usercontroller (GeneralSetting.ascx) which is inside Setting.aspx. Like this i have 10+ usercontrollers inside Setting page. My requirement is to save values of usercontroller into db and i need to use only .ascx & .ascx.cs files. Is it possibe to do as such.

Please find below the code snippet.

GeneralSettings.ascx=======

function SaveGeneralSettings() {
debugger;
if (ValidateGeneralSettings()) {

var txtSamplingPercentage = $("#txtSamplingPercentage")[0].value;
var txtAttempts = $("#txtAttempts")[0].value;
var txtTimeInterval = $("#txtTimeInterval")[0].value;

TicketSampling = new Object();

TicketSampling.SamplingPercentage = txtSamplingPercentage;
UndeliveredMail.MailRetryCount = txtAttempts;
UndeliveredMail.RetryTimeInterval = txtTimeInterval;


PageMethods.UpdateGeneralSettings(TicketSampling);
}
return false;
}



GeneralSetting.ascx.cs=======>

public partial class Settings : PageBase
{
#region properties/variable
private const string TABRESOURCEID = "3BB29895-415B-46B6-9ED0-25539308579C";
private static Guid TabResourceId { get { return new Guid(TABRESOURCEID); } }
#endregion properties/variable

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
RadScriptManager.GetCurrent(this).EnablePageMethods = true;
}

public override Guid ResourceId
{
get
{
return PageResourceKeyConfig.SystemSettings;
}
set
{
throw new NotImplementedException();
}
}

#region webmethods

[WebMethod]
public static void UpdateGeneralSettings(TicketSampling TicketSamplingDetails)
{
GeneralSetting objGeneralsetting = null;
objGeneralsetting = new GeneralSetting();
objGeneralsetting.Sampling = new TicketSampling()
{
SamplingPercentage = TicketSamplingDetails.SamplingPercentage,
};

string xmlstring = XMLSerializerHelper.GetAsXMLFromObject<generalsetting>(objGeneralsetting);
string tabname = "General";

SaveSystemSettings(TabResourceId, tabname, xmlstring);
}

#endregion webmethods

private static bool SaveSystemSettings(Guid TabResourceId, string tabname, string xmlstring)
{
bool isSuccess = false;

using (ISystemSettingsManager systemSettingManager = BLFactory.GetInstance<isystemsettingsmanager>(ContextProvider.CurrentContext))
{
isSuccess = systemSettingManager.SaveSystemSetting(TabResourceId, tabname, xmlstring);
}
return isSuccess;
}

I know if i placed above wwebmethod in setting.aspx it will work fine, however i need to place inside .ascx.cs file. How can i achieve this.

Thanks in advance.

推荐答案

(#txtSamplingPercentage)[ 0] .value;

var txtAttempts =
("#txtSamplingPercentage")[0].value;
var txtAttempts =


(#txtAttempts)[0] .value;

var txtTimeInterval =
("#txtAttempts")[0].value;
var txtTimeInterval =


(#txtTimeInterval)[0] .value;



TicketSampling = new Object();



TicketSampling.SamplingPercentage = txtSamplingPercentage;

UndeliveredMail.MailRetryCount = txtAttempts;

UndeliveredMail.RetryTimeInterval = txtTimeInterval;





PageMethods.UpdateGeneralSettings(TicketSampling);

}

返回false;

}







GeneralSetting.ascx.cs =======>



公共部分类设置:PageBase

{

#region properties / variable

private const string TABRESOURCEID =3BB29895-415B-46B6-9ED0-25539308579C;

private static Guid TabResourceId {get {return new Guid(TABRESOURCEID); } $

#endregion属性/变量



protected override void OnInit(EventArgs e)

{

base.OnInit(e);

RadScriptManager.GetCurrent(this).EnablePageMethods = true;

}



公开覆盖Guid ResourceId

{

get

{

返回PageResourceKeyConfig.SystemSettings ;

}

set

{

抛出新的NotImplementedException();

}

}



#region webmethods



[WebMethod]

public static void UpdateGeneralSettings(TicketSampling TicketSamplingDetails)

{

GeneralSetting objGeneralsetting = null;

objGenera lsetting = new GeneralSetting();

objGeneralsetting.Sampling = new TicketSampling()

{

SamplingPercentage = TicketSamplingDetails.SamplingPercentage,

};



string xmlstring = XMLSerializerHelper.GetAsXMLFromObject< generalsetting>(objGeneralsetting);

string tabname =General;



SaveSystemSettings(TabResourceId,tabname,xmlstring);

}



#endregion webmethods



private static bool SaveSystemSettings(Guid TabResourceId,string tabname,string xmlstring)

{

bool isSuccess = false;



使用(ISystemSettingsManager systemSettingManager = BLFactory.GetInstance< isystemsettingsmanager>(ContextProvider.CurrentContext))

{

isSuccess = systemSettingManager.SaveSystemSetting(TabResourceId,tabname,xmlstring);

}

return isSuccess;

}



我知道如果我在setting.aspx上面放置wwebmethod它会正常工作,但我需要放在.ascx.cs文件中。我怎样才能实现这一点。



提前致谢。
("#txtTimeInterval")[0].value;

TicketSampling = new Object();

TicketSampling.SamplingPercentage = txtSamplingPercentage;
UndeliveredMail.MailRetryCount = txtAttempts;
UndeliveredMail.RetryTimeInterval = txtTimeInterval;


PageMethods.UpdateGeneralSettings(TicketSampling);
}
return false;
}



GeneralSetting.ascx.cs=======>

public partial class Settings : PageBase
{
#region properties/variable
private const string TABRESOURCEID = "3BB29895-415B-46B6-9ED0-25539308579C";
private static Guid TabResourceId { get { return new Guid(TABRESOURCEID); } }
#endregion properties/variable

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
RadScriptManager.GetCurrent(this).EnablePageMethods = true;
}

public override Guid ResourceId
{
get
{
return PageResourceKeyConfig.SystemSettings;
}
set
{
throw new NotImplementedException();
}
}

#region webmethods

[WebMethod]
public static void UpdateGeneralSettings(TicketSampling TicketSamplingDetails)
{
GeneralSetting objGeneralsetting = null;
objGeneralsetting = new GeneralSetting();
objGeneralsetting.Sampling = new TicketSampling()
{
SamplingPercentage = TicketSamplingDetails.SamplingPercentage,
};

string xmlstring = XMLSerializerHelper.GetAsXMLFromObject<generalsetting>(objGeneralsetting);
string tabname = "General";

SaveSystemSettings(TabResourceId, tabname, xmlstring);
}

#endregion webmethods

private static bool SaveSystemSettings(Guid TabResourceId, string tabname, string xmlstring)
{
bool isSuccess = false;

using (ISystemSettingsManager systemSettingManager = BLFactory.GetInstance<isystemsettingsmanager>(ContextProvider.CurrentContext))
{
isSuccess = systemSettingManager.SaveSystemSetting(TabResourceId, tabname, xmlstring);
}
return isSuccess;
}

I know if i placed above wwebmethod in setting.aspx it will work fine, however i need to place inside .ascx.cs file. How can i achieve this.

Thanks in advance.


这篇关于是否可以将webmethod放在.ascx.cs文件中而不是.aspx文件中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆