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?
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)
{
}
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>
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)
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
I have to make validation for password. It works fine but if i add runat=server my password validation does not work.And when i remove runat server it works fine.
my code is as:
<input value="" runat="server" class="validate[required] text-input" type="password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" name="password" id="password" />
<input value="" runat="server" class="validate[required,equals[password]] text-input" type="password" name="password2" id="password2" />
Any help on this topic will be appreciated.
You have taken normal HTML tag telling to act as server side control i,e runat="Server".Normal html control will not work as server side control,So please take asp.net controls and write required code.
<asp:TextBox runat="server"/>
when you put space in control properties asp create diffrent properties for element
in your textbox control you are creating properties like
required pattern
So, ASP Create your text box html like this
<input name="password" type="password" id="password" required="" pattern="asdsa" class="validate[required] text-input" />
Answer
So you need to create properties using code behind
you can Add control attribute at code behind if you having problem in ASP page
<input value="" runat="server" class="validate[required] text-input" type="password" name="password" id="password" />
at code behind
protected void Page_Load(object sender, EventArgs e)
{
password.Attributes.Add("required pattern","(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,}");
}