1) Method Hiding
Relax. Yahoo! Mail virus scanning helps detect nasty viruses!
I am taking an example of Link button controls
Generate runtime Link button and after clicking each and every button some
Alert message should get fired. This can be done in simple 2 steps.
1) Make one method that will generate runtime Link button
public void AddButton()
{
LinkButton lbnew;
int i=1;
while (i<5)
{
lbnew=new LinkButton();
lbnew.Text="Link" + i + "<br>" ;
lbnew.ID="Lnk" + i;
Panel.Controls.Add(lbnew);
i++;
}
}
2) Call AddButton() method in OnLoad Event
private void Page_Load(object sender, System.EventArgs e)
{
AddButton();
int i;
for(i=1;i<5;i++)
{
((LinkButton)Page.FindControl("Lnk"+i)).Attributes
.Add("Onclick","alert('you have clicked link - " + i + "')");
}
Server Side Events
1) Make one method that will generate runtime Link button
public void AddButton()
{
LinkButton lbnew;
int i=1;
while (i<5)
{
lbnew=new LinkButton();
lbnew.Text="Link" + i + "<br>" ;
lbnew.ID="Lnk" + i;
lbnew.CommandArgument ="Lnk" +i;
lbnew.Click += new
System.EventHandler(this.LinkButton_Click);
Panel.Controls.Add(lbnew);
i++;
}
}
2) This events handler will call the LivkButton_click()
private void LinkButton_Click(Object sender,System.EventArgs e)
{
Response.Write("you have clicked link button);
}
Client side
When you generate Runtime controls you must give the Id of that controls
And need to be fire with Attribute properties of that control.
Server side
When you what to fire event in server side you need to add Event Handler on that link button control
There are two ways to prevent cache in ASP.NET
1) Response.Cache.SetCacheability(HttpCacheability.NoCache)
And
2) Response.Cache.SetAllowResponseInBrowserHistory(False)
This code you can right in code behind on_Load events this will not allow user to cache the page or records.
Ritesh Kumar Kesharwani
--Declare cursor in declare section
DECLARE CURSOR
--Open cursor for operation
OPEN CURSOR
FETCH CURSOR
--Fetch record till end
WHILE @@FETCH_STATUS =0
BEGIN
USE CURSOR
END
--Close cursor
CLOSE CURSOR
--Remove from the memory
DEALLOCATE CURSOR
-- Fetch the last row in the cursor.
FETCH LAST FROM authors_cursor-- Fetch the row immediately prior to the current row in the cursor.FETCH PRIOR FROM authors_cursor-- Fetch the second row in the cursor.FETCH ABSOLUTE 2 FROM authors_cursor-- Fetch the row that is three rows after the current row.FETCH RELATIVE 3 FROM authors_cursor-- Fetch the row that is two rows prior to the current row.FETCH RELATIVE -2 FROM authors_cursor
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'ReadData' AND type = 'P')
DROP PROCEDURE ReadData
GO
CREATE PROCEDURE ReadData
AS
BEGIN
DECLARE @STRINGNAME NVARCHAR (3999)
DECLARE CUR_NAME CURSOR FOR
SELECT USERNAME FROM TBLUSERINFO
OPEN CUR_NAME
FETCH NEXT FROM CUR_NAME INTO
@STRINGNAME
WHILE @@FETCH_STATUS =0
PRINT @STRINGNAME
BEGIN
FETCH NEXT FROM CUR_NAME INTO
@STRINGNAME
END
CLOSE CUR_NAME
DEALLOCATE CUR_NAME
END
GO
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'ReturnDataSet' AND type = 'P')
DROP PROCEDURE ReturnDataSet
GO
CREATE PROCEDURE ReturnDataSet
(
@CUR_DATASET CURSOR VARYING OUTPUT
)
AS
BEGIN
SET @CUR_DATASET = CURSOR FOR
SELECT USERNAME FROM TBLUSERINFO
END
GO
IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'ReadCursor' AND type = 'P')
DROP PROCEDURE ReadCursor
GO
CREATE PROCEDURE ReadCursor
(
@CUR_STATUS NVARCHAR (200) OUTPUT,
@CUR_DATASET CURSOR VARYING OUTPUT
)
AS
BEGIN
DECLARE @RETURN_CUR CURSOR
EXEC ReturnDataSet @RETURN_CUR OUTPUT
IF CURSOR_STATUS ('VARIABLE','@RETURN_CUR') <= 0
BEGIN
SET @CUR_STATUS =
'NO DATA AVAILABLE IN CURSOR.'
END
ELSE
BEGIN
SET @CUR_DATASET = @RETURN_CUR
END
END
GO
Ritesh Kumar Kesharwani
How to open new window using HyperLinkColumn in datagrid.
Opening window from Hyperlink column problem comes In Parent Window text [Object] comes and child window open properly When you try to open window like this
Example:
DataNavigateUrlFormatString ="javascript:varedit window.open('LoyaltyRewardDetail.aspx?RewardID={0}',
'childwindow','width=600,height=450,scrollbars=yes, resizable=yes')"
Insead of varedit type void keyword then parent window will remain same.
Example;
<asp:BoundColumn
DataField="InvoiceId"
HeaderText="Invoice Id" >
</asp:BoundColumn>
<asp:HyperLinkColumn
DataTextField="programname"
DataNavigateUrlField="RewardID"
HeaderText="Program Name"
DataNavigateUrlFormatString =
"javascript:void window.open('LoyaltyRewardDetail.aspx?RewardID={0}',
'childwindow','width=600,height=450,scrollbars=yes, resizable=yes')" >
</asp:HyperLinkColumn>
1) Add OnItemDataBound="PointHistoryBinding" into datagrid.
2) Bound the column as it in client side.
2) write code behind C#.net (in this way you can add multiple parameter in queryString
protected void LoyalityHistoryBinding( object sender, DataGridItemEventArgs e )
{
if( e.Item.ItemType == ListItemType.Header )
{
return;
}
string ProgID = e.Item.Cells[5].Text;
string RetailerId = e.Item.Cells[6].Text;
string ProgName = e.Item.Cells[3].Text;
string VersionId = e.Item.Cells[4].Text;
string ReachDate = e.Item.Cells[1].Text;
string passPageLink = "<a href='#'
onclick=\"window.open('LoyaltyDetail.aspx?ProgId={0}&ReachDate={1}&ProgName={2}&VersionId={3}&RetailerId={4}','childwindow','width=600,height=450,
scrollbars=yes, resizable=yes');\">{2}</a>";
string passType = Convert.ToString( DataBinder.Eval(e.Item.DataItem, "ProgramName") ).Trim();
e.Item.Cells[3].Text = String.Format(passPageLink,ProgID,
ReachDate,ProgName,VersionId,RetailerId,passType);
}
Another way to use Hyperlink column in datagrid with more then one parameter QueryString
("How do I specify more than one parameter for my HyperlinkColumn?")
<asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn HeaderText="Sample Column">
<ItemTemplate>
<asp:Hyperlink runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "ProductName").ToString()%>' NavigateUrl='<%# "page1.aspx?id=" + DataBinder.Eval(Container.DataItem,"ProductId").ToString() + "&Name=" + DataBinder.Eval(Container.DataItem,"ProductName").ToString()%>' ID="Hyperlink1" NAME="Hyperlink1"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Ritesh Kumar Kesharwani
How to Change Mouse Pointer server side for button control.
If button control are deactivate then you want to change Mouse Pointer when user go to that button
BtnDelete.enabled = false;
btnDelete.Style["CURSOR"] = "default";
When button active
btnDelete.Style["CURSOR"] = "hand";
BtnDelete.enabled = true;
Ritesh Kumar Kesharwani
Suppose you have more then one button (three button named: btnFirstButton,btnSecondButton,btnThirdButton) in your web page and after enter button press
First button called.
If you want some particular button should called after enter button press then you can do one this after come out from some control (textbox) you can call one JavaScript function
In textbox onkeypress client side (onkeypress="return OnLevelBlur(event);).
<asp:textbox id="txtbox1" Runat="server" MaxLength="10" onkeypress="return OnLevelBlur(event);">
function OnLevelBlur(e)
{
char = String.fromCharCode(e.keyCode);
xCode=char.charCodeAt(0);
if (xCode == 13)
{
document.all["btnFirstButton"].disabled="false"; document.all["btnSecondButton"].disabled="false"; document.Form1.txtbox1.focus();
}
}
Basically you catch Enter button events and put the condition that if enter button pressed then disable btnFirstButton and btnSecondButton then automatically btnThirdButton click event will fire and after server trip that two buttons btnFirstButton and btnSecondButton will active again.
You are disabling some button which you dont want to click after enter button.
Ritesh Kumar Kesharwani
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Public
Shared Function ConvertToDate(ByVal dateString As String, ByRef result As DateTime) As Boolean If dateString.Trim = String.Empty Then Return False End If TrydateString = dateString.Trim
dateString = dateString.Replace("\", "/")
dateString = dateString.Replace(":", "/")
dateString = dateString.Replace("-", "/")
Dim year, month, day As Int16 If dateString.IndexOf("/") = dateString.LastIndexOf("/") Then ' MM/YY format. Dim index1 As Int16 = dateString.IndexOf("/") Dim index2 As Int16 = dateString.LastIndexOf("/")year = dateString.Substring(index2 + 1)
month = dateString.Substring(0, index1)
day = DateTime.DaysInMonth(year, month)
ElseIf dateString.IndexOf("/", dateString.IndexOf("/") + 1) = dateString.LastIndexOf("/") Then ' Check if the second "/" is the last "/" ' MM/DD/YY format. Dim index1 As Int16 = dateString.IndexOf("/") Dim index2 As Int16 = dateString.LastIndexOf("/")year = dateString.Substring(index2 + 1)
month = dateString.Substring(0, index1)
day = dateString.Substring(index1 + 1, index2 - index1 - 1)
Else Return False End If If year < 100 Thenyear = year + 2000
' Convert to 4 digit format. End If Dim expDate As String = MonthName(month) & day & ", " & year If Not IsDate(expDate) Then Return False Elseresult =
CType(expDate, DateTime) Return True End If Catch ex As Exception Return False End Try End Function