I have a parent page containing an iframe, an ASP label and a button.
When the user click on the parent button, it will display some table results inside the iframe.
Now i would like to display the parent label with different text and color depending on the results of the iframe.
So i m trying in the code behind (C#) of the iframe to retrieve the label from the parent and assign it a CssClass. But no matter what i do it always come back with a null reference when trying to find the control from the parent.
Can someone please help?
Parent page code:
<div class="search-row">
<div class="search">
<button id="btnSearch" type="submit" class="button button-block">Search</button>
</div>
<div class="search" style="padding-top: 20px;">
<asp:Label ID="wrapperResponse" CssClass="resp" runat="server">TEST</asp:Label>
</div>
</div>
<div id="iframeDiv">
<iframe name="my_frame" width="100%" height="350px" src="Results.aspx" scrolling="no" frameborder="0"></iframe>
</div>`
The Results.aspx will display a table with some html build dynamically.
Now let s say if resulting Table has one row, i would like Label WrapperReponse to be in Green and says "1 row" but if 2 rows then i would like it to be in Red and says "2 Rows"
In my Results.aspx.cs i tried
String test= String.Format("{0}", Request.Form["wrapperResponse"]);
Label statusResponse = (Label)this.FindControl("wrapperResponse");
Label statusResponse2 = (Label)Parent.FindControl("wrapperResponse");
Any ideas are welcome!
thanks
Well, just a couple of points needed mentioning here. Food for thought.
In order to access the asp label control, you need to do it on the parent page instead of on the results page.
I would suggest you reconsider the design of the page. Do you really have to use the iframe here? Why not place your button and label controls on the results.page directly? Or perhaps make results.aspx as an ASCX user control, so you can embed it on the parent page.
Hope it helps
Related
On the admin side of my DotNetNuke website, I have two tabs with a few controls. I have also a grid view control on Tab 1 with a few records from the SQL server database i.e. Default Images & Slider Images. Each of the grid view row on Tab 1 also has an Edit button which fills the required textboxes (Image Title, Path, and URL, etc) of Tab 1 with data from that particular row in the code-behind.
When the user clicks on the edit button, an if statement on the code-behind file will check the type of the selected image. If it is a Slider Image, then it's title and URL will be passed to those particular textboxes on Tab 1.
However, if it is a Default Image, then I want to activate Tab 2 and pass the Title, Path, and URL of this default image those specific textboxes on Tab 2.
Is there any way to handle this from c# (code-behind)? Can I mark these tabs something like server controls, so I can easily get them with c# and activate the Tab 2? Any help will highly be appreciated.
Here is an illustration of the Tabs markup I am currently working on.
<div class="dnnForm dnnModuleSettings dnnClear" id="dnnAcProjectsModuleSettings">
<ul class="dnnAdminTabNav dnnClear">
<li>Tab 1</li>
<li>Tab 2</li>
</ul>
<div id="A" class="HomeRoomSlider">
<div class="mspsContent dnnClear">
<fieldset>
//Controls etc
</fieldset>
</div>
</div>
<div id="B" class="HomeRoomSliderDefault">
<div class="mspsContent dnnClear">
<fieldset>
//Controls etc
</fieldset>
</div>
</div>
At the moment, I have a GridView that pulls from a SQL data source. Every row has a summary in it, and when a user clicks expand on the row, they get a DetailsView with the details of that particular item in it.
I'm looking for a way to make it so DetailsView only binds to the DataSource when the row is expanded. At the moment it happens on RowDataBound, which results in heaps of queries going back and forth between the SQL server and the ASP NET server.
I'd also like to use Bootstrap to expand and collapse these rows, so it looks good when it expands or collapses.
Any help would be very much appreciated :) I've really tried to find some resources that would assist me in the above, but I've come up bumpkis. The closest I've gotten is an AJAX CollapsiblePanel, but it loads everything at Page_Load anyway.
You are battling two different areas here, and this comment is the one that makes it more complicated:
I'd also like to use Bootstrap to expand and collapse these rows, so it looks good when it expands or collapses.<
What I did was use BS panels and a repeater and with this approach, you can still databind details on a click event but you need some hidden controls inside your item templates for your DetailsView to bind the correct data. When you "loop" through your summary data, you'll need to provide an accurate link to BS expanding child - presumably an identifier and then another hidden control with the same. Run the link on the server so you can have a click event and assign the datasource and databind there.
Depending on how long it take your data to load, you might consider avoiding the databind on every click. If you are using BS to make it elegant, it seems counterproductive to add a postback - at least on the user experience/elegance side. I understand the want to avoid so many data calls though.
Hopefully this will get you started:
<asp:Repeater ID="RepeatCont" runat="server" ClientIDMode="Static">
<HeaderTemplate>
<div class="panel-inner">
<div class="panel-group" id="accCont"> // parent
</HeaderTemplate>
<ItemTemplate>
<div class="panel panel-dark-gray">
<div class="panel-heading">
<h5 class="panel-title">
<a class="panel-toggle" data-toggle="collapse" data-parent="#accCont" href='<%# "#" + Eval("MATCHID1") %>'> // add a postback here with linkbutton or javascript postback force - easier just do bind your child data because you'll have two different trying to happen - postback and data-toggle
<div>
//stuff on the panel
</div>
<div class="clearfix">
<br />
</div>
</a>
</h5>
</div>
<div id='<%# Eval("MATCHID1") %>' class="panel-body collapse">
//Hidden label with your MATCH ID 1 again - this is where you will tell your DetailsView to look for parameter
//put your details view here
</div>
</div>
</ItemTemplate>
<FooterTemplate>
</div>
</div>
</FooterTemplate>
I have a asp panel as below.
<asp:Panel ID="panele" runat="server">
<tr><td><fieldset ID="fsFieldset" class="crossbrowserfieldselect">
<legend align="left">Show the current values</legend>
</td>
<tr> <td><asp:Textbox id ="txtstudent" runat"server"></td>
<asp:panel>
There are many more text boxes and dropdownlists inside the fieldset and to reduce the complexity I did not put the entire code. I have this aspx page and it has 3 modes(select, update,insert). In select mode, aspx page should not display panel. By default the asp panel is visible. I am making it invisible in one of the functions in code behind that drives select mode as shown below. All the controls are readonly in this mode.
enter code here
function selectvalues ()
{
panele.Visible=False; /*code behind */
}
In insert mode, panel should be displayed and working as expected. In update mode, when user tries to edit date of birth value (it is date picker control), the panel should be displayed.Update mode also uses the above function and only when date of birth value is selected the panel should be displayed. Hence I wrote a javascript code to display panel as below.
<Datechooser Width="100px" runat="server" ID="BirthDate"
onselect="return setpanelcontrols();"
</Datechooser>
enter code here
function setpanelcontrols()
{
var objpanele=document.getElementById("<%=panele.ClientID%>");
objpanele.style.display="block";
return true;
}
When I select date of birth, the panel is not displayed. I dont know whats wrong. I really appreciate any help on this.
enter code here
Controls with Visible=False are not rendered as part of the HTML. Try hiding and showing trough CSS like this in your code behind:
panele.CssClass= "myHidePnlclass";
or what I think will fit your current code:
panele.Style["display"] = "none";
When you set the asp:Control Visible Property to false from code behind. The browser doesn't render that element and you can't make it visible from client side (jquery, javascript) then.
To hide it from code behind Replace:
panele.Visible=False;
With
panele.Attributes.Add("style", "display:none");
I see that there is problem with tags. Panel is rendered as div and i have applied the css style with visibily hidden. Finally when i tried to inspect element, i found an interesting thing. Below is the asp code as I posted before. However I added a div to see whats happening.
<tr><td><fieldset ID="fsFieldset" class="crossbrowserfieldselect">
<legend align="left">Show the current values</legend>
</td>
<tr> <td><asp:Textbox id ="txtstudent" runat"server"></td>
<asp:panel>
</div>
Below is the css via inspect element
<div id="BasicInfo_pane" style="visibility:hidden;">
<div id="BasicInfo_panele" class="styleset1" style="visibility:hidden;display:none;">
</div></div>
<table>
<tbody>
<tr>
<td> fieldset="fsFieldset"........ </td> </tr> </tbody> </table>
Clearly for some reason the panel has ended before fieldset as div's ended before fieldset (i think start and end tags are not properly organized, dont know why). And I think this is the reason the fieldset inside panel is not hidden. Panel is hidden and as fieldset is not hidden the output is displayed in browser and I misunderstood that panel is not hidden.
Use
ClientIDMode="Static"
on the asp panel and then in JavaScript:
function selectvalues ()
{
if(YOUR CONDITION){
$('#panele').hide();
}
}
This is the scenario:
I have a Master Page,
In the Master Page I have a user control
In the User Control there is a code that looks like this
<div>
<a id="p1" runat="server">
<asp:Image ID="Img" runat="server" ImageAlign="AbsMiddle" Style="position:relative;
bottom: 0px;" /></a> -<a id="p2" runat="server">
<asp:Label ID="lblRate" runat="server"></asp:Label>
Rates</a>
</div>
Now, when the user clicks on "Rates" it should focus on an item that is another User Control back in the Master Page.
How can I do this?, this is existing code and can not modify the current structure but what is currently happening is that when "Rates" is clicked it postsback with a parameter goto=rates but doesnt do anything.. I need to make so that when it is clicked it focuses on another UserControl in the Master Page. (but this "Rates" link is User Control too)
I tried in my Master Page the following
if(!Page.Postback)
{
if(Request.Params["goto"] == "rates"){
uControl.Focus();
}
}
No luck, please help :(
So to recap:
MasterPage has UserControl -> UserControl has a link that postsback with parameter goto=rates -> back in the MasterPage I need to focus the screen on another UserControl.
I tried to be as clear as I could
Thank you
not all controls supports focus like this. for your user control, you may need build javascript to setup focus.
Looks like you have a not opperator where you should. You should change if(!Page.Postback) to if(Page.Postback).
So there is a a table and a text box in one of the cells
<td>
<asp:TextBox ID="tbSomeTextBox" Columns="5" runat="server"> %
</td>
This textbox gets shown if a certain selection is made in a drop down. The problem is that I would like the "%" character to also be hidden or shown with the textbox.
I have tried putting the whole textbox control inside a DIVand in my JQuery hiding the DIV at the same time I hid the textbox.
<td>
<div id="divSomeDIV"><asp:TextBox ID="tbSomeTextBox" Columns="5" runat="server"> % </div
</td>
But I get an error in my java script that id="divSomeDIV" doesn't exist in the current context.
$("#<%=divSomeDiv.ClientID%>").hide();
Wrapping that single character in a asp:Label seems like overkill.
Any suggestions?
divSomeDiv is running client-side (i.e. no "runat=server"), so there's no need for
$("#<%=divSomeDiv.ClientID%>").hide();
Just do
$("#divSomeDiv").hide();
create an asp.net label, set the label value to be %, and make them both visible or both not visible at the same time... ?
If you were getting "does not exist" in your Javascript it's probably because your Javascript is running before the div is created in the dom. In other words, this is incorrect.
<script>$("#divSomeDiv").hide()</script>
<div id="divSomeDiv">...</div>
You can either put the Javascript after the div
<div id="divSomeDiv">...</div>
<script>$("#divSomeDiv").hide()</script>
Or you can make your Javascript run after the DOM has loaded.
<script>
$(function() {
$("#divSomeDiv").hide()
});
</script>
<div id="divSomeDiv">...</div>