Call another ASP Page dynamically with different Parameters in ASP.NET C# - c#

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>

Related

PostBackUrl not working in page with master page

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" />

Is it possible to add a hyperlink to ASP LinkButton

I have a link button that I want to put a hyperlink to that a popup div is called when the button is clicked.
The asp linkbutton is declared as such:
<TD Class="SpreadSheet"<ASP:LinkButtonID="lbtnViewUsers_Edit" Text="Edit" Runat="Server" onclick="#Upload"/></TD>
and the popup to be called is
<div id="Upload" class="overlay" runat="server">
<div class="popup">
<h2>Edit User &nbsp </h2>
<a class="close" href="#">×</a>
<div class="content">
<!-- content -->
</div>
</div>
</div>
Is there a way to put a sort of href = "#Upload" to the link button?
What you are looking for is a model pop. Asp.net Ajax tool kit has one, you can learn more about it at here . I created a simple sample of how to use this model pop-up. Bear in mind you first have to add the tool kit to your asp.net project (you can use nuget package manager for this) and register the control to page using
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
use the properties of Model pop extender to show and save your per record data.
<asp:Panel ID="pnlpopup" runat="server" Width="400px">
<asp:Panel ID="headerPanel" runat="server">Header text Here </asp:Panel>
<div class="form-group">
<asp:Label ID="Label1" runat="server" Text="lable 1"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
<div class="form-group">
<asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="Save" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</div>
</asp:Panel>
<div class="form-group">
Other data values here
<asp:LinkButton ID="lbEdit" runat="server">Edit</asp:LinkButton>
</div>

Update Panel - The ScriptManager must appear before any controls that need it

I tried to put an update panel in my aspx form, but it keeps on showing this error. The ScriptManager must appear before any controls that need it
This is my aspx
<form id="Form1" runat="server" class="form-horizontal">
<div class="col-lg-6">
<%--<asp:Panel id="pnlExisting" runat="server">
<div class="alert alert-danger" role="danger">
<i class="glyphicon glyphicon-exclamation-sign"></i> <asp:Label ID="recordCheck" runat ="server"> </asp:Label>
</div>
</asp:Panel>--%>
<div class="form-group">
<label class="control-label col-lg-4">Project</label>
<div class="col-lg-8">
<asp:DropDownList ID="ddlProjects" runat="server" class="form-control" AutoPostBack="true"
onselectedindexchanged="ddlProjects_SelectedIndexChanged" /><br />
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-4">Project Code</label>
<div class="col-lg-8">
<asp:Textbox ID="txtProjectCode" runat="server" class="form-control" required />
</div>
</div>
<%-- <div class="form-group">
<label class="control-label col-lg-4">Price</label>
<div class="col-lg-8">
<asp:Textbox ID="txtPrice" runat="server" class="form-control" Textmode="Number" required />
</div>
</div>--%>
<%-- <div class="form-group">
<label class="control-label col-lg-4">Status</label>
<div class="col-lg-8">
<asp:Textbox ID="txtStatus" runat="server" class="form-control" required />
</div>
</div>--%>
</div>
<asp:UpdatePanel ID="upMaterialsList" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lvMaterialsList" EventName="PagePropertiesChanging" />
</Triggers>
<ContentTemplate>
<table class="table table-hover">
<thead>
<th>Material</th>
<th>Quantity</th>
<th>Status</th>
<th>Date Added</th>
<th>Date Modified</th>
<th></th>
</thead>
<tbody>
<asp:ListView ID="lvMaterialsList" runat="server" ondatabound="lvMaterialsList_DataBound"
onpagepropertieschanging="lvMaterialsList_PagePropertiesChanging" OnItemCommand="lvMaterialsList_ItemCommand">
<ItemTemplate>
<tr>
<td><%# Eval("SupplierProduct")%></td>
<td><%# Eval("Quantity") %></td>
<td><%# Eval("Status") %></td>
<td><%# Eval("DateAdded", "{0: MMMM dd, yyyy}") %></td>
<td><%# Eval("DateModified", "{0: MMMM dd, yyyy}") %></td>
<td>
<asp:Label ID="ltReqMat" runat="server" Text='<%# Eval("ReqMatID") %>' Visible="false" />
</td>
<td>
<asp:LinkButton Text="Approved" class="btn btn-success " ID="lbtnApproved" runat="server"
CommandName="Approve" > </asp:LinkButton>
<asp:LinkButton Text="Decline" class="btn btn-warning " ID="lbtnDecline" runat="server"
CommandName="Decline" > </asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
<tr>
<td colspan="12"><h2 class="text-center">No records found.</h2></td>
</td>
</tr>
</EmptyDataTemplate>
</asp:ListView>
</tbody>
</table>
<div class="col-lg-12">
<center>
<asp:Button ID="btnReturn" runat="server" class="btn btn-default" Text="Back"
PostBackUrl="Default.aspx" formnovalidate />
</center>
</div>
<br />
<center>
<asp:DataPager ID="dpMaterialsList" runat="server" PageSize="10" PagedControlID="lvMaterialsList">
<Fields>
<asp:NumericPagerField ButtonType="Button"
NumericButtonCssClass="btn btn-default"
CurrentPageLabelCssClass="btn btn-success"
NextPreviousButtonCssClass="btn btn-default" />
</Fields>
</asp:DataPager>
</center>
</ContentTemplate>
</asp:UpdatePanel>
</form>
I want to know why it is not working properly
Add ScriptManager tags just below the <Form> tag of your page.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
You have to include the ScriptManager control in either your content page or Master page to enable ASP.NET AJAX features. So in your Master page you can place this control just after the form tag and ensure you put it before any ContentPlaceHolder control:-
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</form>
By this all the content page which have the Master page set to the above master will automatically use this ScriptManager.
Apart from this, if at all you want to include any specific script reference in any of your content page then you can make use of ScriptManagerProxy control which at run time will combine the properties of both ScriptManager and ScriptManagerProxy.
According to ASP.NET AJAX:-
ScriptManager - A server control that makes script resources available
to the browser, including the Microsoft AJAX Library and the
functionality that enables partial-page rendering.
ScriptManagerProxy - A server control that enables nested components
to add script and service references if the page already contains a
ScriptManager control.

The UpdatePanel doesn't work with button

I had my code to insert values into DB and after the data inserted the
ModalPopupExtender show and when click on OK button event fire to
reload the page . but I don't want all paged reload I tried to use
update panel but the OK event doesn't work .
<asp:Panel ID="PostPanel" runat="server" Style="display: none;">
<div class="modalPopup">
<div class="PopupBody">
<p class="ads-text">
GO </p>
</div>
<div class="Controls">
<div class="post">
<asp:Button Text="OK" runat="server" ID="btnOkay" ValidationGroup="AddUserpopup"
OnClick="btnOkay_Click" />
</div>
</div>
</div>
</asp:Panel>
<cc1:ModalPopupExtender ID="ModelExtenderPost" OkControlID="btnOkay" runat="server"
TargetControlID="HiddenField22" PopupControlID="PostPanel" PopupDragHandleControlID="PopupHeader"
Drag="true" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
<asp:HiddenField ID="HiddenField22" runat="server" />
protected void btnOkay_Click(object sender, EventArgs e)
{
Response.Redirect(Request.Url.ToString(), true);
}
use updatepanel that is in asp.net
in top of your page :
<%# Page Title="" Language="C#" MasterPageFile="~/..." EnableEventValidation="false" AutoEventWireup="true" ....
and for ypur panel:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode= "Conditional">
<ContentTemplate>
<div class="modalPopup">
<div class="PopupBody">
<p class="ads-text">
GO </p>
</div>
<div class="Controls">
<div class="post">
<asp:Button Text="OK" runat="server" ID="btnOkay" ValidationGroup="AddUserpopup"
OnClick="btnOkay_Click" />
</div>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnOkay" EventName ="Click" />
</Triggers>
</asp:UpdatePanel>

How to register a new user using asp.net(C#)?

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);

Categories

Resources