in my web application I have master page and it has too many content pages and in my content pages I want to post form to other URL. but its not posting the values to other page in this way.
But When I do the same code in simple aspx page without masterpage it works well.
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<form id="frmPay">
<div>
<!-- Receiver Details -->
<input type="hidden" name="merchant_id" id="merchant_id" value="xxgxg" >
<input type="hidden" name="merchant_key" id="merchant_key" value="gxgagag" runat="server">
<input type="hidden" name="return_url" id="return_url" value="http://www.widget.co.za/payment_finished" runat="server">
<input type="hidden" name="cancel_url" id="cancel_url" value="http://www.widget.co.za/payment_cancelled" runat="server">
<input type="hidden" name="notify_url" id="notify_url" value="http://www.widget.co.za/payment_notify" runat="server">
<!-- Payer Details -->
<input type="hidden" name="name_first" id="name_first" value="Bob" runat="server">
<input type="hidden" name="name_last" id="name_last" value="Smith" runat="server">
<input type="hidden" name="email_address" id="email_address" value="bob.smith#example.com" runat="server">
<!-- Transaction Details -->
<input type="hidden" name="m_payment_id" id="m_payment_id" value="TRN123456789" runat="server">
<input type="hidden" name="amount" id="amount" value="200.00" runat="server">
<input type="hidden" name="item_name" id="item_name" value="Widget Model 123" runat="server">
<input type="hidden" name="item_description" id="item_description" value="Widget Model 123" runat="server">
<!-- Transaction Options -->
<input type="hidden" name="email_confirmation" id="email_confirmation" value="" runat="server">
<!-- Security -->
<input type="hidden" name="signature" id="signature" value="" runat="server">
<asp:Button ID="Button1" runat="server" PostBackUrl="https://www.payfast.co.za/eng/process" Text="Button" />
</div>
</form>
</asp:Content>
Your <form> element does not have an action="" attribute - the form won't go anywhere (or rather, it will submit to the current URI (whatever it is)). If you want to submit values to another page in ASP.NET you can read this: http://www.codeproject.com/Articles/14092/Cross-Page-Posting-in-ASP-NET-2-0
Related
I have one page with masterpage as 'checkout.aspx' with asp button in bottom
<%# Page Title="" Language="C#" MasterPageFile="~/allpage.Master" AutoEventWireup="true" CodeBehind="checkout.aspx.cs" Inherits="CafeSite.checkout" %>
<asp:Content ID="Content1" ContentPlaceHolderID="title" runat="server">
B Cafe Checkout
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="body" runat="server">
<br>
<form id="form1" runat="server" action="submit.aspx">
<div style="text-align:center;">
<p style="color:orangered;font-family:'B Koodak';">
<span style="color:white;">آقا/خانم:</span>
<input type="hidden" name="last-form-name" value="<% =Page.Request.Params["last-form-name"] %>" /> <% =Page.Request.Params["last-form-name"] %>
</p>
<p style="color:orangered;font-family:'B Koodak';">
<span style="color:white;">به شماره موبایل:</span>
<input type="hidden" name="last-form-phone" value="<% =Page.Request.Params["last-form-phone"] %>" /> <% =Page.Request.Params["last-form-phone"] %>
<span style="color:white;">به شماره میز:</span>
<input type="hidden" name="last-form-sellist" value="<% =Page.Request.Params["last-form-sellist"] %>" /> <% =Page.Request.Params["last-form-sellist"] %>
</p>
<input type="hidden" name="order" value="<% =Page.Request.Params["order"] %>" />
<input type="hidden" name="count" value="<% =Page.Request.Params["count"] %>" />
</div>
<p id="P-Header">
سفارشات شما
به شرح ذیل می باشد
</p>
<div class="text-center">
<div class="text-center">
<div id="Table-Div" class="container" >
<asp:Table ID="Table1" runat="server" Height="100%" Width="100%">
</asp:Table>
</div>
</div>
<br>
<asp:Button ID="Button1" runat="server" form="form1" CssClass="btn-success rounded" Text="مورد تایید است" PostBackUrl="~/submit.aspx" />
</div>
</form>
<br>
</asp:Content>
my asp button has postbackurl to my submit page but is not working
I don't know how to solve this proble. does anyone know how to solve this and help me?
Add the form to the master page not the subpage just after the body.
Something like
<body>
<form runat="server" id="myformID" enctype="multipart/form-data">
Then just add a button to the sub-page and wire it up like normal in the code behind
I found the answer of my question.
In the aspx page with master page the form id is change and so here we should edit form properties on asp button from form1 to aspnetForm.
<asp:Button ID="Button1" runat="server" form="aspnetForm" CssClass="btn-success rounded" Text="مورد تایید است" PostBackUrl="~/submit.aspx" />
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" MasterPageFile="MasterPage.master" %>
<asp:Content ID="ContentPlaceHolder1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>
<asp:Content ID="ContentPlaceHolder2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<br />
<div id="signupform">
<form class="signupform" name="formreg" runat="server" onsubmit="return valform()"> <br/>
<input dir="rtl" type="text" name="uname" class="uname"/> </br>
<input dir="rtl" type="text" name="fname" class="fname"/> </br>
<input dir="rtl" type="text" name="lname" class="lname"/> </br>
<input dir="rtl" type="password" name="pword" class="pword"/> </br>
<input dir="rtl" type="password" name="rpword" class="rpword"/> </br>
<input dir="rtl" type="text" name="mmail" class="mail"/> </br>
<input dir="rtl" type="text" name="rmail" class="rmail"/> </br>
<input dir="rtl" type="text" name="gil" class="gil"/> </br>
<input type="checkbox" name="anon" value="True" class="dropan"/></br>
<input type="submit" name="sub" class="subbutton" value=""/>
<%=registrationstatus %>
</form>
</div>
</asp:Content>
This is my code, My problem is that the onsubmit="return valform()" attribute on my form wont fire if the runat="server" attribute exists, they can't work together please help me I am clueless why these two attributes wont work together
This is because you can't use both together. As said in the docs -
<input type="text" id="Textbox1" runat="server">
Doing this will give you programmatic access to the HTML element on the server before the Web page is created and sent down to the client. The HTML element must contain an id attribute. This attribute serves as an identity for the element and enables you to program to elements by their specific IDs. In addition to this attribute, the HTML element must contain runat="server". This tells the processing server that the tag is processed on the server and is not to be considered a traditional HTML element.
Here is the reference.
http://msdn.microsoft.com/en-us/library/aa478973.aspx
under section - Using HTML Server Controls
So, HTML with run='server' will not be treated as a normal Html element and thus will always be processed by the server. If you want to override the default behavior, you have to bind your javascripts with after the html is loaded in the browser, may be using jQuery or something similar. With jQuery something like this would help -
$(function(){
$("#formreg").submit(function(){
return valform();
});
});
By examing your code, I reach on conclusion that you might be using another form tag on Master page and there is no javascript issue. Only one form tag(Server Side) can exists either on a master page or content page. They can not be nested. When you would use runat="Server" attribute on both of form tags then error occurs saying "A page can have only one server-side Form tag". So remove runat="server" attribute from one of the form tags, onsubmit would begin firing.
I solved it with very easy way.
if we have such a form
<form method="post" name="setting-form" >
<input type="text" id="UserName" name="UserName" value=""
placeholder="user name" >
<input type="password" id="Password" name="password" value="" placeholder="password" >
<div id="remember" class="checkbox">
<label>remember me</label>
<asp:CheckBox ID="RememberMe" runat="server" />
</div>
<input type="submit" value="login" id="login-btn"/>
</form>
You can now catch get that event before the form postback and stop it from postback and do all the ajax you want using this jquery.
$(document).ready(function () {
$("#login-btn").click(function (event) {
event.preventDefault();
alert("do what ever you want");
});
});
I want to call another ASP Page and pass a parameter (entry.ID).
I have a Master-Page Global.master like this (I will only post a part of code):
<body>
<div id="global" style="height:2000px;">
<form runat="server" id="globalForm">
<div id="body">
<asp:ContentPlaceHolder ID="mainContentPlaceHolder" runat="server">
<div id="mainContent">
</div>
</asp:ContentPlaceHolder>
</div>
</form>
</div>
and a Default.aspx Page which uses the Master-Page:
<asp:Content ID="Content1" ContentPlaceHolderID="mainContentPlaceHolder" runat="Server">
<div id="mainContent">
<% ICollection<Database.Blogentry> entries;
entries = Database.BlogentryDBO.Instance.getAllBlogentries();
foreach (Database.Blogentry entry in entries) { %>
<div class="blogEntryBody">
<div class="blogEntryText">
<%= entry.Content %>
</div>
</div>
<div class="blogEntryFooter">
<span class="blogEntryView">
<%--CALL HERE ANOTHER PAGE WITH A BUTTON AND PASS THE PARAMETER entry.ID-->
</span>
</div>
<%
}
%>
</div>
I already tried it with
<label visible="false" id="LabelEntryId" name="LabelEntryId"><%= entry.ID %></label>
<asp:button ID="Button2" runat="server" class="buttonBlogEntry" text="view more ..." onclick="viewEntireBlog_onclick" CommandArgument='<%# Eval("LabelEntryId")%>' />
but I don't have a CommandEventArgs element in the onClick method but only a EventArgs element so I can't access my CommandArgument?!
And using
<input runat="server" type="text" id="LabelEntryId" value="<%= entry.ID %>" visible="false"/>
and then accessing the input-element in the code-behind isn't possible either, because i have more than one LabelEntryId-Input because of the loop.
Another idea was to do something like this
<asp:button ID="Button1" runat="server" class="buttonBlogEntry" text="view more ..." onclick="<%= Response.Redirect("BlogEntrySortedByCategory.aspx?entryID=" + entry.ID); %>"/>
but I don't know how to do that...
Can you help me please?
have you tried with a standard a tag?
<a href='/someotherpage.aspx?entryid=<%= entry.Id %>'>View more</a>
I have following code snippet in my asp.net webpage.
<div id="descDiv" style="display:none;">
<form>
<asp:TextBox ID="inputDesc" Height="200px" Width="100%" runat="server" TextMode="MultiLine" placeholder="Enter any details you know about this city" required="required"></asp:TextBox>
<input type="button" Class="cancel" value="Cancel" OnClick="hideInput('descDiv');" /><asp:Button ID="Submit_Desc" CssClass="submit" runat="server" Text="Submit" OnClick="Submit_Desc_Click" />
</form>
</div>
When I click the submit button I receive this error:
Invalid postback or callback argument. Event validation is enabled using
<pages enableEventValidation="true"/> in configuration or
<%# Page EnableEventValidation="true" %> in a page.
For security purposes, this feature verifies that arguments to postback or
callback events originate from the server control that originally rendered them.
If the data is valid and expected, use the
ClientScriptManager.RegisterForEventValidation method in order to register the
postback or callback data for validation.
This form is enclosed in another main form which has 'runat' attribute. What should I do to correct this problem?
EDIT:
Here is the shortest code to reproduce the problem:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="descDiv">
<form>
<asp:TextBox ID="inputDesc" Height="200px" Width="100%" runat="server" TextMode="MultiLine" placeholder="Enter any details you know about this city" required="required"></asp:TextBox>
<input type="button" class="cancel" value="Cancel" onclick="hideInput('descDiv');" />
<asp:Button ID="Submit_Desc" CssClass="submit" runat="server" Text="Submit" OnClick="Submit_Desc_Click"/>
</form>
</div>
</div>
<form>
<asp:TextBox ID="TextBox1" Height="200px" Width="100%" runat="server" TextMode="MultiLine" placeholder="Enter any details you know about this city" required="required"></asp:TextBox>
<input type="button" class="cancel" value="Cancel" onclick="hideInput('descDiv');" />
<asp:Button ID="Button1" CssClass="submit" runat="server" Text="Submit" OnClick="Submit_Desc_Click"/>
</form>
</form>
</body>
</html>
You cannot have two forms on your page, remove the form tag just under your div. The one to keep has to be the form runat="server" since it's a .net page.
what you can do is use .net buttons and process whatever they do from code behind
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
</form>
protected void Button1_Click(object sender, EventArgs e)
{
// do something with button 1
}
protected void Button2_Click(object sender, EventArgs e)
{
// do something with button 2
}
I want to make a function to register a new user without using CreateUserWizard. How could I change my code to allow this?
<%# Page Language="C#" AutoEventWireup="true" CodeFile="registerUser.aspx.cs" Inherits="_Default" %>
<html>
<head runat="server">
<title>LLLY网上书店 - 注册</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<section class="register">
<h1>LLLY网上书店 - 注册新用户</h1>
<form method="post" action="index.html" runat="server">
<div class="reg_section personal_info">
<h3>个人信息</h3>
<asp:TextBox ID="username" runat="server" value="" placeholder="用户名"></asp:TextBox>
<asp:TextBox ID="email" runat="server" placeholder="电子邮件地址"></asp:TextBox>
</div>
<div class="reg_section password">
<h3>用户密码</h3>
<asp:TextBox ID="password" runat="server" placeholder="请输入密码"></asp:TextBox>
<asp:TextBox ID="confirmPwd" runat="server" placeholder="确认密码"></asp:TextBox>
<input type="password" name="confirm" value="" placeholder="确认密码">--%>
</div>
<div class="reg_section password">
<h3>地区</h3>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="textarea" runat="server" TextMode="MultiLine" placeholder="家庭住址"></asp:TextBox>
</div>
<p class="terms">
<label>
<input type="checkbox" name="remember_me" id="remember_me">
我同意 LLLY网上书店 注册准入原则
</label>
</p>
<p class="submit">
<asp:Button ID="commit" runat="server" Text="注册" onclick="commit_Click"></asp:Button>
</p>
</form>
</section>
</div>
</body>
</html>
Your question is not so simple and you can find a fully tutorial with source code and details on asp.net site:
Creating User Accounts (C#)
Also you can read the article about:Understanding ASP.NET Roles and Membership - A Beginner's Tutorial
If you want to create user by code you can use one of overload method of Create User in Membership class.
MSDN : Membership.CreateUser Method
MembershipCreateStatus status;
var user = Membership.CreateUser(username.Text, password.Text, email.Text, null, null, true, out status);