change iframe label from main asp.net page - asp.net

So, basically I have a simple asp.net page "Default.aspx" that has a textbox called "txt"and button "adjust_btn" and an iFrame that is linked to "preview.aspx" which has "label1" in header.
Here is the code I have for Default.aspx:
<p>
<asp:Button ID="preview_btn" runat="server" Text="Preview" Width="110px" OnClick="preview_btn_Click" />
<asp:TextBox ID="txt" runat="server" Width="200px" Height="25px"></asp:TextBox>
</p>
Here's the code I have in "Preview.aspx":
<h1> <asp:Label ID="Label1" runat="server" Text="Label1"></asp:Label> </h1>
Here's the code i have for the button click:
protected void preview_btn_Click(object sender, EventArgs e)
{
iframe.Visible= true;
// here i want something that does this iframe.label1 = textbox1.Text;
// so the label1 is in iframe and the textbox1 is in the main page..
}
Appreciate your help, team!

Related

Connecting Session from a repeater's item to another page doesn't work

I want to take the text in the text box from the particular item in the repeater that was clicked, and use it on the page ViewRecipe2.aspx.
Currently, when you click a button on one of the items, it returns back to the repeater's page, but the repeater does not appear, instead of moving to the page ViewRecipe2.aspx.
This is my repeater in aspx:
<asp:Repeater ID="RepeaterR" runat="server">
<ItemTemplate>
<div class="wrapper">
<table>
<div class="box">
<div class="property-card">
<div class="property-image">
<div class="property-image-title">
</div>
</div>
<div class="property-description">
<asp:Button CssClass="h5" runat="server" ID="Button1" OnClick="Button1_Click" Text=<%# Eval("recipeName")%> BackColor="Transparent" BorderColor="Transparent"/>
<p><%#Eval("avgRating") %> stars</p>
<asp:Image class="img" runat="server" src=<%#Eval("recipePic") %> />
<asp:TextBox ID="hiddenTB" runat="server" Text=<%# Eval("recipeName")%> Visible="false"></asp:TextBox>
</div>
</div>
</div>
</table>
</div>
</ItemTemplate>
</asp:Repeater>
This is the code behind on c#:
protected void Button1_Click(object sender, EventArgs e)
{
RepeaterItem item = (sender as Button).NamingContainer as RepeaterItem;
string VR = (item.FindControl("hiddenTB") as TextBox).Text;
if (VR!=null)
{
Session["selectedRecipe"] = VR;
Response.Redirect("ViewRecipe2.aspx");
}
}
This is ViewRecipe2.aspx:
<asp:TextBox ID="TextBoxP" runat="server"></asp:TextBox>
And the code behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string theRecipeName = (Session["selectedRecipe"]).ToString();
TextBoxP.Text = theRecipeName;
}
}
Well, text box or hidden field is "never" null.
but, you need quotes around that "text" setting of the hidden field.
<asp:TextBox ID="hiddenTB" runat="server"
Text='<%# Eval("recipeName")%>' Visible="false">
</asp:TextBox>
Also, keep in mind, that with visible=false, then the markup is NOT sent nor rendered client side. This means that client side js code can't use that text box, but server side code can just fine grab the textbox, and then the value as you have.
However, while you "should" have those single quotes?
it should still have worked.
I would for testing, remove the Visible="false", and then you can actually see + verify that the value is correct.

Asp.net ASP:Login and forms

On my webpage, I use ASP:Login, when members login to my page, very standard.
I also have a contact-form.
When I use my contact-form, there is no problem, but when I log in as a member, at use the contact form, nothing gets submitted, but the "form page" just loads again.
If I then fill out the form again, and hit the submit-button, the information is send.
My form is build like this:
<asp:Panel id="NameSug" Runat="server" DefaultButton="SendSug">
<asp:Textbox name="NavnForslag" id="NavnForslag" runat="server" width="200" MaxLength="18" /><br/><br/>
<asp:imagebutton id="SendSug" onclick="CupName_click" runat="server" ImageUrl="images/login.gif"/>
</asp:Panel>
So if I'm not logged in, and fill out the form, it sends right away. If I'm logged in, I have to hit the "send" button, fill out the form again, and hit send again.
My backend-file looks like this:
public partial class usercontrols_msgSystem_CupNameSugFront : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
// Do something
}
protected void CupName_click(object sender, ImageClickEventArgs e)
{
// Do something else
}
}
My overall form-tag (I have one, that "surrounds" all the forms), looks like this:
<form id="DasTeam" runat="server">
Also, my login-form looks like this:
<asp:Login id="Login1" runat="server" DestinationPageUrl="~/Login.aspx">
<LayoutTemplate>
<div id="login">
<asp:Panel ID="panelLogin" runat="server" DefaultButton="submitLoginBtn">
<p class="tekst_alias">Alias:</p>
<p class="box"><asp:TextBox ID="UserName" runat="server" Width="150px"></asp:TextBox></p>
<p class="tekst"> Password:</p>
<p class="box"><asp:TextBox ID="Password" runat="server" TextMode="Password" Width="150px"></asp:TextBox></p>
<p class="login"><asp:LinkButton ID="submitLoginBtn" CommandName="Login" runat="server" CssClass="loginbutton">Login</asp:LinkButton></p>
<p class="failure"><asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal></p>
</asp:Panel>

get info from one page and show it on other page

i m working on shopping cart site
i want to show complete information of a product contained in a div section. on an other page. i have may div that contained information.
goal is to get the info on a new page when user clicks some product's image.
Error:
Control 'MainContent_ImageButton1' of type 'ImageButton' must be placed inside a form tag with runat=server.
HTML:
<div id="physics" runat="server">
<h3>High School Physics</h3>
<%-- <img src="images/Book.jpg" /> --%>
<asp:ImageButton ID="ImageButton1"
src="images/Book.jpg" runat="server" onclick="ImageButton1_Click" />
<p> Book Description Goes Here
<br />
<asp:Label ID="Label1" runat="server" Text="Label">PKR 770/-</asp:Label>
<br />
<asp:TextBox ID="TextBox1" Text="1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Add" />
</p>
</div>
Code :
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
StringWriter sw = new StringWriter();
HtmlTextWriter w = new HtmlTextWriter(sw);
physics.RenderControl(w);
Session["mySessionVar"] = sw.GetStringBuilder().ToString();
Response.Redirect("ShowLarge.aspx", true);
}
HTML: where i want to show this info
<div id="ShowInLargeView" runat="server">
</div>
Code:
protected void Page_Load(object sender, EventArgs e)
{
ShowInLargeView.InnerHtml = (String)Session["mySessionVar"];
}
i want to show the complete info of Div in an other page. i m getting an error. this scenario is about shopping cart
i need help
please help.
The error you are getting is related to the fact that you are trying to add an event handler
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
In order to add an event handler to an element on your page it will need to be encapsulated in a 'form' with the runat="server" attribute. this will result in the click event of the ImageButton ending up in your code-behind.
so your aspx would become something like :
<form runat="server">
<div id="physics" runat="server">
<h3>High School Physics</h3>
<%-- <img src="images/Book.jpg" /> --%>
<asp:ImageButton ID="ImageButton1"
src="images/Book.jpg" runat="server" onclick="ImageButton1_Click" />
<p> Book Description Goes Here
<br />
<asp:Label ID="Label1" runat="server" Text="Label">PKR 770/-</asp:Label>
<br />
<asp:TextBox ID="TextBox1" Text="1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Add" />
</p>
</div>
</form>
In general it should suffice to encapsulate your entire page in a form tag, this way all events will be passed to your code-behind.

modalpopupextender always shown and targetcontrolid is not working

I have a repeater and it has a column of linkbuttons in it. I want to add those linkbuttons to targetcontrolid but it failed because they are in the repeater. So i create an additional invisible button like this :
<asp:Button ID="btnFakePopUp" runat="server" Text="" visible="false"
onclick="btnFakePopUp_Click"/>
And in i tried to link the linkbutton to the invisible button in this code :
protected void lbtnPosition_Click(object sender, EventArgs e) {
btnFakePopUp_Click(sender, e);
}
protected void btnFakePopUp_Click(object sender, EventArgs e)
{
popupJob.Show();
}
And this is my modalpopupextender code (my prefix is asp: so dont get confuse) :
<asp:ModalPopupExtender ID="popupJob" runat="server" PopupControlID="panelPopup" CancelControlID="popupClose" TargetControlID="btnFakePopUp"
Drag="true" PopupDragHandleControlID="panelPopup">
</asp:ModalPopupExtender>
<asp:Panel ID="panelPopup" runat="server" BackColor="#ebf0ff" Width="300px">
<div>
test<br />
<asp:Button ID="btnSave" runat="server" Text="Save" />
<asp:Button ID="btnApply" runat="server" Text="Apply" />
<input id="popupClose" type="button" value="Close" />
</div>
</asp:Panel>
The problems are :
1. The panelpopup is always shown...(it should be hidden, and only be shown when the user click the link button)
2. Nothing happened when i tried to click the link button (the panelpopup should be shown)
Thank you :D
For a btnFakePopup invisible you could set the display:none with CSS
example:
<asp:ImageButton ID="btnFakePopUp" runat="server" style="display: none"></asp:ImageButton>
I don't understand why, but setting btnFakePopUp visibility to true corrected the problem. Now my modalpopupextender is running smoothly.

Dynamicly created repeater and ItemCommand event problem

A strange problem.
On my page i have a placeholder where I create a repeater on run time.
In ItemTemplate i have a button that invokes repeater_ItemCommand event.
I put a breakpoint on first line of repeater_ItemCommand event, when the button is triggered the event is invoked as planned, but after RebindRepeaters() is finished, when i click on the button again repeater_ItemCommand event is not invoked!
Only if i click on the button one again it invokes, in other scenarios(this is simple version of my page, in original page i have updatepanel that complex everything) it never invokes!
My aspx code:
<form id="form1" runat="server">
<div id="talk">
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
My Code-behind:
protected void Page_Init(object sender, EventArgs e)
{
RebindRepeaters();
}
void RebindRepeaters()
{
PlaceHolder1.Controls.Clear();
CreateRepeater(PlaceHolder1);
}
void CreateRepeater(Control container)
{
Repeater repeater1 = new Repeater();
repeater1.ItemCommand += new RepeaterCommandEventHandler(repeater_ItemCommand);
repeater1.ItemTemplate = Page.LoadTemplate("CommentsTemplate.ascx");
container.Controls.Add(repeater1);
repeater1.DataSource = Comment.GetCommentsP(8, 0);
repeater1.DataBind();
}
void repeater_ItemCommand(object sender, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "Edit":
RebindRepeaters();
break;
}
}
The CommentsTemplate.ascx:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="CommentsTemplate.ascx.cs" Inherits="CommentsTemplate" %>
<ul>
<li>
<div class="show">
<div class="c">
<asp:LinkButton ID="lbtnTitle" runat="server" Text='<%#Eval("EncodedTitle")%>'
CausesValidation="false" CommandName="VoteUp" OnClientClick="viewHide(this);return false;" CommandArgument='<%#Eval("ID")%>'></asp:LinkButton>
<p class="d"><%#Eval("AddedBy")%>,<%#Eval("AddedDate")%></p>
<div class="CommentBody"><%# Eval("EncodedBody") %>
</div>
</div>
<div class="userpanel">
<asp:Panel runat="server" ID="panAdmin" Visible='<%# UserCanEdit %>' style="float:left;">
<asp:ImageButton runat="server" ID="btnSelect" CommandName="Edit" CommandArgument='<%# Eval("ID") %>'
CausesValidation="false" AlternateText="Edit comment" ImageUrl="~/Images/Edit.gif" />
<asp:ImageButton runat="server" ID="btnDelete" CommandName="Delete" CommandArgument='<%# Eval("ID") %>'
CausesValidation="false" AlternateText="Delete comment" ImageUrl="~/Images/Delete.gif"
OnClientClick="if (confirm('Are you sure you want to delete this comment?') == false) return false;" />
</asp:Panel>
</div>
</div>
</li>
</ul>
If you need more info just ask.
Could you try overidding createChildcontrols and add the RebindRepeaters call there instead of in Page_Init? And make sure to give your repeater an explicit ID:
Repeater repeater1 = new Repeater();
repeater1.ID = "repeater1";
Without an id the asp.net event handling won't know where the event was called from.
Dynamic controls have to be re-added on every postback in order for their events to fire. A new control tree is being created on the postback and the dynamic control is no longer in it, therefore ASP.NET can't evaluate the change in order to fire the event.
EDIT: I was able to fire the event each click by removing RebindRepeaters(). You were binding it twice, once here and once in (Page_Init):
void repeater_ItemCommand(object sender, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "Edit":
//RebindRepeaters();
break;
}
}

Resources