Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Comments
F-ES Sitecore 18-Mar-15 16:03pm    
Yes you can put it in the .cs file, just move it. You might have to add some "using" statements at the top, but Visual Studio's "Resolve" function should help with that (right-click anything with a squiggly line that can't be found and select Resolve from the context menu)

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900