Before reading my question I would recommend you to first read this article: http://blog.karbyn.com/articles/creating-a-custom-sitecore-administration-page-with-authentication/
. As in the article, I am working on implementing an admin backend for my sitecore built web application. So far; I have an action method called Page_Load which is responsible for rendering a form to the View - which enables Sitecore content users to query the Database, filtering the entries by DateTime. FormPost is empty and I will explain why shortly.
public partial class AdminUtility : AdminPage
{
protected void Page_Load(object sender, EventArgs e)
{
CheckSecurity(true); //Required!
base.OnInit(e);
}
protected void FormPost(object sender, EventArgs e)
{
}
}
Page_Load renders this form. Because of Sitecore routing I was having difficulty posting the data to a different aspx page. Hence, Is it possible to post the form directly back to the same controller class but this time the method "FormPost" can handle the request.
<form action="FormPost" id="form1" runat="server">
<p> Date From: <input type="text" name="DateFrom" id="DateFrom"> </p>
<p> Date To: <input type="text"name="DateTo" id="DateTo"> </p>
<input type="submit" />
</form>
Instead of using the Form attribute, try to place the onclick directly on the button as shown below using ASP.NET user control:
<div id="form1">
<p> Date From: <asp:TextBox runat="server" ID="DateFrom" /> </p>
<p> Date To: <asp:TextBox runat="server" ID="DateTo" /> </p>
<asp:Button runat="server" ID="SubmitButton" Text="Process" OnClick="FormPost"/>
</div>
Related
I'm working on a simple login screen with the below code:
<form id="login">
<div class="formHeader">
<h1>Login</h1>
</div>
<div class="formDiv">
<input type="text" placeholder="Email" name="txtEmail"/>
<div class="inputImage fa fa-user"></div>
</div>
<div class="formDiv">
<input type="password" placeholder="Password" name="txtPassword"/>
<div class="inputImage fa fa-lock"></div>
</div>
<div class="formDiv">
<label id="remember">
<input type="checkbox" name="cbxRemberMe" value="Checked"/>
<div class="checkbox"></div><span>Remember me</span>
</label>
</div>
<div class="formDiv">
<input type="submit" value="LOGIN" onclick="btnLogin_Click" />
</div>
<div class="formFooter"><a class="forgot" href="#">Forgot Password</a></div>
and back-end code
protected void btnLogin_Click(object sender, EventArgs e)
{
}
But the button does not call the backend code at all.
Nothing happens except the URL changes from
"http://localhost:15726/Pages/Login.aspx" to
"http://localhost:15726/Pages/Login.aspx?txtEmail=&txtPassword=&ctl00=LOGIN"
I cannot put a Runat=Server attribute in the form as I have 2 forms on this page (login and register)
any help is appreciated.
What I have tried:
Playing around with Runat=Server, onclick() and OnServerClick() (swapping around and changing them up)
Making input type=submit / input type=button
none of these work.
Have you tried these two approaches?
<asp:Button runat="server" id="btnLogin" Text="LOGIN" OnClick="btnLogin_Click">
or
< button onserverclick="btnLogin_Click" runat="server" id="btnLogin">LOGIN</button>
Edit
This was supposed to be a comment and not answer. Sorry for that.
However, the entire form doesn't seem to be "webform" form compatible. If you want to be able to read the values from the form elements the form should have a runat="server" tag, too.
Firstly, you need to specify whether it is a server control or client control. Specify runat=server to tell that it should be available for the Code-Behind file.
Finally, Use any javascript function with OnClick and any code behind function with OnServerClick
Something like this,
aspx
Plain HTML
<input type="submit" runat="server" value="LOGIN" onclick="return js_btnLogin_Click()" OnServerClick="btnLogin_Click"/>
or with ASPX Control
<asp:Button runat="server" Text="LOGIN" OnClientClick="return js_btnLogin_Click()" OnClick="btnLogin_Click">
javascript
<script type="text/javascript">
function js_btnLogin_Click()
{
//return false, in case if you want to stop posting the form to the server
return true;
}
</script>
Code-Behind
protected void btnLogin_Click(object sender, EventArgs e)
{
}
I started learning asp.net to make a very simple web app which can manage the scheduled tasks of the machine where it runs.
I have created a very simple form in the .aspx file:
<form id="form1" runat="server" OnClick="Form_Submit">
<p>
<input class="form-control" id="scheduleName" type="Text" runat="server" />
</p>
<p>
<input class="form-control" id="checkschedule" type="Text" runat="server" />
</p>
<p>
<input class="btn btn-default" value="Save" type="Submit" runat="server" />
</p>
</form>
I then have the following code on the corresponding .cs file
public partial class Content : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void Form_Submit(object sender, EventArgs e)
{
string test = scheduleName.Value;
checkschedule.Value = test;
}
}
I tested I can populate the inputs from the onload function (I will use it to show the list of schedules on the system)
But I cannot get to modify the value of checkschedule when I post the form from the browser - It doesn't change on my browser.
I guess I should notify that I've changed the value and send it back... but I cannot find a proper way to do it. Checked other answers but couldn't get my head around this.. any help is appreciated!
I solved it myself, using session - saved variables ( actually a better way of doing what I wanted to do)
I need to perform a postback in order to process a gateway payment by redirect, so i've got an example in order to do inside an html with server side code (runat=server in the inputs):
<form action="https://xxxxxxxx" method="post">
<input runat="server" type="text" id="param1" name="param1" value="asd" />
<input runat="server" size="100" type="text" id="parm2" name="parm2" value="asd" />
<input runat="server" type="text" size="50" id="param3" name="param3" value="asd" />
<input runat="server" type="submit" value="Post!" />
</form>
protected void Page_Load(object sender, EventArgs e)
{
// New instance of library and his magic
LibraryXXX r = new LibraryXXX();
r.Parameter.Add("xxxx", xxxx);
// more logic goes here
}
Clinking the submit button sends the postback and the page loads an html. I want traslate that sample to an aspx webform. The problem is i can't have more than one form label inside an aspx. So, how can i do the same postback inside an aspx?
Hi I am using input type text in login page but in aspx.cs page is not working
input control give the error. here is my .aspx Page-
<input type="text" id="txtloginname" name="txtloginname" required value="Username" onblur="if(this.value=='')this.value='Username'"
onfocus="if(this.value=='Username')this.value='' " /></p>
and Here is my aspx.cs page
SessionInfo.LoginName = txtloginname.Value.Trim();
SessionInfo.DisplayName = txtloginname.Value.Trim();
it gives the error Like --
The name 'txtloginname' does not exist in the current context
Input type "text" is pure html control, it is not available in server side. If you want these in server side, Add attribute runat="server" and in server side you can find these control as html Control.
if it is in master page do the following
System.Web.UI.HtmlControls.HtmlInputText txtLogin = this.Master.FindControl("FeaturedContent").FindControl("txtloginname") as System.Web.UI.HtmlControls.HtmlInputText;
not in master page
System.Web.UI.HtmlControls.HtmlInputText txtLogin = this.FindControl("txtloginname") as System.Web.UI.HtmlControls.HtmlInputText;
SessionInfo.LoginName = txtLogin.Value.Trim();
SessionInfo.DisplayName = txtLogin.Value.Trim();
OR
You can use jquery onchange event to get the textbox value and assign it to a asp hidden field, Now the hidden field with the textbox value is available in server side.
there are two ways of doing this for getting the value of input type in aspx page.
1)code for aspx page
<form id="form1" runat="server">
Name:
<input type="text" id="txtName" name="Name" value="Username" onblur="if(this.value=='')this.value='Username'"
onfocus="if(this.value=='Username')this.value='' " />
<br />
Email:
<input type="text" id="txtEmail" runat="server" value="" />
<br />
<br />
<asp:Button ID="Button1" Text="Submit" runat="server" OnClick="Submit" />
In aspx.cs page code
protected void Submit(object sender, EventArgs e)
{
string name = Request.Form["Name"];
string email = txtEmail.Value;
}
there are two text boxes in example and two ways to get text value .
you can use any one you like
you are getting error because for running server side code you need to add attribute runat="server" in the input control
In my Web Forms project, I've got a an <asp:UpdatePanel> and within the panel's <ContentTemplate> I'm using a couple of radio button groups derived from the UI Bootstrap example.
When the page performs a partial post-back in the UpdatePanel, I lose the Angular functionality and my Angular directives no longer control the radio button groups and their current selected buttons.
Granted, I've seen examples of how to call Javascript functions after a partial postbacks such as endRequestHandler and pageLoad but I'm not particularly sure how to craft this in such a way to work with Angular. The angular module is declared at the top of the page like
<html lang="en" ng-app="NewHireFormsManagement">
Here is a short and sweet version of the code I have now...
ASP.NET
<!-- Pull hidden data to set current radio button positions -->
<asp:Label ID="FormStatusCurrentStatusLabel" runat="server" Visible="false" />
<script type="text/javascript">
// Bind client-side events before/after async page-load
function pageLoad(sender, args) {
// Set and Update Form Status
var ITUpdateStatusRadios = function ($scope) {
$scope.radioModel = '<%= this.FormStatusCurrentStatusLabel.Text %>';
};
}
</script>
<asp:UpdatePanel ID="ITadminStatusUpdatePanel" runat="server">
<ContentTemplate>
<div ng-controller="ITUpdateStatusRadios">
<div class="btn-group">
<label class="btn btn-default" ng-model="radioModel" btn-radio="'Attention_Needed'">
<i class='fa fa-times-circle'></i> Attention Needed
</label>
<label class="btn btn-default" ng-model="radioModel" btn-radio="'Pending'">
<i class='fa fa-paper-plane-o'></i> Pending
</label>
<label class="btn btn-default" ng-model="radioModel" btn-radio="'Complete'">
<i class='fa fa-check'></i> Complete
</label>
</div>
<!-- Pull Results from this label on form submit -->
<input type="hidden" runat="server" id="FormStatusNewStatusInput" value="{{radioModel || 'null'}}">
</div>
<asp:Button ID="ITStatusUpdateSubmitButton" runat="server" OnClick="AdminStatusUpdateSubmitButton_Click" CssClass="btn btn-success" Text="Update" />
</ContentTemplate>
</asp:UpdatePanel>
C# Code-Behind
// Page Load
protected void Page_Load(object sender, EventArgs e)
{
...SQL stored procedure query
this.FormStatusCurrentStatusLabel.Text = sqlITFormStatusDataReader["CompletionStatus"].ToString(); // Current Form Completion status
}
// Update Button
protected void AdminStatusUpdateSubmitButton_Click(object sender, EventArgs e)
{
try
{
.. prepair sql connection
updateformsqlCmd.Parameters.AddWithValue("#udAdminCompletionStatus", FormStatusNewStatusInput.Value);
.. call stored procedure and update value
}
catch()
{
}
finally
{
}
}
Basically, the initial radio position is set dynamically based on data read from a database on on Page_Load. When 'Update' button is pressed, another event is called to update the same database table and then the current radio position would ideally be re-set in real time, again on Page_Load. It's just that the JS function is being lost for Angular.
Any ideas?