close Jquery Modal popup Datalist button click - asp.net

i am running into a problem that i have a jquery modal popup in my usercontrol that i show on a click of a button and user selects something from datalist and then i returned some value on the parent user control in a hidden field all is fine till here but after the click on the select button i want the jquery modal to be closed also
here is some code of the div which i show in modal diaog
<asp:UpdatePanel ID="upDatagrabber" runat="server">
<ContentTemplate>
<table>
<tr>
<td>Select Category</td><td><asp:DropDownList ID="ddlTemplateCatagory"
runat="server" AutoPostBack="True"></asp:DropDownList></td>
</tr>
<tr>
<td colspan="2">
<table cellspacing="0" cellpadding="0" border="0" style="float:left;padding:5px;margin:5px;width:200px;display:block;">
<tbody>
<tr>
<asp:DataList ID="dlTemplates" runat="server" RepeatColumns="3"
RepeatDirection="Horizontal" onitemcommand="dlTemplates_ItemCommand">
<ItemTemplate>
<td style="border-right: gainsboro 1px solid; border-top: gainsboro 1px solid;
border-left: gainsboro 1px solid; border-bottom: gainsboro 1px solid;padding:5px;">
<table><tr><td>
<%# Eval("NewsletterName").ToString()%>
</td></tr>
<tr><td><asp:Button ID="btnSelectNL_Template" Text="Select" runat="server" CssClass="button" CommandArgument='<%# Eval("NewsletterId").ToString()%>' CommandName="Select"/></td></tr>
</table>
</td>
</ItemTemplate>
</asp:DataList>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</ContentTemplate>
and in the ItemCommandEvent I tried following
protected void dlTemplates_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int SelectedNewsletterId = int.Parse(e.CommandArgument.ToString());
if (NewsletterSelectedHandler!= null)
{
e.Item.Attributes.Add("onclick","jQuery('#mydialog').dialog('close');");
NewsletterSelectedHandler(SelectedNewsletterId);
}
}
}
EDIT
i shown the popup using this in my code behind
ScriptManager.RegisterClientScriptBlock(this.Page, Page.GetType(), "change", "jQuery('#mydialog').dialog('open');closedialog = 1;jQuery('#mydialog').parent().appendTo(jQuery('form:aspnetForm'));", true);
popup shown successfully but i could not close it on the button click of datalist child button i tried code provided by tugburk i checked the error console also there is no error
code for close is as followd :
<script type="text/javascript">
$(document).ready(function(){
$('#ctl00_ContentPlaceHolder1_NewsletterWizard1_TemplatePicker1_dlTemplates_ctl00_btnSelectNL_Template').click(function(){
$('#mydialog').dialog('close');
});
});
</script>
Any help would be appreciable
Many thanks in the Advance

use the following code;
$(document).ready(function(){
$('#<%= btnSelectNL_Template.ClientID %>').click(function(){
$('#id_of_your_dialog_element').dialog('close');
});
});
EDIT :
you are hardcoding your button id there;
ctl00_ContentPlaceHolder1_NewsletterWizard1_TemplatePicker1_dlTemplates_ctl00_b‌​tnSelectNL_Template
DataList will produce multiple buttons if you have multiple records. add a class name to that button, and try to write a code against it
$('.MyButtonClass').click(function(){
$('#mydialog').dialog('close');
});

Related

How to increase the `DropDownHeight` of `RadComboBox` that contains `Templates`

I have a RadComboBox as below :-
<telerik:RadComboBox ID="RadComboBoxNames" runat="server" Width="470px" DropDownAutoWidth="Enabled" MaxHeight="363px" Skin="MySkin" EmptyMessage="Select"
HighlightTemplatedItems="True" DataValueField="ID" DataTextField="ID" OnDataBound="RadComboBoxNames_DataBound" >
<HeaderTemplate>
<table style="width: 250px; text-align: left">
<tr>
<td style="font-weight: bold; width: 60px;">ID</td>
<td style="font-weight: bold; width: 180px;">Name</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table style="width: 250px; text-align: left">
<tr>
<td style="width: 60px;"><%#DataBinder.Eval(Container.DataItem, "ID")%></td>
<td style="width: 180px;"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
</tr>
</table>
</ItemTemplate>
</telerik:RadComboBox>
Now my DropDown height is not 363px as I have set in the MaxHeight property, it is very small and not increasing my dropdown height even if I Increase the value in MaxHeight property !!
How to increase my DropDownHeight of my RadComboBox ? Do I have to use any styling techniques ? Please Help, ThankYou.
You can alternatively change the MaxWidth of the RadComboBox drop down area by editing the default theme of RadComboBox. To do that, follow these steps:
Open your project in Blend and with RadComboBox selected go to Object-> Edit Template -> Edit a Copy
Search for a Control Template with an x:Key="NonEditableComboBox"
Inside, find Popup x:Name="PART_Popup"
Add a MaxWidth property that equals a value which you see fit to your needs.
Hope it would help.
Just keep the Height property of the RadComboBox !!

Is it possible to auto increment repeater control?

I have a repeater control on my web page that displays images as a result of a search. The user searches for a keyword, and my program stores the search results in a data table. The repeater then displays the images in the data table. So, if there are 150 images in the data table, the repeater will display all 150 images. Here's the code for my repeater:
<div>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div style="background-color: Silver; border-style: solid; display: inline-block;
float: left; margin: 5px; overflow: hidden;">
<div style="text-align: center">
<asp:Label ID="lblImage" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "image") %>'></asp:Label>
</div>
<div>
<%# DataBinder.Eval(Container.DataItem, "url") %>
</div>
<div style="text-align: center;">
<asp:HyperLink ID="requestLink" runat="server" Text="Original" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "requestUrl") %>'>
</asp:HyperLink>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
What if, however, I don't want to display all 150 images? Is there a way to only display, say, 20 at a time and let the repeater auto expand when the user scrolls down or hits a 'MORE' button, or something like that?
Thanks!
For that you have to search for auto refresh or scroll event of mouse.
for auto refresh you can write this kind of code in javascript using that you can reload page after every interval
<script type="text/javascript">
setInterval(function () {
load()
}, 30000);
var load = function () {
location.reload();
};
</script>
and on Load event of page you have to rebind data to repeater.

Can't add items from listbox to list

I am trying to add all items from a listbox to list(.cs page).I added items to listbox using javascript.Now LstScan.Items.Count return zero always.I can't add items to listbox.Listbox shows values.but problem happens in my .cs file.
here is my code;
Html and javascript Code is:
<script type="text/javascript">
function displayKeyCode_demo(e) {
var code;
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
if (code == 13) {
var textbox = document.getElementById("<%=TextBox1.ClientID%>")
var listbox = document.getElementById("<%=LstScan.ClientID%>")
var newOption = document.createElement("Option");
newOption.value = textbox.value;
newOption.innerHTML = textbox.value;
listbox.add(newOption);
}
}
</script>
<div>
<table cellspacing="3px" style="margin: 10px auto 3px 85px;">
<tr>
<td width="150px">
<asp:TextBox ID="TextBox1" runat="server" onkeypress="displayKeyCode_demo(event)"></asp:TextBox>
</td>
<td width="200px">
<asp:ListBox ID="LstScan" runat="server" Height="200px" Width="150px" AppendDataBoundItems="True" AutoPostBack="True" >
</asp:ListBox>
</td>
</tr>
</table>
</div>
here is my code behind code:
List<int> LstSOnum = new List<int>();
foreach (ListItem item in LstScan.Items) {
LstSOnum.Add(int.Parse(item.Value));
}
You can try with Text
LstSOnum.Add(int.Parse(item.Text));

HTML <td> tag's style attribute is not respecting the setting of width

In the following snippet of code, the width percentage attribute of the td tag seems to be ignored in Firefox/IE, etc. So both "Password" and the textbox get half the row, which is a waste of space. Is there something flagrantly wrong with the below snippet:
<table align="center" width="80%" cellpadding="0" cellspacing="0" class="loginBg">
<asp:Panel runat="server" ID="pnlLoginIn" style="width:100%;">
<tr>
<td style="padding-left:0px;font-family:Verdana;font-size:70%;width:30%">Username</td>
<td style="padding-right:0px;width:70%" align="left"><asp:TextBox id="txtUsername" runat="server" Width="90px" /></td>
<asp:RequiredFieldValidator ID="rfvUserName" runat="server" ErrorMessage="*" ControlToValidate="txtUsername" ValidationGroup="credentials" Display="Dynamic" />
</tr>
</asp:Panel>
</table>
Also, I'm doing styles in line because this is a very bare page that is only used to populate an iframe in another web application.
Thanks in advance for any tips.
EDIT: Added some code to clarify context.
EDIT 2: I removed the asp:Panel and the width proportioning seems to work now...but only when the iframe or browser window is 300+ pixels wide. In really small browser windows/frames, it forces both s to be 50%. Truly bizaree.
It seems that ie and table widths don't play nicely together.
What you can do to enforce a minimum width for your table is to add an extra row to your table which spans all columns which has a width of the minimum size that you desire. This will then enforce your td percentages when the broswer is resized or your iframe is small.
Like so:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<style>
.min500
{
width: 500px;
height: 1px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table align="center" border="1" cellpadding="0" cellspacing="0" class="loginBg">
<asp:Panel runat="server" ID="pnlLoginIn" style="width:100%;">
<tr>
<td colspan="2">
<div class="min500"></div>
</td>
</tr>
<tr>
<td style="padding-left:0px;font-family:Verdana;font-size:70%;width:30%;">
Username
</td>
<td style="padding-right:0px;width:70%;" align="left">
<asp:TextBox id="txtUsername" runat="server" Width="90px" /></td>
<asp:RequiredFieldValidator ID="rfvUserName" runat="server" ErrorMessage="*" ControlToValidate="txtUsername" ValidationGroup="credentials" Display="Dynamic" />
</tr>
</asp:Panel>
</table>
</form>
For one thing, put your validator inside a <td>.
Secondly -- check for width settings in other rows' <td> styles -- you might have conflicts.
Does it happen if you take the textbox out?
Shouldn't the <asp:RequiredFieldValidator> be inside one of the <td>s?
edit: And the <asp:Panel> between the <table> and the <tr> probably isn't helping. That is, you shouldn't have extra controls/tags in your table that arent supposed to be there. Something like an <asp:Panel> should either wrap the whole table or be inside one of the <td>s.
edit: in short, the tags as arranged will generate invalid html and so all styling bets are off.
I was having big problems with this in ASP.NET. Using a colgroup tag in the table resulted in a page source back from IIS WITHOUT that group. As you may guess the table just did what it wanted at that point. After figuring out the problem may have been needing the runat='server' attribute on colgroup as it was on the parent table, I encountered a no compile situation. What finally worked for me was a typical kludge of putting the desired cell widths on the tags of the first row. PROBLEM: The first real row of the table had cells that spanned columns so a dummy row was required. Now, how to hide that?
Set the table to have fixed width and layout style:
style="width: 800px; table-layout: fixed"
Then use a first row something like this for the least amount of code that seems to work (use widths that add up to your table width):
<tr id="DummyTableRow" style="line-height: 0px" runat="server">
<td style="width: 200px; border: none"> </td>
<td style="width: 200px; border: none"> </td>
<td style="width: 400px; border: none"> </td>
</tr>
So others don't bother trying them, a list of failed attempts:
This won't work or any combination of trying to do it with the td tags:
<tr runat="server" style="display: none">
This won't work or any combination of trying to do it with the td tags:
<tr runat="server" visible="false">
This sort of worked, but left a blank row:
<tr runat="server" style="visibility: hidden">

Change control postion dynamically in ASP.NET

I control visibility of buttons on a web page according to the type of a user.Visibility is determined in the Page_Load event. But there's one problem with the position of the controls.Appearance is awful.How can I make so that one button's top is the same as another button's top?
The markup is as follows: (added by OP in comment)
<tr>
<td style="width: 200px; height: 20px;">
<asp:Button ID="btnStajStatic" runat="server"
OnClick="btnStajStatic_Click" Text="Staj statistika"
Width="120px" BackColor="WhiteSmoke" BorderStyle="Solid" />
</td>
</tr>

Resources